Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:OpenShock/Firmware into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
redmushie committed Oct 6, 2023
2 parents 7cbff28 + 4d425c9 commit 547b7f1
Show file tree
Hide file tree
Showing 53 changed files with 5,136 additions and 858 deletions.
39 changes: 19 additions & 20 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"ardenivanov.svelte-intellisense",
"bradlc.vscode-tailwindcss",
"dbaeumer.vscode-eslint",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"esbenp.prettier-vscode",
"fivethree.vscode-svelte-snippets",
"lkrms.inifmt",
"ms-python.black-formatter",
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"platformio.platformio-ide",
"svelte.svelte-vscode",
"svelte.svelte-vscode",
"xaver.clang-format"
],
"unwantedRecommendations": ["ms-vscode.cpptools-extension-pack"]
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"ardenivanov.svelte-intellisense",
"bradlc.vscode-tailwindcss",
"dbaeumer.vscode-eslint",
"editorconfig.editorconfig",
"esbenp.prettier-vscode",
"fivethree.vscode-svelte-snippets",
"ms-python.black-formatter",
"ms-vscode.cpptools",
"ms-vscode.cpptools-extension-pack",
"platformio.platformio-ide",
"svelte.svelte-vscode",
"xaver.clang-format"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
4 changes: 0 additions & 4 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,6 @@
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true
},
"[ini]": {
"editor.defaultFormatter": "lkrms.inifmt",
"editor.formatOnSave": true
},
"[python]": {
"editor.defaultFormatter": "ms-python.black-formatter",
"editor.formatOnSave": true
Expand Down
60 changes: 58 additions & 2 deletions WebUI/src/lib/WebSocketMessageHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,37 @@ interface WiFiScanCompletedMessage {
status: 'completed';
}

interface WiFiScanCancelledMessage {
type: 'wifi';
subject: 'scan';
status: 'cancelled';
}

interface WiFiScanErrorMessage {
type: 'wifi';
subject: 'scan';
status: 'error';
}

export type WiFiScanMessage = WiFiScanStartedMessage | WiFiScanDiscoveryMessage | WiFiScanCompletedMessage | WiFiScanErrorMessage;
export type WiFiMessage = WiFiScanMessage;
interface WiFiConnectSuccessMessage {
type: 'wifi';
subject: 'connect';
status: 'success';
ssid: string;
}

interface WiFiConnectErrorMessage {
type: 'wifi';
subject: 'connect';
status: 'error';
ssid: string;
bssid: string;
error: string;
}

export type WiFiScanMessage = WiFiScanStartedMessage | WiFiScanDiscoveryMessage | WiFiScanCompletedMessage | WiFiScanCancelledMessage | WiFiScanErrorMessage;
export type WiFiConnectMessage = WiFiConnectSuccessMessage | WiFiConnectErrorMessage;
export type WiFiMessage = WiFiScanMessage | WiFiConnectMessage;
export type WebSocketMessage = InvalidMessage | PoggiesMessage | WiFiMessage;

export function WebSocketMessageHandler(message: WebSocketMessage) {
Expand Down Expand Up @@ -68,6 +91,9 @@ function handleWiFiMessage(message: WiFiMessage) {
case 'scan':
handleWiFiScanMessage(message);
break;
case 'connect':
handleWiFiConnectMessage(message);
break;
default:
console.warn('[WS] Received invalid wifi message: ', message);
return;
Expand All @@ -85,6 +111,9 @@ function handleWiFiScanMessage(message: WiFiScanMessage) {
case 'completed':
handleWiFiScanCompletedMessage();
break;
case 'cancelled':
handleWiFiScanCancelledMessage();
break;
case 'error':
handleWiFiScanErrorMessage(message);
break;
Expand All @@ -106,7 +135,34 @@ function handleWiFiScanCompletedMessage() {
WiFiStateStore.setScanning(false);
}

function handleWiFiScanCancelledMessage() {
WiFiStateStore.setScanning(false);
}

function handleWiFiScanErrorMessage(message: WiFiScanErrorMessage) {
console.error('[WS] Received WiFi scan error message: ', message);
WiFiStateStore.setScanning(false);
}

function handleWiFiConnectMessage(message: WiFiConnectMessage) {
switch (message.status) {
case 'success':
handleWiFiConnectSuccessMessage(message);
break;
case 'error':
handleWiFiConnectErrorMessage(message);
break;
default:
console.warn('[WS] Received invalid connect message: ', message);
return;
}
}

function handleWiFiConnectSuccessMessage(message: WiFiConnectSuccessMessage) {
WiFiStateStore.setConnected(message.ssid);
}

function handleWiFiConnectErrorMessage(message: WiFiConnectErrorMessage) {
console.error('[WS] Failed to connect to %s (%s): %s', message.ssid, message.bssid, message.error);
WiFiStateStore.setConnected(null);
}
7 changes: 7 additions & 0 deletions WebUI/src/lib/stores/WiFiStateStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { writable } from 'svelte/store';

const { subscribe, update } = writable<WiFiState>({
initialized: false,
connected: null,
scanning: false,
networks: {},
});
Expand All @@ -16,6 +17,12 @@ export const WiFiStateStore = {
return store;
});
},
setConnected(connected: string | null) {
update((store) => {
store.connected = connected;
return store;
});
},
setScanning(scanning: boolean) {
update((store) => {
store.scanning = scanning;
Expand Down
1 change: 1 addition & 0 deletions WebUI/src/lib/types/WiFiState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type { WiFiNetwork } from './WiFiNetwork';

export type WiFiState = {
initialized: boolean;
connected: string | null;
scanning: boolean;
networks: { [bssid: string]: WiFiNetwork };
};
17 changes: 12 additions & 5 deletions WebUI/src/routes/+page.svelte
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
<script lang="ts">
import { WebSocketClient } from "$lib/WebSocketClient";
import WiFiList from "$lib/components/WiFiList.svelte";
import { WebSocketClient } from '$lib/WebSocketClient';
import WiFiList from '$lib/components/WiFiList.svelte';
function pair() {
WebSocketClient.Instance.Send('{ "type": "pair", "code": "123456" }');
}
</script>

<div class="flex flex-col items-center justify-center h-full">
<div class="flex-col space-y-5 w-full max-w-md">
<div class="flex-col space-y-5 w-full max-w-md">
<WiFiList />
<div>
<h3 class="h3 mb-2">Other settings</h3>
<div class="flex flex-col space-y-2">
<h3 class="h3">Other settings</h3>
<div class="flex space-x-2">
<input class="input variant-form-material" type="text" placeholder="Pair Code" />
<button class="btn variant-filled" on:click={pair}>Pair</button>
</div>
<div class="flex space-x-2">
<input class="input variant-form-material" type="text" placeholder="TX Pin" />
<button class="btn variant-filled">Configure</button>
Expand Down
13 changes: 13 additions & 0 deletions certificates/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Certificates used for HTTPS

These certificates are fetched from [CURL's website](https://curl.se/docs/caextract.html) and are used for HTTPS connections.

## How to update

1. Download the latest version of the certificate bundle along with its sha256 from [CURL's website](https://curl.se/docs/caextract.html).
2. Replace the `cacert.pem` file in this directory with the new one.
3. Replace the `cacert.sha256` file in this directory with the new one.
4. Update the `version.txt` file with the new version you downloaded.
5. Run `gen_crt_bundle.py` to generate the new `x509_crt_bundle` file.
6. Move the new `x509_crt_bundle` file to the `data/cert` directory.
7. Commit the changes.
Loading

0 comments on commit 547b7f1

Please sign in to comment.