/* ===== pfod Command for PIC Data Logging ==== pfodApp msg {.} --> {,<+3>~PIC Led Control`0~V3|A`0~Led is ~~Off\On~|B~Plot of Random Data} */ /* * File: pfodMenu.c */ /* Code generated by pfodDesignerV2 V2.0.2182 * (c)2014-2016 Forward Computing and Control Pty. Ltd. * NSW Australia, www.forward.com.au * This generated code may be freely used for both private and commercial use */ #include "pfodMenu.h" #include "pfodParser.h" uint8_t pfodParser_connected; // set true (1) when {.} parsed, set false (0) when {!} parsed. int cmd_A_var; // name the variable for 'Led is' 0=Off 1=On // plotting data variables volatile uint8_t pfodParser_sendDataFlag; // set this to true (1) to send data, it is reset to false (0) by pfodParser_sendData() volatile unsigned long plot_X_var; // X axis defaults to an incrementing counter unless your code assigns a value to plot_X_var before each pfodParser_sendData() call. volatile int plot_1_var; volatile int plot_2_var; // plot 3 is hidden void pfodParser_sendMainMenu(void); void pfodParser_sendMainMenuUpdate(void); void pfodParser_sendData(void); void pfodParser_setup(void) { pfodParser_pfodParser("V3"); // initialize the pfodParser and set the version pfodParser_connected = 0; // set true (1) when {.} parsed, set false (0) when {!} parsed. pfodParser_sendDataFlag = 0; // set this to true to send data, it is reset to false by pfodParser_sendData(). cmd_A_var = 0; plot_X_var = 0; plot_1_var = 0; plot_2_var = -1; } void pfodParser_parse(void) { uint8_t cmd = pfodParser_parse_RX(); // parse incoming data from connection // parser returns non-zero when a pfod command is fully parsed if (cmd != 0) { // have parsed a complete msg { to } uint8_t* pfodFirstArg = pfodParser_getFirstArg(); // may point to \0 if no arguments in this msg. long pfodLongRtn; // used for parsing long return arguments, if any if ('.' == cmd) { // pfodApp has connected and sent {.} , it is asking for the main menu pfodParser_connected = 1; // set this true first to enable parser prints if (!pfodParser_isRefresh()) { pfodParser_sendMainMenu(); // send back the menu designed } else { pfodParser_sendMainMenuUpdate(); // menu is cached just send update } // now handle commands returned from button/sliders } else if('A'==cmd) { // user moved slider -- 'Led is' // in the main Menu of PIC Data Logging // set output based on slider 0=Off 1=On pfodParser_parseLong(pfodFirstArg,&pfodLongRtn); // parse first arg as a long cmd_A_var = (int)pfodLongRtn; // set variable pfodParser_sendMainMenuUpdate(); // always send back a pfod msg otherwise pfodApp will disconnect. } else if('B'==cmd) { // user pressed -- 'Plot of Random Data' // in the main Menu of PIC Data Logging // return plotting msg. pfodParser_printStr("{=PIC Data|count|Random Data~~~|Led setting~2~-1~LED (On=1)|}"); } else if ('!' == cmd) { // CloseConnection command pfodParser_connected = 0; } else { // unknown command pfodParser_printStr("{}"); // always send back a pfod msg otherwise pfodApp will disconnect. } } pfodParser_sendData(); // send data only if both pfodParser_connected and pfodParser_sendDataFlag are true } /** * Send global plot variables * if and only if both pfodParser_connected and pfodParser_sendDataFlag are true * X axis defaults to an incrementing counter unless your code assigns a value to plot_X_var before each pfodParser_sendData() call. */ void pfodParser_sendData(void) { if (!pfodParser_sendDataFlag) { return; } pfodParser_sendDataFlag = 0; // send plot data in CSV format pfodParser_printLong(plot_X_var); pfodParser_printCh(','); pfodParser_printLong(plot_1_var); pfodParser_printCh(','); pfodParser_printLong(plot_2_var); pfodParser_printCh(','); // Plot 3 is hidden in pfodDesignerV2. No data sent. pfodParser_println(); // end of CSV data record plot_X_var++; } void pfodParser_sendMainMenu(void) { // !! Remember to change the parser version string // every time you edit this method pfodParser_printStr("{,"); // start a Menu screen pfod message // send menu background, format, prompt, refresh and version pfodParser_printStr("<+3>~PIC Led Control`0"); pfodParser_sendVersion(); // send the menu version // send menu items pfodParser_printStr("|A"); pfodParser_printCh('`'); pfodParser_printLong(cmd_A_var); // output the current value pfodParser_printStr("~Led is ~~Off\\On~"); // Note the \\ inside the "'s to send \ ... pfodParser_printStr("|B"); pfodParser_printStr("~Plot of Random Data"); pfodParser_printStr("}"); // close pfod message } void pfodParser_sendMainMenuUpdate(void) { pfodParser_printStr("{;"); // start an Update Menu pfod message // send menu items pfodParser_printStr("|A"); pfodParser_printCh('`'); pfodParser_printLong(cmd_A_var); // output the current value pfodParser_printStr("}"); // close pfod message // ============ end of menu =========== } int pfodParser_swap01(int in) { return (in==0)?1:0; }