/* ===== pfod Command for Video 11 Template ==== pfodApp msg {.} --> {,~`0~V1|+A~z} */ // Using Serial and 9600 baud for send and receive // Flora Bluefruit LE or Bluefruit LE UART Friend /* Code generated by pfodDesignerV3 V3.0.3630 */ /* * (c)2014-2018 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. */ // download the libraries from http://www.forward.com.au/pfod/pfodParserLibraries/index.html // pfodParser.zip V3.35+ contains pfodParser, pfodSecurity, pfodDelay, pfodBLEBufferedSerial, pfodSMS and pfodRadio #include // pfodDwgControls.zip V1.0+ contains pfodDwgControls.h includes DesignerSwitch.h #include int swap01(int); // method prototype for slider end swaps const int MAX_MULTI_SELECTIONS = 7; //max 7 possible selections out of all possible, //***** long multiSelections[MAX_MULTI_SELECTIONS]; // -1 means not selected //***** int multiSe0 = 0; int multiSe1 = 0; int multiSe2 = 0; int multiSe3 = 0; int multiSe4 = 0; int multiSe5 = 0; int multiSe6 = 0; pfodParser parser("V2"); // create a parser to handle the pfod messages unsigned long plot_mSOffset = 0; // set by {@} response bool clearPlot = false; // set by the {@} response code pfodDwgs dwgs(&parser); // drawing support // Commands for drawing controls only need to unique per drawing, you can re-use cmd 'a' in another drawing. // the setup routine runs once on reset: void setup() { Serial.begin(9600); for (int i=3; i>0; i--) { // wait a few secs to see if we are being programmed delay(1000); } parser.connect(&Serial); // connect the parser to the i/o stream // <<<<<<<<< Your extra setup code goes here for (int i = 0; i < MAX_MULTI_SELECTIONS; i++) { //***** multiSelections[i] = -1; // empty //***** } //***** } // the loop routine runs over and over again forever: void loop() { 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(); // send back the menu designed } else { sendMainMenuUpdate(); // menu is cached just send update } // 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('A'==cmd) { // user pressed menu item that loaded drawing with load cmd 'z' // in the main Menu of Video 11 Template byte dwgCmd = parser.parseDwgCmd(); // parse rest of dwgCmd, return first char of active cmd // can be \0 if no dwg or no active areas defined // << Modify this code for your own controls if(dwgCmd == 'a') { sendMultiSelectionScreen(); } } else if ('b' == cmd) { // return from multi selection input byte* argIdx = pfodFirstArg; // pickup the first arg which is the number // will be null if no arges int i = 0; multiSe0 = 0; multiSe1 = 0; multiSe2 = 0; multiSe3 = 0; multiSe4 = 0; multiSe5 = 0; multiSe6 = 0; for (; (i < MAX_MULTI_SELECTIONS) && (*argIdx != 0); i++) { argIdx = parser.parseLong(argIdx, &multiSelections[i]); Serial.println(multiSelections[i]); //argIdx will be null after last arg is parsed } if (i < MAX_MULTI_SELECTIONS) { // add a -1 to terminate the array of indices multiSelections[i] = -1; } sendDrawingUpdates_z(); } else if ('z' == cmd) { // pfodApp is asking to load dwg 'z' if (!parser.isRefresh()) { // not refresh, send whole dwg parser.parseLong(pfodFirstArg,&pfodLongRtn); // parse first arg as a long sendDrawing_z(pfodLongRtn); } else { // refresh just update drawing state sendDrawingUpdates_z(); } } else if ('!' == cmd) { // CloseConnection command closeConnection(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 closeConnection(Stream *io) { // add any special code here to force connection to be dropped } void sendMultiSelectionScreen() { parser.print(F("{*b")); // add the current selections for (int i = 0; i < MAX_MULTI_SELECTIONS; i++) { long index = multiSelections[i]; if (index < 0) { break; } // else parser.print(F("`")); parser.print(index); } parser.print(F("~Multi-selection" "|Value 0|Value 1|Value 2|Value 3|Value 4|Value 5|Value 6}")); } void sendMainMenu() { // !! Remember to change the parser version string // every time you edit this method parser.print(F("{,")); // start a Menu screen pfod message // send menu background, format, prompt, refresh and version parser.print(F("<-1>~Multi Selection Input Menu`0")); //************************************************************************************** parser.sendVersion(); // send the menu version // send menu items parser.print(F("|+A~z")); parser.print(F("}")); // close pfod message } void sendMainMenuUpdate() { parser.print(F("{;")); // start an Update Menu pfod message // send menu items parser.print(F("|+A")); parser.print(F("}")); // close pfod message // ============ end of menu =========== } void sendDrawing_z(long dwgIdx) { if (dwgIdx == 0) { sendDrawing_z0(); } else if (dwgIdx == 1) { sendDrawing_z1(); // add more parts of the dwg here if needed } else { parser.print(F("{}")); // always return somthing } } void sendDrawing_z0() { //********************************************************************************************************* dwgs.start(200, 225, dwgs.WHITE,true); //true means more to come, background defaults to WHITE if omitted i.e. dwgs.start(50,30); parser.sendRefreshAndVersion(0); // send the parser version to cache this image, no auto-refresh //****************************** //create a rounded rectangle button, with a label on it, and a touchzone //****************************************************** dwgs.rectangle().size(60, 10).offset(110.00, 10).color(142).rounded().filled().send(); //button //******************************* dwgs.label().fontSize(6).bold().offset(140.00, 15.00).color(1).text(F("Multi Selection Input")).send(); //label //********************** dwgs.touchZone().cmd('a').size(50, 0.1).offset(115.00, 15.00).send(); //create a touchzone here //****************************** dwgs.end(); //********************************************************************************************************** } //********************************************************************************************************** void sendDrawing_z1() { dwgs.startUpdate(true); //true means more to come, // empty date so pfodApp will not ask for more dwgs.end(); } void sendDrawingUpdates_z() { //*************************************************************************************************** dwgs.startUpdate(); // dwg refresh updates must be <1024 bytes, i.e. can only be 1 msg //*************************************** dwgs.end(); //*************************************************************************************************** } int swap01(int in) { return (in==0)?1:0; } // ============= end generated code ========= /* const int MAX_MULTI_SELECTIONS = 7; //max 7 possible selections out of all possible, //******************************************** long multiSelections[MAX_MULTI_SELECTIONS]; // -1 means not selected //************************************************************ if(dwgCmd == 'a') { //******************************************************************************************************** sendMultiSelectionScreen(); //******************************************************************************************* } //******************************************************************************************************* } else if ('b' == cmd) { //********************************************************************************** // return from multi selection input //********************************************************************************** byte* argIdx = pfodFirstArg; // pickup the first arg which is the number // will be null if no arges //********************************************************************************** int i = 0; //********************************************************************************** for (; (i < MAX_MULTI_SELECTIONS) && (*argIdx != 0); i++) { //************************************************************** argIdx = parser.parseLong(argIdx, &multiSelections[i]); //****************************************************************** Serial.println(multiSelections[i]); //********************************************************************************** //argIdx will be null after last arg is parsed //********************************************************************** } if (i < MAX_MULTI_SELECTIONS) { //********************************************************************************** // add a -1 to terminate the array of indices //******************************************************************* multiSelections[i] = -1; //**************************************************************************************** } //parser.print(F("{}")); sendDrawingUpdates_z(); void sendMultiSelectionScreen() { //***************************************************************************************** parser.print(F("{*b")); //************************************************************************************************ // add the current selections //******************************************************************************************* for (int i = 0; i < MAX_MULTI_SELECTIONS; i++) { //*********************************************************************** long index = multiSelections[i]; //************************************************************************************** if (index < 0) { //******************************************************************************************** break; //******************************************************************************************* } // else //******************************************************************************************* parser.print(F("`")); //******************************************************************************************* parser.print(index); //******************************************************************************************* } //******************************************************************************************* parser.print(F("~Multi-selection" //******************************************************************************************* "|Value 0|Value 1|Value 2|Value 3|Value 4|Value 5|Value 6}")); //*********************************************** } //******************************************************************************************** void sendDrawing_z0() { //********************************************************************************************************* dwgs.start(200, 225, dwgs.WHITE,true); //true means more to come, background defaults to WHITE if omitted i.e. dwgs.start(50,30); parser.sendRefreshAndVersion(0); // send the parser version to cache this image, no auto-refresh //****************************** //create a rounded rectangle button, with a label on it, and a touchzone //****************************************************** dwgs.rectangle().size(40, 10).offset(100.00, 10).color(142).rounded().filled().send(); //button //******************************* dwgs.label().fontSize(7).bold().offset(120.00, 15.00).color(1).text(F("Multi Input")).send(); //label //********************** dwgs.touchZone().cmd('a').size(30, 0.1).offset(105.00, 15.00).send(); //create a touchzone here //****************************** dwgs.end(); //********************************************************************************************************** } //********************************************************************************************************** void sendDrawingUpdates_z() { //*************************************************************************************************** dwgs.startUpdate(); // dwg refresh updates must be <1024 bytes, i.e. can only be 1 msg //*************************************** dwgs.end(); //*************************************************************************************************** } FOR BRIANS USE ONLY ******************FOR BRIANS USE ONLY******************************************* Serial.print("multiSe0 = "); Serial.println(multiSe0); Serial.print("multiSe1 = "); Serial.println(multiSe1); Serial.print("multiSe2 = "); Serial.println(multiSe2); Serial.print("multiSe3 = "); Serial.println(multiSe3); Serial.print("multiSe4 = "); Serial.println(multiSe4); Serial.print("multiSe5 = "); Serial.println(multiSe5); Serial.print("multiSe6 = "); Serial.println(multiSe6); if(multiSelections[i] == 0) { multiSe0 = 1; } if(multiSelections[i] == 1) { multiSe1 = 1; } if(multiSelections[i] == 2) { multiSe2 = 1; } if(multiSelections[i] == 3) { multiSe3 = 1; } if(multiSelections[i] == 4) { multiSe4 = 1; } if(multiSelections[i] == 5) { multiSe5 = 1; } if(multiSelections[i] == 6) { multiSe6 = 1; } //************************************************************************************************************ byte multiSe0; byte multiSe1; byte multiSe2; byte multiSe3; byte multiSe4; byte multiSe5; byte multiSe6; //multi select flags //************************************************************************************************************ */