Internal_Datalogger but with USB support removed (for MAX40108 Demo board), proof of concept that MAX32625 can be used successfully with VDDB(USB) left unpowered, as long as the USB library is not used.
Dependencies: max32625pico CmdLine
Diff: DataLogger_Internal.cpp
- Revision:
- 30:07197a430869
- Parent:
- 29:6a9edb6e973b
- Child:
- 31:47eee7e0cc2d
--- a/DataLogger_Internal.cpp Mon Apr 26 21:39:21 2021 -0700 +++ b/DataLogger_Internal.cpp Tue Apr 27 00:00:38 2021 -0700 @@ -2032,6 +2032,18 @@ #endif // USE_DATALOGGER_SPIDeviceRegRead //-------------------------------------------------- +// support Datalogger_PrintRow() print gstrRemarkText field from recent #remark +#ifndef USE_DATALOGGER_REMARK_FIELD +#define USE_DATALOGGER_REMARK_FIELD 1 +#endif // USE_DATALOGGER_REMARK_FIELD +#if USE_DATALOGGER_REMARK_FIELD +// Datalogger_PrintRow() print gstrRemarkText field from recent #remark +const size_t gstrRemarkTextLASTINDEX = 40; // gstrRemarkText buffer size - 1 +char gstrRemarkText[gstrRemarkTextLASTINDEX+1] = ""; +char gstrRemarkHeader[] = "comment"; // comment or remark? +#endif // USE_DATALOGGER_REMARK_FIELD + +//-------------------------------------------------- // Datalogger_RunActionTable() supported actions #ifndef USE_DATALOGGER_ActionTable #define USE_DATALOGGER_ActionTable 1 @@ -2042,14 +2054,14 @@ // Datalogger_RunActionTable() supported actions typedef enum action_type_enum_t { action_noop = 0, // no operation - action_digitalOutLow, // pin = low if condition - action_digitalOutHigh, // pin = low if condition - action_button, // pin = button index 1, 2, 3 - action_trigger_Halt, - action_trigger_FreeRun, - action_trigger_Timer, - action_trigger_PlatformDigitalInput, - action_trigger_SPIDeviceRegRead, + action_digitalOutLow = 1, // pin = low if condition + action_digitalOutHigh = 2, // pin = high if condition + action_button = 3, // pin = button event index 1, 2, 3 + action_trigger_Halt = 4, + action_trigger_FreeRun = 5, + action_trigger_Timer = 6, + action_trigger_PlatformDigitalInput = 7, + action_trigger_SPIDeviceRegRead = 8, } action_type_enum_t; // // Datalogger_RunActionTable() supported conditions @@ -2089,7 +2101,7 @@ const int ACTION_TABLE_ROW_MAX = 20; #if MAX40108_DEMO bool Datalogger_action_table_enabled = true; -int Datalogger_action_table_row_count = 6; // assert (Datalogger_action_table_row_count <= ACTION_TABLE_ROW_MAX) +int Datalogger_action_table_row_count = 8; // assert (Datalogger_action_table_row_count <= ACTION_TABLE_ROW_MAX) #else // MAX40108_DEMO int Datalogger_action_table_row_count = 0; #endif // MAX40108_DEMO @@ -2119,11 +2131,11 @@ // L@5 act=2 pin=91 if=2 ch=2 x=0.600000 -- digitalOutHigh D91 if A2 < 0.600000 {action_digitalOutHigh, pin_LED_1, condition_if_An_lt_threshold, channel_WE, threshold_WE_0V6}, // - // L@6 act=3 pin=2 if=2 ch=2 x=0.700000 -- button 2 if A2 < 0.700000 - {action_button, 2, condition_if_An_gt_threshold, channel_WE, threshold_WE_0V7}, + // L@6 act=3 pin=4 if=1 ch=2 x=0.700000 -- button 4 event if A2 > 0.700000 + {action_button, 4, condition_if_An_gt_threshold, channel_WE, threshold_WE_0V7}, // - // L@7 act=3 pin=3 if=2 ch=2 x=0.600000 -- button 3 if A2 < 0.600000 - {action_button, 3, condition_if_An_lt_threshold, channel_WE, threshold_WE_0V6}, + // L@7 act=3 pin=5 if=2 ch=2 x=0.600000 -- button 5 event if A2 < 0.600000 + {action_button, 5, condition_if_An_lt_threshold, channel_WE, threshold_WE_0V6}, // #endif // MAX40108_DEMO // @@ -2710,7 +2722,7 @@ #if HAS_BUTTON4_DEMO_INTERRUPT // command_table: list of commands to perform on button press char onButton4_command_table_00[COMMAND_TABLE_COL_MAX] = "# Button4 event"; -char onButton4_command_table_01[COMMAND_TABLE_COL_MAX] = ""; +char onButton4_command_table_01[COMMAND_TABLE_COL_MAX] = "# WE>0.7:active"; char onButton4_command_table_02[COMMAND_TABLE_COL_MAX] = ""; char onButton4_command_table_03[COMMAND_TABLE_COL_MAX] = ""; char onButton4_command_table_04[COMMAND_TABLE_COL_MAX] = ""; @@ -2735,7 +2747,7 @@ #if HAS_BUTTON5_DEMO_INTERRUPT // command_table: list of commands to perform on button press char onButton5_command_table_00[COMMAND_TABLE_COL_MAX] = "# Button5 event"; -char onButton5_command_table_01[COMMAND_TABLE_COL_MAX] = ""; +char onButton5_command_table_01[COMMAND_TABLE_COL_MAX] = "# WE<0.6:sleep"; char onButton5_command_table_02[COMMAND_TABLE_COL_MAX] = ""; char onButton5_command_table_03[COMMAND_TABLE_COL_MAX] = ""; char onButton5_command_table_04[COMMAND_TABLE_COL_MAX] = ""; @@ -3264,7 +3276,7 @@ // TODO: %B1@! disable button response but keep command table contents // TODO: %B1@@ enable button response // TODO: %B1! trigger onButton1FallingEdge() immediately (for test development) - cmdLine.serial().printf("\r\n %%B1! trigger Button1; %%B1@ -- view/edit command table"); + cmdLine.serial().printf("\r\n %%B1! trigger Button1 event; %%B1@ -- view/edit command table"); #endif // USE_DATALOGGER_CommandTable //-------------------------------------------------- #if HAS_digitalInOuts @@ -3526,6 +3538,17 @@ command_table[editRowIndex][COMMAND_TABLE_COL_MAX-1]='\0'; // null character at end of line } } + else if ((editRowIndex == command_table_row_count) && (command_table_row_count < COMMAND_TABLE_ROW_MAX)) { + // %B1@nnn command add new row (even though this looks like a replace command) if and only if nnn==next new unassigned line number + // + command_table_row_count++; + cmdLine.serial().printf("\r\n add next row %d containing \"%s\"", + editRowIndex, cmdLine.str()+argIndex); + strncpy(command_table[editRowIndex], cmdLine.str()+argIndex, COMMAND_TABLE_COL_MAX-1); + command_table[editRowIndex][COMMAND_TABLE_COL_MAX-1]='\0'; // null character at end of line + command_table[command_table_row_count][0]='\0'; // empty string marks end of command_table + // + } } break; case '+': @@ -3583,13 +3606,13 @@ } } break; - case '!': - // pause the entire action table - // TODO: %B1@! disable button response but keep command table contents + case '.': // something other than ! because %B1! means trigger event + // pause the button event + // TODO: %B1@. disable button response but keep command table contents //~ Datalogger_action_table_enabled = false; break; case '@': - // enable the entire action table + // enable the button event // TODO: %B1@@ enable button response //~ Datalogger_action_table_enabled = true; break; @@ -3605,9 +3628,14 @@ lineIndex, command_table[lineIndex]); } - cmdLine.serial().printf("\r\n command_table_row_count = %d", - command_table_row_count); - cmdLine.serial().printf("\r\nCommand table editing commands:"); + //~ cmdLine.serial().printf("\r\n command_table_row_count = %d/%d", + //~ command_table_row_count, COMMAND_TABLE_ROW_MAX); + cmdLine.serial().printf("\r\n\r\nEdit Button%d event (used %d/%d, %d free):", + command_table_button_index, + command_table_row_count, + COMMAND_TABLE_ROW_MAX, + (COMMAND_TABLE_ROW_MAX - command_table_row_count) + ); if (command_table_row_count < COMMAND_TABLE_ROW_MAX) { // if command_table_row_count => COMMAND_TABLE_ROW_MAX then the table is full cmdLine.serial().printf("\r\n %%B%1d@+ command -- add new row %d at end of table", @@ -3626,9 +3654,12 @@ command_table_row_count-1); cmdLine.serial().printf("\r\n %%B%1d@-~~~ -- delete all rows", command_table_button_index); - cmdLine.serial().printf("\r\n %%B%1d@! -- pause entire command table", - command_table_button_index); - cmdLine.serial().printf("\r\n %%B%1d@@ -- enable command table", + //~ cmdLine.serial().printf("\r\n %%B%1d@. -- pause entire command table", + //~ command_table_button_index); + //~ cmdLine.serial().printf("\r\n %%B%1d@@ -- enable command table", + //~ command_table_button_index); + cmdLine.serial().printf("\r\n %%B%1d! -- trigger Button%d event", + command_table_button_index, command_table_button_index); } // @@ -4156,8 +4187,64 @@ break; case '\r': case '\n': // ignore blank line case '\0': // ignore empty line + main_menu_status(cmdLine); + //~ main_menu_help(cmdLine); + // print command prompt + //cmdLine.serial().printf("\r\n>"); + break; case '#': // ignore comment line // # -- lines beginning with # are comments + // +#if USE_DATALOGGER_REMARK_FIELD + // Datalogger_PrintRow() print gstrRemarkText field from recent #remark -- in main_menu_onEOLcommandParser + // # command handler update gstrRemarkText buffer instead of just ignoring the remark + // + // ignore extra spaces before the remark + // find argIndex such that cmdLine[argIndex] is the start of the second word + int argIndex; + for (argIndex = 1; cmdLine[argIndex] != '\0'; argIndex++) + { + if (cmdLine[argIndex] == ' ') break; + } + for (; cmdLine[argIndex] != '\0'; argIndex++) + { + if (cmdLine[argIndex] != ' ') break; + } + // + strncpy(gstrRemarkText, cmdLine.str()+argIndex, gstrRemarkTextLASTINDEX+1); + // do not exceed string buffer limit; keep sentinel null character at end of buffer + gstrRemarkText[gstrRemarkTextLASTINDEX] = '\0'; + for (int index = 0; index < gstrRemarkTextLASTINDEX; index++) + { + if ((gstrRemarkText[index]) == '\0') break; // null character at end of string + if ((gstrRemarkText[index]) < 0x20) { + // replace non-printing characters with _ + gstrRemarkText[index] = '_'; + continue; + } + if ((gstrRemarkText[index]) >= 0x7F) { + // replace non-printing characters with _ + gstrRemarkText[index] = '_'; + continue; + } + switch(gstrRemarkText[index]) + { + case ',': + // replace , with ; + gstrRemarkText[index] = ';'; + break; + case '"': + // replace " with ' + gstrRemarkText[index] = '\''; + break; + case '\\': + // replace \ with / + gstrRemarkText[index] = '/'; + break; + } + } +#endif // USE_DATALOGGER_REMARK_FIELD + // main_menu_status(cmdLine); //~ main_menu_help(cmdLine); // print command prompt @@ -4474,43 +4561,57 @@ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': // edit row data - if (Datalogger_action_table_row_count > 0) { + if (1) { // removed Datalogger_action_table_row_count > 0 -- support %L@nnn command add new row (even though this looks like a replace command) if and only if nnn==next new unassigned line number // if Datalogger_action_table_row_count == 0 then the table is empty // get row number to edit from cmdLine[2] editRowIndex = atoi(cmdLine.str()+2); - // default is no change - edit_action = Datalogger_action_table[editRowIndex].action; - edit_digitalOutPin = Datalogger_action_table[editRowIndex].digitalOutPin; - edit_condition = Datalogger_action_table[editRowIndex].condition; - edit_condition_channel = Datalogger_action_table[editRowIndex].condition_channel; - edit_condition_threshold = Datalogger_action_table[editRowIndex].condition_threshold; - // scan cmdLine[2] for key=value of what fields to change - if (cmdLine.parse_int_dec("act", edit_action)) - { - //~ cmdLine.serial().printf("\r\n act=%d", edit_action); - } - if (cmdLine.parse_int_dec("pin", edit_digitalOutPin)) - { - //~ cmdLine.serial().printf("\r\n pin=%d", edit_digitalOutPin); + if ((editRowIndex >= 0) && (editRowIndex < Datalogger_action_table_row_count)) { + // update row + cmdLine.serial().printf("\r\n replace row %d", editRowIndex); + // rescan cmdLine[2] for key=value of what fields to change (now that we have got defaults from the existing line + edit_action = Datalogger_action_table[editRowIndex].action; + edit_digitalOutPin = Datalogger_action_table[editRowIndex].digitalOutPin; + edit_condition = Datalogger_action_table[editRowIndex].condition; + edit_condition_channel = Datalogger_action_table[editRowIndex].condition_channel; + edit_condition_threshold = Datalogger_action_table[editRowIndex].condition_threshold; + // rescan cmdLine[2] for key=value of what fields to change (now that we have got defaults from the existing line + if (cmdLine.parse_int_dec("act", edit_action)) + { + //~ cmdLine.serial().printf("\r\n act=%d", edit_action); + } + if (cmdLine.parse_int_dec("pin", edit_digitalOutPin)) + { + //~ cmdLine.serial().printf("\r\n pin=%d", edit_digitalOutPin); + } + if (cmdLine.parse_int_dec("if", edit_condition)) + { + //~ cmdLine.serial().printf("\r\n if=%d", edit_condition); + } + if (cmdLine.parse_int_dec("ch", edit_condition_channel)) + { + //~ cmdLine.serial().printf("\r\n ch=%d", edit_condition_channel); + } + if (cmdLine.parse_double("x", edit_condition_threshold)) + { + //~ cmdLine.serial().printf("\r\n x=%d", edit_condition_threshold); + } + Datalogger_action_table[editRowIndex].action = (action_type_enum_t)edit_action; + Datalogger_action_table[editRowIndex].digitalOutPin = edit_digitalOutPin; + Datalogger_action_table[editRowIndex].condition = (action_condition_enum_t)edit_condition; + Datalogger_action_table[editRowIndex].condition_channel = edit_condition_channel; + Datalogger_action_table[editRowIndex].condition_threshold = edit_condition_threshold; } - if (cmdLine.parse_int_dec("if", edit_condition)) - { - //~ cmdLine.serial().printf("\r\n if=%d", edit_condition); - } - if (cmdLine.parse_int_dec("ch", edit_condition_channel)) - { - //~ cmdLine.serial().printf("\r\n ch=%d", edit_condition_channel); + else if ((editRowIndex == Datalogger_action_table_row_count) && (Datalogger_action_table_row_count < ACTION_TABLE_ROW_MAX)) { + // %L@nnn command add new row (even though this looks like a replace command) if and only if nnn==next new unassigned line number + Datalogger_action_table_row_count++; + cmdLine.serial().printf("\r\n add next row %d", editRowIndex); + Datalogger_action_table[editRowIndex].action = (action_type_enum_t)edit_action; + Datalogger_action_table[editRowIndex].digitalOutPin = edit_digitalOutPin; + Datalogger_action_table[editRowIndex].condition = (action_condition_enum_t)edit_condition; + Datalogger_action_table[editRowIndex].condition_channel = edit_condition_channel; + Datalogger_action_table[editRowIndex].condition_threshold = edit_condition_threshold; + // } - if (cmdLine.parse_double("x", edit_condition_threshold)) - { - //~ cmdLine.serial().printf("\r\n x=%d", edit_condition_threshold); - } - // update row - Datalogger_action_table[editRowIndex].action = (action_type_enum_t)edit_action; - Datalogger_action_table[editRowIndex].digitalOutPin = edit_digitalOutPin; - Datalogger_action_table[editRowIndex].condition = (action_condition_enum_t)edit_condition; - Datalogger_action_table[editRowIndex].condition_channel = edit_condition_channel; - Datalogger_action_table[editRowIndex].condition_threshold = edit_condition_threshold; } break; case '+': @@ -4519,6 +4620,7 @@ // if Datalogger_action_table_row_count => ACTION_TABLE_ROW_MAX then the table is full editRowIndex = Datalogger_action_table_row_count; Datalogger_action_table_row_count++; + cmdLine.serial().printf("\r\n add new row %d", editRowIndex); Datalogger_action_table[editRowIndex].action = (action_type_enum_t)edit_action; Datalogger_action_table[editRowIndex].digitalOutPin = edit_digitalOutPin; Datalogger_action_table[editRowIndex].condition = (action_condition_enum_t)edit_condition; @@ -4532,39 +4634,45 @@ // if Datalogger_action_table_row_count == 0 then the table is empty if ((cmdLine[3] == '~') && (cmdLine[4] == '~') && (cmdLine[5] == '~')) { // L@-~~~ -- delete all rows from table + cmdLine.serial().printf("\r\n delete all rows"); Datalogger_action_table_row_count = 0; break; } - editRowIndex = atoi(cmdLine.str()+3); - // delete row editRowIndex from Datalogger_action_table - for (int i = editRowIndex; i < (Datalogger_action_table_row_count-1); i++) - { - // copy row i+1 into row i - Datalogger_action_table[i].action = Datalogger_action_table[i+1].action; - Datalogger_action_table[i].digitalOutPin = Datalogger_action_table[i+1].digitalOutPin; - Datalogger_action_table[i].condition = Datalogger_action_table[i+1].condition; - Datalogger_action_table[i].condition_channel = Datalogger_action_table[i+1].condition_channel; - Datalogger_action_table[i].condition_threshold = Datalogger_action_table[i+1].condition_threshold; + else { + editRowIndex = atoi(cmdLine.str()+3); + cmdLine.serial().printf("\r\n delete row %d", editRowIndex); + // delete row editRowIndex from Datalogger_action_table + for (int i = editRowIndex; i < (Datalogger_action_table_row_count-1); i++) + { + // copy row i+1 into row i + Datalogger_action_table[i].action = Datalogger_action_table[i+1].action; + Datalogger_action_table[i].digitalOutPin = Datalogger_action_table[i+1].digitalOutPin; + Datalogger_action_table[i].condition = Datalogger_action_table[i+1].condition; + Datalogger_action_table[i].condition_channel = Datalogger_action_table[i+1].condition_channel; + Datalogger_action_table[i].condition_threshold = Datalogger_action_table[i+1].condition_threshold; + } + Datalogger_action_table_row_count--; } - Datalogger_action_table_row_count--; } break; - case '!': - // pause the entire action table + case '.': + // L@. pause the entire Log action table + cmdLine.serial().printf("\r\n pause the entire Log action table"); Datalogger_action_table_enabled = false; break; case '@': - // enable the entire action table + // L@@ enable the entire Log action table + cmdLine.serial().printf("\r\n enable the entire Log action table"); Datalogger_action_table_enabled = true; break; } // // Print the contents of Datalogger_action_table if (Datalogger_action_table_enabled) { - cmdLine.serial().printf("Action table enabled; L@! to pause"); + // cmdLine.serial().printf("Log action table enabled; L@. to pause"); } else { - cmdLine.serial().printf("Action table paused; L@@ to enable"); + cmdLine.serial().printf("Log action table paused; L@@ to enable"); } //~ cmdLine.serial().printf("\r\n Datalogger_action_table_row_count=%d", Datalogger_action_table_row_count); for (int i = 0; i < Datalogger_action_table_row_count; i++) @@ -4695,7 +4803,11 @@ break; } // switch(Datalogger_action_table[i].condition) } // for ...Datalogger_action_table_row_count // Print the contents of Datalogger_action_table - cmdLine.serial().printf("\r\nAction table editing commands:"); + cmdLine.serial().printf("\r\n\r\nEdit Log action table (used %d/%d, %d free):", + Datalogger_action_table_row_count, + ACTION_TABLE_ROW_MAX, + (ACTION_TABLE_ROW_MAX - Datalogger_action_table_row_count) + ); if (Datalogger_action_table_row_count < ACTION_TABLE_ROW_MAX) { // if Datalogger_action_table_row_count => ACTION_TABLE_ROW_MAX then the table is full cmdLine.serial().printf("\r\n L@+ act=4 if=1 ch=5 x=12345 -- add new entry at end of table"); @@ -4709,8 +4821,8 @@ Datalogger_action_table_row_count-1, Datalogger_action_table_row_count-1); cmdLine.serial().printf("\r\n L@-~~~ -- delete all rows"); - cmdLine.serial().printf("\r\n L@! -- pause entire action table"); - cmdLine.serial().printf("\r\n L@@ -- enable action table"); + if (Datalogger_action_table_enabled) cmdLine.serial().printf("\r\n L@. -- pause entire Log action table"); + if (!Datalogger_action_table_enabled) cmdLine.serial().printf("\r\n L@@ -- enable Log action table"); } // } // case L@ -- configures Datalogger_action_table @@ -5140,6 +5252,10 @@ # endif // HAS_DAPLINK_SERIAL } #endif // defined(LOG_PLATFORM_AIN) +#if USE_DATALOGGER_REMARK_FIELD + // Datalogger_PrintRow() print gstrRemarkText field from recent #remark -- in Datalogger_PrintHeader + cmdLine.serial().printf(",\"%s\"", gstrRemarkHeader); +#endif // USE_DATALOGGER_REMARK_FIELD // end of column header line cmdLine.serial().printf("\r\n"); # if HAS_DAPLINK_SERIAL @@ -5430,6 +5546,8 @@ break; case action_button: // pin = button index 1, 2, 3 { + // don't allow onButton1FallingEdge() command processing to halt the datalog + Datalogger_Trigger_enum_t saved_Datalogger_Trigger = Datalogger_Trigger; #if HAS_BUTTON1_DEMO_INTERRUPT switch (Datalogger_action_table[i].digitalOutPin) // pin = button index 1, 2, 3 { @@ -5478,6 +5596,8 @@ #endif // HAS_BUTTON9_DEMO_INTERRUPT } // switch (Datalogger_action_table[i].digitalOutPin) // pin = button index 1, 2, 3 #endif // HAS_BUTTON1_DEMO_INTERRUPT + // don't allow onButton1FallingEdge() command processing to halt the datalog + Datalogger_Trigger = saved_Datalogger_Trigger; } // case action_button break; case action_trigger_Halt: @@ -5613,6 +5733,10 @@ need_reinit = false; #endif // defined(SPI_ADC_DeviceName) // SPI connected ADC } +#if USE_DATALOGGER_REMARK_FIELD + // Datalogger_PrintRow() print gstrRemarkText field from recent #remark -- in void Datalogger_PrintRow() + cmdLine.serial().printf(",\"%s\"", gstrRemarkText); +#endif // USE_DATALOGGER_REMARK_FIELD cmdLine.serial().printf("\r\n"); if (need_reinit) { //~ delay(500); // platform_delay_ms 500ms timing delay function