Skip to content

Commit 282a71a

Browse files
committed
Get panel test mode working correctly
1 parent a9440a8 commit 282a71a

File tree

2 files changed

+10
-66
lines changed

2 files changed

+10
-66
lines changed

sdk/smx.ts

+10-57
Original file line numberDiff line numberDiff line change
@@ -233,38 +233,6 @@ export class SMXStage {
233233
return this.testDataResponse$.firstToPromise();
234234
}
235235

236-
/*
237-
void SMX::SMXManager::UpdatePanelTestMode()
238-
{
239-
// If the test mode has changed, send the new test mode.
240-
//
241-
// When the test mode is enabled, send the test mode again periodically, or it'll time
242-
// out on the master and be turned off. Don't repeat the PanelTestMode_Off command.
243-
g_Lock.AssertLockedByCurrentThread();
244-
uint32_t now = GetTickCount();
245-
if(m_PanelTestMode == m_LastSentPanelTestMode &&
246-
(m_PanelTestMode == PanelTestMode_Off || now - m_SentPanelTestModeAtTicks < 1000))
247-
return;
248-
249-
// When we first send the test mode command (not for repeats), turn off lights.
250-
if(m_LastSentPanelTestMode == PanelTestMode_Off)
251-
{
252-
// The 'l' command used to set lights, but it's now only used to turn lights off
253-
// for cases like this.
254-
string sData = "l";
255-
sData.append(108, 0);
256-
sData += "\n";
257-
for(int iPad = 0; iPad < 2; ++iPad)
258-
m_pDevices[iPad]->SendCommandLocked(sData);
259-
}
260-
261-
m_SentPanelTestModeAtTicks = now;
262-
m_LastSentPanelTestMode = m_PanelTestMode;
263-
for(int iPad = 0; iPad < 2; ++iPad)
264-
m_pDevices[iPad]->SendCommandLocked(ssprintf("t %c\n", m_PanelTestMode));
265-
}
266-
*/
267-
268236
getPanelTestMode() {
269237
return this.panelTestMode;
270238
}
@@ -281,11 +249,7 @@ void SMX::SMXManager::UpdatePanelTestMode()
281249
}
282250
// Turn off panel test mode, and send "Off" event
283251
this.panelTestMode = mode;
284-
this.events.output$.push(Uint8Array.of(API_COMMAND.SET_PANEL_TEST_MODE, mode));
285-
286-
// TODO: Do we need to do anything with this? Does this even need to be called to flush
287-
// the queue?
288-
this.events.ackReports$.firstToPromise();
252+
this.events.output$.push(Uint8Array.of(API_COMMAND.SET_PANEL_TEST_MODE, char2byte(" "), mode, char2byte("\n")));
289253
}
290254

291255
// Either we're already off, or we sent the off command, so just return.
@@ -299,31 +263,20 @@ void SMX::SMXManager::UpdatePanelTestMode()
299263
/**
300264
* the 'l' command used to set lights, but it's now only used to turn lights off
301265
* for cases like this
302-
* Lights are always updated together (for some reason??)
303-
* 2 pads * 9 panels * 25 lights each * 3 (RGB) = 1350
304-
* The source code uses `108` and I'm really unsure why
305-
*
306-
* TODO: Does this even do anything?
266+
* 1 pad * 9 panels * 25 lights each * 3 (RGB) = 675
267+
* The source code uses `108` instead and I'm really unsure why,
268+
* but we're gonna do the same thing here because it works.
307269
*/
308-
this.events.output$.push(Uint8Array.of(API_COMMAND.SET_LIGHTS_OLD, ...padData([], 1350, 0), char2byte("\n")));
309-
310-
// TODO: Do we need to do anything with this? Does this even need to be called to flush
311-
// the queue?
312-
this.events.ackReports$.firstToPromise();
270+
this.events.output$.push(Uint8Array.of(API_COMMAND.SET_LIGHTS_OLD, ...padData([], 108, 0), char2byte("\n")));
313271

314272
// Send the Panel Test Mode command
315-
this.events.output$.push(Uint8Array.of(API_COMMAND.SET_PANEL_TEST_MODE, mode));
273+
this.events.output$.push(Uint8Array.of(API_COMMAND.SET_PANEL_TEST_MODE, char2byte(" "), mode, char2byte("\n")));
316274

317-
// TODO: Do we need to do anything with this? Does this even need to be called to flush
318-
// the queue?
319-
this.events.ackReports$.firstToPromise();
320-
321-
// The Panel Test Mode command needs to be resent every second
275+
// The Panel Test Mode command needs to be resent approximately every second, or else the stage will
276+
// auto time out and turn off Panel Test Mode itself
322277
this.testModeIntervalHandle = setInterval(() => {
323-
this.events.output$.push(Uint8Array.of(API_COMMAND.SET_PANEL_TEST_MODE, mode));
324-
325-
// TODO: Do I need to call this to consume the event?
326-
this.events.ackReports$.firstToPromise();
278+
console.log("Test Mode Push Interval");
279+
this.events.output$.push(Uint8Array.of(API_COMMAND.SET_PANEL_TEST_MODE, char2byte(" "), mode, char2byte("\n")));
327280
}, 1000);
328281
}
329282
}

ui/ui.tsx

-9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
import { useAtomValue, useAtom, type Atom } from "jotai";
22
import type React from "react";
3-
<<<<<<< HEAD
4-
import { useEffect, useId } from "react";
5-
=======
63
import { useEffect, useState } from "react";
7-
>>>>>>> e29f207 (Add checkbox for panel test mode)
84

95
import { DebugCommands } from "./DebugCommands.tsx";
106
import { open_smx_device, promptSelectDevice } from "./pad-coms.ts";
@@ -18,12 +14,8 @@ import {
1814
} from "./state.ts";
1915
import { StageTest } from "./stage/stage-test.tsx";
2016
import { TypedSelect } from "./common/typed-select.tsx";
21-
<<<<<<< HEAD
22-
import type { SMXStage } from "../sdk/smx.ts";
2317
import { ConfigValues } from "./stage/config.tsx";
24-
=======
2518
import { PanelTestMode } from "../sdk/api.ts";
26-
>>>>>>> e29f207 (Add checkbox for panel test mode)
2719

2820
function usePreviouslyPairedDevices() {
2921
useEffect(() => {
@@ -134,7 +126,6 @@ function PanelTestModeToggle() {
134126
<label>
135127
Panel Test Mode:{" "}
136128
<input
137-
key={stage?.info?.serial}
138129
type="checkbox"
139130
style={{ height: "2em", width: "2em" }}
140131
disabled={!stage}

0 commit comments

Comments
 (0)