-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c6b1f28
commit 0ca07c9
Showing
3 changed files
with
43 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,42 @@ | ||
import { writable } from 'svelte/store'; | ||
import { writable, derived } from 'svelte/store'; | ||
|
||
export const selectedLevel = writable('L1'); | ||
|
||
export const levelStates = writable({ | ||
L1: Array(12).fill('gray'), | ||
L2: Array(12).fill('gray'), | ||
L3: Array(12).fill('gray'), | ||
L4: Array(12).fill('gray') | ||
L1: Array(12).fill('gray'), | ||
L2: Array(12).fill('gray'), | ||
L3: Array(12).fill('gray'), | ||
L4: Array(12).fill('gray') | ||
}); | ||
|
||
levelStates.subscribe((states) => { | ||
console.log(states); | ||
// Create a derived store that maps the state colors to numeric values for NetworkTables | ||
export const levelStatesNT = derived(levelStates, ($levelStates) => { | ||
const ntValues = {}; | ||
for (const level in $levelStates) { | ||
ntValues[level] = $levelStates[level].map(color => { | ||
switch (color) { | ||
case 'gray': return 0; | ||
case 'yellow': return 1; | ||
case 'lime': return 2; | ||
case 'red': return 3; | ||
default: return 0; | ||
} | ||
}); | ||
} | ||
return ntValues; | ||
}); | ||
|
||
// Update NetworkTables | ||
export function updateNetworkTables(nt, states) { | ||
if (!nt) return; | ||
|
||
for (const level in states) { | ||
nt.putValue(`/ReefScape/${level}`, states[level]); | ||
} | ||
} | ||
|
||
// Subscribe to state changes and update NT | ||
levelStatesNT.subscribe(states => { | ||
// called from the Reef component with the actual NT instance | ||
console.log('Reef states updated:', states); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters