Skip to content

Commit dbd9bd4

Browse files
committed
Add PowerOff and SystemSetup commands
The `PowerOff` command shuts down the system. The `SystemSetup` command displays the system setup menu Signed-off-by: Christophe de Dinechin <[email protected]>
1 parent 1c21767 commit dbd9bd4

File tree

10 files changed

+77
-33
lines changed

10 files changed

+77
-33
lines changed

doc/commands/system.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ Force a garbage collection
106106
## USBFWUPDATE
107107

108108

109-
## OFF
109+
## PowerOff (OFF)
110+
110111
Turn calculator off programmatically
111112

113+
114+
## SystemSetup
115+
116+
Display the built-in system setup

fonts/EditorFont.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern const unsigned char EditorFont_sparse_font_data[];
77
const unsigned char EditorFont_sparse_font_data[72805] FONT_QSPI =
88
{
99

10-
0xDC, 0x01, 0xE0, 0xB8, 0x04, 0x36, 0x00, 0x01, 0x00, 0x2C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01,
10+
0xDE, 0x01, 0xE0, 0xB8, 0x04, 0x36, 0x00, 0x01, 0x00, 0x2C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01,
1111
0x00, 0x2C, 0x01, 0x01, 0x08, 0x00, 0x20, 0x5F, 0x00, 0x2C, 0x01, 0x01, 0x08, 0x00, 0x02, 0x0B,
1212
0x05, 0x21, 0x09, 0xEF, 0xBD, 0xF7, 0xDE, 0x7B, 0xEF, 0xBD, 0xF7, 0xDE, 0x7B, 0xEF, 0xBD, 0xF7,
1313
0x1E, 0x00, 0x00, 0xB8, 0xFF, 0xFF, 0xFF, 0x0E, 0x03, 0x0B, 0x0B, 0x0F, 0x11, 0x8F, 0x7F, 0xFC,

fonts/HelpFont.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern const unsigned char HelpFont_sparse_font_data[];
77
const unsigned char HelpFont_sparse_font_data[14848] FONT_QSPI =
88
{
99

10-
0xDC, 0x01, 0xFC, 0x73, 0x14, 0x00, 0x01, 0x00, 0x11, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01, 0x00,
10+
0xDE, 0x01, 0xFC, 0x73, 0x14, 0x00, 0x01, 0x00, 0x11, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01, 0x00,
1111
0x11, 0x01, 0x01, 0x03, 0x00, 0x20, 0x5F, 0x00, 0x11, 0x01, 0x01, 0x03, 0x00, 0x01, 0x04, 0x02,
1212
0x0D, 0x04, 0xFF, 0xFF, 0xF3, 0x03, 0x01, 0x04, 0x04, 0x05, 0x06, 0xFF, 0xFF, 0x0F, 0x01, 0x04,
1313
0x08, 0x0D, 0x0A, 0x12, 0x12, 0x14, 0x7F, 0x7F, 0x24, 0x24, 0x24, 0xFE, 0xFE, 0x28, 0x48, 0x48,

fonts/StackFont.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ extern const unsigned char StackFont_sparse_font_data[];
77
const unsigned char StackFont_sparse_font_data[36007] FONT_QSPI =
88
{
99

10-
0xDC, 0x01, 0xA2, 0x99, 0x02, 0x24, 0x00, 0x01, 0x00, 0x1C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01,
10+
0xDE, 0x01, 0xA2, 0x99, 0x02, 0x24, 0x00, 0x01, 0x00, 0x1C, 0x01, 0x01, 0x00, 0x00, 0x0D, 0x01,
1111
0x00, 0x1C, 0x01, 0x01, 0x06, 0x00, 0x20, 0x5F, 0x00, 0x1C, 0x01, 0x01, 0x06, 0x00, 0x02, 0x05,
1212
0x03, 0x17, 0x06, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x1F, 0xC0, 0xFF, 0x1F, 0x02, 0x05, 0x08, 0x0A,
1313
0x0C, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0xE7, 0x01, 0x05, 0x0E, 0x17, 0x10,

src/command.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,28 @@ COMMAND_DECLARE(Ticks);
193193
// ----------------------------------------------------------------------------
194194

195195

196+
COMMAND(Off)
197+
// ----------------------------------------------------------------------------
198+
// Switch the calculator off
199+
// ----------------------------------------------------------------------------
200+
{
201+
extern void power_off();
202+
power_off();
203+
return OK;
204+
}
205+
206+
207+
COMMAND(SystemSetup)
208+
// ----------------------------------------------------------------------------
209+
// Select the system menu
210+
// ----------------------------------------------------------------------------
211+
{
212+
extern void system_setup();
213+
system_setup();
214+
return OK;
215+
}
216+
217+
196218
COMMAND(HomeDirectory)
197219
// ----------------------------------------------------------------------------
198220
// Return the home directory

src/dm42/sysmenu.cc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,3 +661,24 @@ cstring menu_item_description(uint8_t menu_id,
661661

662662
return ln;
663663
}
664+
665+
666+
void power_off()
667+
// ----------------------------------------------------------------------------
668+
// Power off the calculator
669+
// ----------------------------------------------------------------------------
670+
{
671+
SET_ST(STAT_PGM_END);
672+
}
673+
674+
675+
void system_setup()
676+
// ----------------------------------------------------------------------------
677+
// Invoke the system setup
678+
// ----------------------------------------------------------------------------
679+
{
680+
SET_ST(STAT_MENU);
681+
handle_menu(&application_menu, MENU_RESET, 0);
682+
CLR_ST(STAT_MENU);
683+
wait_for_key_release(-1);
684+
}

src/dm42/sysmenu.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ int menu_item_run(uint8_t mid);
6363
cstring menu_item_description(uint8_t mid, char *, const int);
6464
bool load_state_file(cstring path);
6565
bool save_state_file(cstring path);
66-
66+
void power_off();
67+
void system_setup();
6768

6869
#endif // SYSMENU_H

src/ids.tbl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ CMD(HomeDirectory)
224224
CMD(Ticks)
225225
CMD(Depth)
226226

227+
228+
227229
// ============================================================================
228230
//
229231
// Loops
@@ -355,7 +357,6 @@ MENU(TimeMenu)
355357
MENU(PlotMenu)
356358

357359

358-
359360
// ============================================================================
360361
//
361362
// Special menus and menu commands
@@ -364,6 +365,8 @@ MENU(PlotMenu)
364365

365366
CMD(VariablesMenu)
366367
CMD(Catalog)
368+
NAMED(Off, "PowerOff")
369+
CMD(SystemSetup)
367370

368371
CMD(Unimplemented)
369372
#define LAST_COMMAND ID_Unimplemented

src/input.cc

Lines changed: 18 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,16 @@ void input::clear_help()
277277
}
278278

279279

280+
void input::clear_menu()
281+
// ----------------------------------------------------------------------------
282+
// Clear the menu
283+
// ----------------------------------------------------------------------------
284+
{
285+
menuObject = nullptr;
286+
menus(0, nullptr, nullptr);
287+
}
288+
289+
280290
bool input::key(int key, bool repeating)
281291
// ----------------------------------------------------------------------------
282292
// Process an input key
@@ -311,29 +321,6 @@ bool input::key(int key, bool repeating)
311321
return true;
312322
}
313323

314-
// Hard-code OFF
315-
if (shift && key == KEY_EXIT)
316-
{
317-
// Power off
318-
SET_ST(STAT_PGM_END);
319-
shift = false; // Make sure we don't have shift when waking up
320-
last = 0;
321-
clear_help(); // Otherwise shutdown images don't work
322-
return true;
323-
}
324-
325-
// Hard-code system menu
326-
// REVISIT: Shit should probably just be a regular RPL function
327-
if (!alpha && shift && key == KEY_0)
328-
{
329-
SET_ST(STAT_MENU);
330-
handle_menu(&application_menu, MENU_RESET, 0);
331-
CLR_ST(STAT_MENU);
332-
wait_for_key_release(-1);
333-
shift = false;
334-
return true;
335-
}
336-
337324
bool result =
338325
handle_shifts(key) ||
339326
handle_help(key) ||
@@ -2026,6 +2013,9 @@ bool input::handle_editing(int key)
20262013
}
20272014
case KEY_EXIT:
20282015
// Clear error if there is one, else clear editor
2016+
if (shift || xshift)
2017+
return false;
2018+
20292019
if (RT.error())
20302020
RT.clear_error();
20312021
else
@@ -2101,9 +2091,10 @@ bool input::handle_editing(int key)
21012091
}
21022092
break;
21032093
case KEY_EXIT:
2104-
if (shift)
2105-
SET_ST(STAT_PGM_END);
2094+
if (shift || xshift)
2095+
return false;
21062096
alpha = false;
2097+
clear_menu();
21072098
return true;
21082099
case KEY_DOWN:
21092100
// Key down to edit last object on stack
@@ -2374,8 +2365,8 @@ static const byte defaultShiftedCommand[2*input::NUM_KEYS] =
23742365
OP2BYTES(KEY_2, 0),
23752366
OP2BYTES(KEY_3, menu::ID_ProgramMenu),
23762367
OP2BYTES(KEY_SUB, menu::ID_IOMenu),
2377-
OP2BYTES(KEY_EXIT, 0),
2378-
OP2BYTES(KEY_0, 0),
2368+
OP2BYTES(KEY_EXIT, command::ID_Off),
2369+
OP2BYTES(KEY_0, command::ID_SystemSetup),
23792370
OP2BYTES(KEY_DOT, 0),
23802371
OP2BYTES(KEY_RUN, 0),
23812372
OP2BYTES(KEY_ADD, menu::ID_Catalog),

src/input.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ struct input
124124

125125
uint shift_plane() { return xshift ? 2 : shift ? 1 : 0; }
126126
void clear_help();
127+
void clear_menu();
127128
object_p object_for_key(int key);
128129
void edit(unicode c, modes m);
129130
result edit(utf8 s, size_t len, modes m, int off = 0);

0 commit comments

Comments
 (0)