// Board: Non-Arduino CPP code // Connection: Serial /* Code generated by pfodWeb V4.1.20-- 14th Nov 2026 * (c)2026 Forward Computing and Control Pty. Ltd. * NSW Australia, www.forward.com.au * This code is not warranted to be fit for any purpose. You may only use it at your own risk. * This generated code may be freely used for both private and commercial use * provided this copyright is maintained. */ /* ===== pfod Command for OnOff_serial ==== pfodApp msg {.} --> {,~<+3>Example Menu<-3> with 4 menu items On/Off item, label, Dwg item, label`0~V1|c0`0~<+2>Led is ~~Off\On~|!c1~On/Off Menu Item|c2~LedOnOff|!c3~A Dwg Menu Item with 2 buttons} */ // pfodMainMenu.cpp #include "pfodMainMenu.h" #include #include #include "Dwg_LedOnOff.h" // #define DEBUG pfodMainMenu mainMenu; // weak: defining this function in any other .cpp replaces it, which is // how a subclass takes over without editing this file -- see pfodMainMenu.h pfodMainMenu& __attribute__((weak)) get_pfodMainMenu() { return mainMenu; } // Pin settings // Fill in the appropriate pin nos for your board here static pfodPrint* debugPtr = NULL; // local to this file static const unsigned long refresh_ms = 0; // main menu refresh const char* mainMenuPromptText_var = "<+3>Example Menu<-3>\nwith 4 menu items\nOn/Off item, label, Dwg item, label"; // current prompt text -- change this + call sendMainMenu() or sendMainMenuUpdate() to update the prompt int onOffOut_var = 0; // name the variable for 'Led is' 0=Off 1=On const char* label_var = "On/Off Menu Item"; // current text for 'On/Off Menu Item' -- change this + call sendMainMenu() to update the label (see docs/pfodAI-guide.md §6.3a to also push it via sendMainMenuUpdate()) const char* label_2_var = "A Dwg Menu Item with 2 buttons"; // current text for 'A Dwg Menu Item with 2 buttons' -- change this + call sendMainMenu() to update the label (see docs/pfodAI-guide.md §6.3a to also push it via sendMainMenuUpdate()) unsigned long plot_msOffset = 0; // set by {@} response bool clearPlot = false; // set by the {@} response code void pfodMainMenu::onOffOut_Changed(int value) { // 'Led is' (void)value; } pfodMainMenu::pfodMainMenu() { initialized = false; closeConnectionFnPtr = NULL; } // Sets the close-connection callback, then calls the (virtual) one-arg init(), // so a subclass overrides just the one-arg version. void pfodMainMenu::init(pfodCloseConnectionPtr _closeConnectionFnPtr, pfodParser& primingParser) { if (!initialized) { closeConnectionFnPtr = _closeConnectionFnPtr; } init(primingParser); } void pfodMainMenu::init(pfodParser& primingParser) { if (initialized) { return; } (void)debugPtr; // suppress not used warning #ifdef DEBUG debugPtr = getDebugPtr(); #endif initialized = true; // Primes this menu by sending it once to primingParser, muted with // setStream(NULL) so nothing reaches a client, then the stream is restored. // Runs BEFORE the drawings and sub-menus below, which are passed the same parser. pfodStream* savedStream = primingParser.getPfodAppStream(); primingParser.setStream(NULL); // priming output is discarded sendMainMenu(primingParser); // before any included dwgs or submenus to match later gets higher idx primingParser.setStream(savedStream); get_dwg_LedOnOff().init(primingParser); // initialize drawing -- 'LedOnOff' } // the loop routine runs over and over again forever: void pfodMainMenu::handle(pfodParser& parser) { if (!initialized) { if (debugPtr) { debugPtr->println(F(" Need to call init_pfodMainMenu() from setup().")); } } uint8_t cmd = parser.parse(); // 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 = parser.getFirstArg(); // may point to \0 if no arguments in this msg. pfod_MAYBE_UNUSED(pfodFirstArg); // may not be used, just suppress warning long pfodLongRtn; // used for parsing long return arguments, if any pfod_MAYBE_UNUSED(pfodLongRtn); // may not be used, just suppress warning if ('.' == cmd) { // pfodApp has connected and sent {.} , it is asking for the main menu if (!parser.isRefresh()) { sendMainMenu(parser); // send back the menu designed -- '<+3>Example Menu<-3> with 4 menu items On/Off item, label, Dwg item, label' } else { sendMainMenuUpdate(parser); // menu is cached just send update -- '<+3>Example Menu<-3> with 4 menu items On/Off item, label, Dwg item, label' } // handle {@} request } else if('@'==cmd) { // pfodApp requested 'current' time plot_msOffset = millis(); // capture current millis as offset rawdata timestamps clearPlot = true; // clear plot on reconnect as have new plot_msOffset parser.print(F("{@`0}")); // return `0 as 'current' raw data milliseconds // now handle commands returned from button/sliders } else if(parser.cmdEquals(onOffOut_Cmd)) { // user moved slider -- 'Led is' parser.parseLong(pfodFirstArg,&pfodLongRtn); // parse first arg as a long onOffOut_var = (int)pfodLongRtn; // set variable onOffOut_Changed(onOffOut_var); // virtual hook -- hardware/action handling sendMainMenuUpdate(parser); // always send back a pfod msg otherwise pfodApp will disconnect. // } else if(parser.cmdEquals(label_Cmd)) { // pfodApp NEVER sends this cmd -- 'On/Off Menu Item' } else if(parser.cmdEquals(dwg_Cmd)) { // user touch not handled by dwg -- 'LedOnOff', handle it here // drawing loadCmd handled internally by get_dwg_xxx().init() // add touchZone handling here and return response for inputs that return false from processDwgCmds() sendMainMenuUpdate(parser); // always send back a pfod msg otherwise pfodApp will disconnect. // } else if(parser.cmdEquals(label_2_Cmd)) { // pfodApp NEVER sends this cmd -- 'A Dwg Menu Item with 2 buttons' } else if ('!' == cmd) { // CloseConnection command if (closeConnectionFnPtr) { closeConnectionFnPtr(parser.getPfodAppStream()); } } else { // unknown command parser.print(F("{}")); // always send back a pfod msg otherwise pfodApp will disconnect. } } // <<<<<<<<<<< Your other loop() code goes here } void pfodMainMenu::sendMainMenu(pfodParser& parser) { // !! Remember to change the parser version string OR Clear the cache // every time you edit this method parser.menu(); // start a Menu screen pfod message. Send {, // send menu background, format, prompt, refresh and version parser.print(F("~")); // background silver parser.print(mainMenuPromptText_var); // output the current prompt text parser.sendRefreshAndVersion(refresh_ms); // send the menu version // send menu items parser.slider(onOffOut_Cmd); // start Slider parser.print(F("<+2>")); // background light blue, +2 size, bold, black text parser.print('`'); parser.print(onOffOut_var); // output the current value parser.print(F("~Led is ~~Off\\On~")); // Note the \\\\ inside the ' 's to send \\ ... parser.label(label_Cmd); // start Label parser.print(F("")); // background silver parser.print(F("~")); parser.print(label_var); // output the current text parser.print(F("|+")); // start Drawing parser.print(dwg_Cmd); // drawing menu item cmd -- 'LedOnOff' parser.print(F("")); // background silver parser.print(F("~")); parser.print(get_dwg_LedOnOff()); // the drawing's loadCmd parser.label(label_2_Cmd); // start Label parser.print(F("")); // background silver parser.print(F("~")); parser.print(label_2_var); // output the current text parser.endOfMsg(); // close pfod message. Send } } void pfodMainMenu::sendMainMenuUpdate(pfodParser& parser) { parser.menuUpdate(); // start an Update Menu pfod message. Send {; // send menu items that should be updated parser.slider(onOffOut_Cmd); // start Slider parser.print('`'); parser.print(onOffOut_var); // output the current value parser.print(F("|+")); // drawing menu item update parser.print(dwg_Cmd); // -- 'LedOnOff' parser.endOfMsg(); // close pfod message. Send } // ============ end of menu =========== } // The only place a priming pfodParser is created. noinline keeps it out of // init_pfodMainMenu()'s own stack frame, so the Serial/BLE path never reserves it. static void __attribute__((noinline)) init_pfodMainMenuWithTempParser(pfodCloseConnectionPtr _closeConnectionFnPtr) { pfodParser primingParser; // io NULL, so its output is discarded get_pfodMainMenu().init(_closeConnectionFnPtr, primingParser); // NULL closeFn is fine, it is stored as is } // HTTP/TCP: no sketch parser at init time, so prime via one temporary parser. handle_mainMenuFnPtr init_pfodMainMenu(pfodCloseConnectionPtr _closeConnectionFnPtr) { init_pfodMainMenuWithTempParser(_closeConnectionFnPtr); return handle_pfodMainMenu; } // Serial/BLE: prime via the sketch's own parser (muted while priming). handle_mainMenuFnPtr init_pfodMainMenu(pfodCloseConnectionPtr _closeConnectionFnPtr, pfodParser& primingParser) { get_pfodMainMenu().init(_closeConnectionFnPtr, primingParser); // NULL closeFn is fine, it is stored as is return handle_pfodMainMenu; } void handle_pfodMainMenu(pfodParser& parser) { get_pfodMainMenu().handle(parser); } // ============= end generated code =========