Skip to content

Commit

Permalink
Merge branch 'develop' into feature/ditch-arduino-serial
Browse files Browse the repository at this point in the history
  • Loading branch information
hhvrc committed Nov 21, 2024
2 parents 5379918 + 4a3bd1c commit e001e00
Show file tree
Hide file tree
Showing 48 changed files with 848 additions and 613 deletions.
16 changes: 8 additions & 8 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,29 @@
"@skeletonlabs/skeleton": "2.10.3",
"@skeletonlabs/tw-plugin": "0.4.0",
"@sveltejs/adapter-static": "^3.0.6",
"@sveltejs/kit": "2.8.0",
"@sveltejs/kit": "2.8.1",
"@sveltejs/vite-plugin-svelte": "^3.1.2",
"@tailwindcss/forms": "0.5.9",
"@tailwindcss/typography": "0.5.15",
"@types/node": "22.9.0",
"autoprefixer": "10.4.20",
"eslint": "^9.14.0",
"eslint": "^9.15.0",
"eslint-config-prettier": "9.1.0",
"eslint-plugin-svelte": "2.46.0",
"flatbuffers": "24.3.25",
"postcss": "8.4.48",
"postcss": "8.4.49",
"prettier": "3.3.3",
"prettier-plugin-svelte": "3.2.7",
"prettier-plugin-svelte": "3.2.8",
"svelte": "4.2.19",
"svelte-check": "4.0.6",
"tailwindcss": "3.4.14",
"svelte-check": "4.0.9",
"tailwindcss": "3.4.15",
"tslib": "2.8.1",
"typescript": "5.6.3",
"vite-plugin-tailwind-purgecss": "^0.3.3",
"vitest": "2.1.4"
"vitest": "2.1.5"
},
"dependencies": {
"vite": "^5.4.10"
"vite": "^5.4.11"
},
"engines": {
"node": ">=20.18",
Expand Down
548 changes: 274 additions & 274 deletions frontend/pnpm-lock.yaml

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions frontend/src/lib/MessageHandlers/WifiNetworkEventHandler.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { WifiNetworkEvent } from '$lib/_fbs/open-shock/serialization/local/wifi-network-event';
import { WifiNetwork as FbsWifiNetwork } from '$lib/_fbs/open-shock/serialization/types/wifi-network';
import { WifiNetworkEventType } from '$lib/_fbs/open-shock/serialization/types/wifi-network-event-type';
import { DeviceStateStore } from '$lib/stores';
import { HubStateStore } from '$lib/stores';
import { toastDelegator } from '$lib/stores/ToastDelegator';
import type { WiFiNetwork } from '$lib/types/WiFiNetwork';
import type { MessageHandler } from '.';
Expand All @@ -27,7 +27,7 @@ function handleDiscoveredEvent(fbsNetwork: FbsWifiNetwork) {
saved: fbsNetwork.saved(),
};

DeviceStateStore.setWifiNetwork(network);
HubStateStore.setWifiNetwork(network);
}
function handleUpdatedEvent(fbsNetwork: FbsWifiNetwork) {
const ssid = fbsNetwork.ssid();
Expand All @@ -47,7 +47,7 @@ function handleUpdatedEvent(fbsNetwork: FbsWifiNetwork) {
saved: fbsNetwork.saved(),
};

DeviceStateStore.setWifiNetwork(network);
HubStateStore.setWifiNetwork(network);
}
function handleLostEvent(fbsNetwork: FbsWifiNetwork) {
const bssid = fbsNetwork.bssid();
Expand All @@ -57,7 +57,7 @@ function handleLostEvent(fbsNetwork: FbsWifiNetwork) {
return;
}

DeviceStateStore.removeWifiNetwork(bssid);
HubStateStore.removeWifiNetwork(bssid);
}
function handleSavedEvent(fbsNetwork: FbsWifiNetwork) {
const ssid = fbsNetwork.ssid();
Expand All @@ -68,7 +68,7 @@ function handleSavedEvent(fbsNetwork: FbsWifiNetwork) {
return;
}

DeviceStateStore.updateWifiNetwork(bssid, (network) => {
HubStateStore.updateWifiNetwork(bssid, (network) => {
network.saved = true;
return network;
});
Expand All @@ -87,7 +87,7 @@ function handleRemovedEvent(fbsNetwork: FbsWifiNetwork) {
return;
}

DeviceStateStore.updateWifiNetwork(bssid, (network) => {
HubStateStore.updateWifiNetwork(bssid, (network) => {
network.saved = false;
return network;
});
Expand All @@ -106,7 +106,7 @@ function handleConnectedEvent(fbsNetwork: FbsWifiNetwork) {
return;
}

DeviceStateStore.setWifiConnectedBSSID(bssid);
HubStateStore.setWifiConnectedBSSID(bssid);

toastDelegator.trigger({
message: 'WiFi network connected: ' + ssid,
Expand All @@ -122,7 +122,7 @@ function handleDisconnectedEvent(fbsNetwork: FbsWifiNetwork) {
return;
}

DeviceStateStore.setWifiConnectedBSSID(null);
HubStateStore.setWifiConnectedBSSID(null);

toastDelegator.trigger({
message: 'WiFi network disconnected: ' + ssid,
Expand Down
23 changes: 14 additions & 9 deletions frontend/src/lib/MessageHandlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HubToLocalMessagePayload } from '$lib/_fbs/open-shock/serialization/loc
import { ReadyMessage } from '$lib/_fbs/open-shock/serialization/local/ready-message';
import { WifiScanStatusMessage } from '$lib/_fbs/open-shock/serialization/local/wifi-scan-status-message';
import { ByteBuffer } from 'flatbuffers';
import { DeviceStateStore } from '$lib/stores';
import { HubStateStore } from '$lib/stores';
import { SerializeWifiScanCommand } from '$lib/Serializers/WifiScanCommand';
import { toastDelegator } from '$lib/stores/ToastDelegator';
import { SetRfTxPinCommandResult } from '$lib/_fbs/open-shock/serialization/local/set-rf-tx-pin-command-result';
Expand All @@ -25,15 +25,17 @@ function handleInvalidMessage() {
}

const PayloadTypes = Object.keys(HubToLocalMessagePayload).length / 2;
const PayloadHandlers: MessageHandler[] = new Array<MessageHandler>(PayloadTypes).fill(handleInvalidMessage);
const PayloadHandlers: MessageHandler[] = new Array<MessageHandler>(PayloadTypes).fill(
handleInvalidMessage
);

PayloadHandlers[HubToLocalMessagePayload.ReadyMessage] = (cli, msg) => {
const payload = new ReadyMessage();
msg.payload(payload);

console.log('[WS] Connected to device, poggies: ', payload.poggies());
console.log('[WS] Connected to hub, poggies: ', payload.poggies());

DeviceStateStore.update((store) => {
HubStateStore.update((store) => {
store.wifiConnectedBSSID = payload.connectedWifi()?.bssid() || null;
store.accountLinked = payload.accountLinked();
store.config = mapConfig(payload.config());
Expand All @@ -48,7 +50,7 @@ PayloadHandlers[HubToLocalMessagePayload.ReadyMessage] = (cli, msg) => {
store.gpioValidOutputs = gpioValidOutputs;
}

console.log('[WS] Updated device state store: ', store);
console.log('[WS] Updated hub state store: ', store);

return store;
});
Expand Down Expand Up @@ -78,7 +80,7 @@ PayloadHandlers[HubToLocalMessagePayload.WifiScanStatusMessage] = (cli, msg) =>
const payload = new WifiScanStatusMessage();
msg.payload(payload);

DeviceStateStore.setWifiScanStatus(payload.status());
HubStateStore.setWifiScanStatus(payload.status());
};

PayloadHandlers[HubToLocalMessagePayload.WifiNetworkEvent] = WifiNetworkEventHandler;
Expand Down Expand Up @@ -109,6 +111,9 @@ PayloadHandlers[HubToLocalMessagePayload.AccountLinkCommandResult] = (cli, msg)
case AccountLinkResultCode.InvalidCode:
reason = 'Invalid code';
break;
case AccountLinkResultCode.RateLimited:
reason = 'Too many requests';
break;
case AccountLinkResultCode.InternalError:
reason = 'Internal error';
break;
Expand All @@ -130,7 +135,7 @@ PayloadHandlers[HubToLocalMessagePayload.SetRfTxPinCommandResult] = (cli, msg) =
const result = payload.result();

if (result == SetGPIOResultCode.Success) {
DeviceStateStore.setRfTxPin(payload.pin());
HubStateStore.setRfTxPin(payload.pin());
toastDelegator.trigger({
message: 'Changed RF TX pin to: ' + payload.pin(),
background: 'bg-green-500',
Expand Down Expand Up @@ -163,7 +168,7 @@ PayloadHandlers[HubToLocalMessagePayload.SetEstopEnabledCommandResult] = (cli, m
const success = payload.success();

if (success) {
DeviceStateStore.setEstopEnabled(payload.enabled());
HubStateStore.setEstopEnabled(payload.enabled());
toastDelegator.trigger({
message: 'Changed EStop enabled to: ' + enabled,
background: 'bg-green-500',
Expand All @@ -184,7 +189,7 @@ PayloadHandlers[HubToLocalMessagePayload.SetEstopPinCommandResult] = (cli, msg)

if (result == SetGPIOResultCode.Success) {
const gpioPin = payload.gpioPin();
DeviceStateStore.setEstopGpioPin(gpioPin);
HubStateStore.setEstopGpioPin(gpioPin);
toastDelegator.trigger({
message: 'Changed EStop pin to: ' + gpioPin,
background: 'bg-green-500',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export enum AccountLinkResultCode {
InvalidCodeLength = 2,
NoInternetConnection = 3,
InvalidCode = 4,
InternalError = 5
RateLimited = 5,
InternalError = 6
}
17 changes: 14 additions & 3 deletions frontend/src/lib/components/GpioPinSelector.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { DeviceStateStore } from '$lib/stores';
import { HubStateStore } from '$lib/stores';
import { UsedPinsStore } from '$lib/stores/UsedPinsStore';
import { WebSocketClient } from '$lib/WebSocketClient';
Expand All @@ -10,7 +10,13 @@
let pendingPin: number | null = null;
let statusText: string = 'Loading...';
$: canSet = pendingPin !== null && pendingPin !== currentPin && pendingPin >= 0 && pendingPin <= 255 && $DeviceStateStore.gpioValidOutputs.includes(pendingPin) && !$UsedPinsStore.has(pendingPin);
$: canSet =
pendingPin !== null &&
pendingPin !== currentPin &&
pendingPin >= 0 &&
pendingPin <= 255 &&
$HubStateStore.gpioValidOutputs.includes(pendingPin) &&
!$UsedPinsStore.has(pendingPin);
$: if (currentPin !== null) {
UsedPinsStore.markPinUsed(currentPin, name);
Expand Down Expand Up @@ -40,7 +46,12 @@
<span class="text-sm text-gray-500">{statusText}</span>
</div>
<div class="flex space-x-2">
<input class="input variant-form-material" type="number" placeholder="GPIO Pin" bind:value={pendingPin} />
<input
class="input variant-form-material"
type="number"
placeholder="GPIO Pin"
bind:value={pendingPin}
/>
<button class="btn variant-filled" on:click={setGpioPin} disabled={!canSet}>Set</button>
</div>
</div>
22 changes: 15 additions & 7 deletions frontend/src/lib/components/WiFiList.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<script lang="ts">
import { getModalStore } from '@skeletonlabs/skeleton';
import { DeviceStateStore } from '$lib/stores';
import { HubStateStore } from '$lib/stores';
import { WebSocketClient } from '$lib/WebSocketClient';
import { WifiAuthMode } from '$lib/_fbs/open-shock/serialization/types/wifi-auth-mode';
import { WifiScanStatus } from '$lib/_fbs/open-shock/serialization/types/wifi-scan-status';
Expand All @@ -13,14 +13,16 @@
const modalStore = getModalStore();
$: scanStatus = $DeviceStateStore.wifiScanStatus;
$: scanStatus = $HubStateStore.wifiScanStatus;
$: isScanning = scanStatus === WifiScanStatus.Started || scanStatus === WifiScanStatus.InProgress;
$: connectedBSSID = $DeviceStateStore.wifiConnectedBSSID;
$: connectedBSSID = $HubStateStore.wifiConnectedBSSID;
// Sorting the groups themselves by each one's strongest network (by RSSI, higher is stronger)
// Only need to check the first network in each group, since they're already sorted by signal strength
$: strengthSortedGroups = Array.from($DeviceStateStore.wifiNetworkGroups.entries()).sort((a, b) => b[1].networks[0].rssi - a[1].networks[0].rssi);
$: strengthSortedGroups = Array.from($HubStateStore.wifiNetworkGroups.entries()).sort(
(a, b) => b[1].networks[0].rssi - a[1].networks[0].rssi
);
function wifiScan() {
const data = SerializeWifiScanCommand(!isScanning);
Expand Down Expand Up @@ -87,14 +89,20 @@
{#if netgroup.ssid}
<span class="ml-2">{netgroup.ssid}</span>
{:else}
<span class="ml-2">{netgroup.networks[0].bssid}</span><span class="text-gray-500 ml-1">(Hidden)</span>
<span class="ml-2">{netgroup.networks[0].bssid}</span><span class="text-gray-500 ml-1"
>(Hidden)</span
>
{/if}
</span>
<div class="btn-group variant-outline">
{#if netgroup.saved}
<button on:click={() => wifiConnect(netgroup)}><i class="fa fa-arrow-right text-green-500" /></button>
<button on:click={() => wifiConnect(netgroup)}
><i class="fa fa-arrow-right text-green-500" /></button
>
{:else}
<button on:click={() => wifiAuthenticate(netgroup)}><i class="fa fa-link text-green-500" /></button>
<button on:click={() => wifiAuthenticate(netgroup)}
><i class="fa fa-link text-green-500" /></button
>
{/if}
<button on:click={() => wifiSettings(netgroupKey)}><i class="fa fa-cog" /></button>
</div>
Expand Down
23 changes: 17 additions & 6 deletions frontend/src/lib/components/modals/WiFiDetails.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
import { SerializeWifiNetworkSaveCommand } from '$lib/Serializers/WifiNetworkSaveCommand';
import { SerializeWifiNetworkConnectCommand } from '$lib/Serializers/WifiNetworkConnectCommand';
import { WebSocketClient } from '$lib/WebSocketClient';
import { DeviceStateStore } from '$lib/stores';
import { HubStateStore } from '$lib/stores';
import { getModalStore } from '@skeletonlabs/skeleton';
import { SerializeWifiNetworkForgetCommand } from '$lib/Serializers/WifiNetworkForgetCommand';
import { WifiAuthMode } from '$lib/_fbs/open-shock/serialization/types/wifi-auth-mode';
const modalStore = getModalStore();
export let groupKey: string;
$: group = $DeviceStateStore.wifiNetworkGroups.get(groupKey);
$: group = $HubStateStore.wifiNetworkGroups.get(groupKey);
function GetWifiAuthModeString(type: WifiAuthMode) {
switch (type) {
Expand Down Expand Up @@ -85,11 +85,17 @@
{#if group}
<div class="flex justify-between space-x-2">
<h2 class="h2">Network Info</h2>
<button class="btn-icon variant-outline" on:click={() => modalStore.close()}><i class="fa fa-xmark"></i></button>
<button class="btn-icon variant-outline" on:click={() => modalStore.close()}
><i class="fa fa-xmark"></i></button
>
</div>
<div>
{#each rows as row (row.key)}
<span class="flex justify-between"><span class="font-bold">{row.key}:</span><span class="text-gray-700 dark:text-gray-300">{row.value}</span></span>
<span class="flex justify-between"
><span class="font-bold">{row.key}:</span><span class="text-gray-700 dark:text-gray-300"
>{row.value}</span
></span
>
{/each}
</div>
<!-- Per-AP info -->
Expand Down Expand Up @@ -117,7 +123,10 @@
{#if showPasswordPrompt}
<button on:click={() => (showPasswordPrompt = false)}>Cancel</button>
{/if}
<button on:click={ConnectWiFi} disabled={showPasswordPrompt && !validPassword}><i class={'fa mr-2 text-green-500' + (group.saved ? ' fa-wifi' : ' fa-link')}></i>Connect</button>
<button on:click={ConnectWiFi} disabled={showPasswordPrompt && !validPassword}
><i class={'fa mr-2 text-green-500' + (group.saved ? ' fa-wifi' : ' fa-link')}
></i>Connect</button
>
{#if group.saved}
<button on:click={ForgetWiFi}><i class="fa fa-trash mr-2 text-red-500"></i>Forget</button>
{/if}
Expand All @@ -126,7 +135,9 @@
{:else}
<div class="flex justify-between space-x-2">
<h2 class="h2">WiFi Info</h2>
<button class="btn-icon variant-outline" on:click={() => modalStore.close()}><i class="fa fa-xmark"></i></button>
<button class="btn-icon variant-outline" on:click={() => modalStore.close()}
><i class="fa fa-xmark"></i></button
>
</div>
<div class="flex justify-center">
<i class="fa fa-spinner fa-spin"></i>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { WifiScanStatus } from '$lib/_fbs/open-shock/serialization/types/wifi-scan-status';
import type { WiFiNetwork, WiFiNetworkGroup, DeviceState } from '$lib/types';
import type { WiFiNetwork, WiFiNetworkGroup, HubState } from '$lib/types';
import { writable } from 'svelte/store';
import { WifiAuthMode } from '$lib/_fbs/open-shock/serialization/types/wifi-auth-mode';

const { subscribe, update } = writable<DeviceState>({
const { subscribe, update } = writable<HubState>({
wifiConnectedBSSID: null,
wifiScanStatus: null,
wifiNetworks: new Map<string, WiFiNetwork>(),
Expand Down Expand Up @@ -47,11 +47,11 @@ function SsidMapReducer(groups: Map<string, WiFiNetworkGroup>, [, value]: [strin
return groups;
}

function updateWifiNetworkGroups(store: DeviceState) {
function updateWifiNetworkGroups(store: HubState) {
store.wifiNetworkGroups = Array.from(store.wifiNetworks.entries()).reduce(SsidMapReducer, new Map<string, WiFiNetworkGroup>());
}

export const DeviceStateStore = {
export const HubStateStore = {
subscribe,
update,
setWifiConnectedBSSID(connectedBSSID: string | null) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/stores/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './DeviceStateStore';
export * from './HubStateStore';
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { WifiScanStatus } from '$lib/_fbs/open-shock/serialization/types/wi
import type { Config } from '$lib/mappers/ConfigMapper';
import type { WiFiNetwork, WiFiNetworkGroup } from './';

export type DeviceState = {
export type HubState = {
wifiConnectedBSSID: string | null;
wifiScanStatus: WifiScanStatus | null;
wifiNetworks: Map<string, WiFiNetwork>;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/lib/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './DeviceState';
export * from './HubState';
export * from './WiFiNetwork';
export * from './WiFiNetworkGroup';
Loading

0 comments on commit e001e00

Please sign in to comment.