-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add PanelTestMode suppport to smx class #42
Open
fchorney
wants to merge
6
commits into
main
Choose a base branch
from
fc/add-panel-test-mode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2801066
Add PanelTestMode suppport to smx class
fchorney b40467d
Linted
fchorney 1344e65
improve typing for debug commands
noahm e29f207
Add checkbox for panel test mode
noahm 7b3ac81
key the input on the current stage serial
noahm 9a1667b
Merge branch 'main' into fc/add-panel-test-mode
noahm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,12 +1,12 @@ | ||
import * as Bacon from "baconjs"; | ||
import { collatePackets, type AckPacket, type DataPacket } from "./state-machines/collate-packets"; | ||
import { API_COMMAND, char2byte } from "./api"; | ||
import { API_COMMAND, PanelTestMode, char2byte } from "./api"; | ||
import { SMXConfig, type Decoded } from "./commands/config"; | ||
import { SMXDeviceInfo } from "./commands/data_info"; | ||
import { StageInputs } from "./commands/inputs"; | ||
import { HID_REPORT_INPUT, HID_REPORT_INPUT_STATE, send_data } from "./packet"; | ||
import { SMXSensorTestData, SensorTestMode } from "./commands/sensor_test"; | ||
import { RGB } from "./utils"; | ||
import { RGB, padData } from "./utils"; | ||
|
||
/** | ||
* Class purely to set up in/out event stream "pipes" to properly throttle and sync input/output from a stage | ||
|
@@ -82,6 +82,8 @@ export class SMXStage { | |
private test_mode: SensorTestMode = SensorTestMode.CalibratedValues; | ||
private debug = true; | ||
private _config: SMXConfig | null = null; | ||
private panelTestMode = PanelTestMode.Off; | ||
private testModeIntervalHandle: number | null = null; | ||
|
||
public get config() { | ||
return this._config?.config || null; | ||
|
@@ -233,6 +235,97 @@ export class SMXStage { | |
return this.testDataResponse$.firstToPromise(); | ||
} | ||
|
||
/* | ||
void SMX::SMXManager::UpdatePanelTestMode() | ||
{ | ||
// If the test mode has changed, send the new test mode. | ||
// | ||
// When the test mode is enabled, send the test mode again periodically, or it'll time | ||
// out on the master and be turned off. Don't repeat the PanelTestMode_Off command. | ||
g_Lock.AssertLockedByCurrentThread(); | ||
uint32_t now = GetTickCount(); | ||
if(m_PanelTestMode == m_LastSentPanelTestMode && | ||
(m_PanelTestMode == PanelTestMode_Off || now - m_SentPanelTestModeAtTicks < 1000)) | ||
return; | ||
|
||
// When we first send the test mode command (not for repeats), turn off lights. | ||
if(m_LastSentPanelTestMode == PanelTestMode_Off) | ||
{ | ||
// The 'l' command used to set lights, but it's now only used to turn lights off | ||
// for cases like this. | ||
string sData = "l"; | ||
sData.append(108, 0); | ||
sData += "\n"; | ||
for(int iPad = 0; iPad < 2; ++iPad) | ||
m_pDevices[iPad]->SendCommandLocked(sData); | ||
} | ||
|
||
m_SentPanelTestModeAtTicks = now; | ||
m_LastSentPanelTestMode = m_PanelTestMode; | ||
for(int iPad = 0; iPad < 2; ++iPad) | ||
m_pDevices[iPad]->SendCommandLocked(ssprintf("t %c\n", m_PanelTestMode)); | ||
} | ||
*/ | ||
|
||
setPanelTestMode(mode: PanelTestMode) { | ||
// If we want to turn panel test mode off... | ||
if (mode === PanelTestMode.Off) { | ||
// We don't want to send the "Off" command multiple times, so only send it if | ||
// it's currently activated | ||
if (this.panelTestMode !== PanelTestMode.Off) { | ||
if (this.testModeIntervalHandle !== null) { | ||
clearInterval(this.testModeIntervalHandle); | ||
this.testModeIntervalHandle = null; | ||
} | ||
// Turn off panel test mode, and send "Off" event | ||
this.panelTestMode = mode; | ||
this.events.output$.push(Uint8Array.of(API_COMMAND.SET_PANEL_TEST_MODE, mode)); | ||
|
||
// TODO: Do we need to do anything with this? Does this even need to be called to flush | ||
// the queue? | ||
this.events.ackReports$.firstToPromise(); | ||
} | ||
|
||
// Either we're already off, or we sent the off command, so just return. | ||
return; | ||
} | ||
|
||
// We only need to run this when the current mode is not the same as the requested mode | ||
if (this.panelTestMode !== mode) { | ||
this.panelTestMode = mode; | ||
|
||
/** | ||
* the 'l' command used to set lights, but it's now only used to turn lights off | ||
* for cases like this | ||
* Lights are always updated together (for some reason??) | ||
* 2 pads * 9 panels * 25 lights each * 3 (RGB) = 1350 | ||
* The source code uses `108` and I'm really unsure why | ||
* | ||
* TODO: Does this even do anything? | ||
*/ | ||
this.events.output$.push(Uint8Array.of(API_COMMAND.SET_LIGHTS_OLD, ...padData([], 1350, 0), char2byte("\n"))); | ||
|
||
// TODO: Do we need to do anything with this? Does this even need to be called to flush | ||
// the queue? | ||
this.events.ackReports$.firstToPromise(); | ||
|
||
// Send the Panel Test Mode command | ||
this.events.output$.push(Uint8Array.of(API_COMMAND.SET_PANEL_TEST_MODE, mode)); | ||
|
||
// TODO: Do we need to do anything with this? Does this even need to be called to flush | ||
// the queue? | ||
this.events.ackReports$.firstToPromise(); | ||
|
||
// The Panel Test Mode command needs to be resent every second | ||
this.testModeIntervalHandle = setInterval(() => { | ||
this.events.output$.push(Uint8Array.of(API_COMMAND.SET_PANEL_TEST_MODE, mode)); | ||
|
||
// TODO: Do I need to call this to consume the event? | ||
this.events.ackReports$.firstToPromise(); | ||
Comment on lines
+325
to
+326
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need to worry about consuming these. I think because they are acks to unattended commands we can just let them silently discarded in the background. |
||
}, 1000); | ||
} | ||
} | ||
|
||
private handleConfig(data: Uint8Array): SMXConfig { | ||
// biome-ignore lint/style/noNonNullAssertion: info should very much be defined here | ||
this._config = new SMXConfig(data, this.info!.firmware_version); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, I think there's probably a better way to do this with the BaconJS interval to generate a stream of regular events that we can use for this. I'll add the UI for this first and worry about thinking through the better version of this interval later
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh yeah interesting. Would just need a way to tell it to stop since it says indefinitely.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, I think you would chain the interval stream with a
takeUntil
that watches another event stream (maybe a bus we can manually emit from) for a stop signal.