/* ===== pfod Command for Video 12 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 #include // int swap01(int); // method prototype for slider end swaps // float col; //variable just for displaying column float row; //variable just for displaying row int ctb = 10; //used a separate variable for column touched in touchZone 'b' so as to not interfere with col in touchZone 'a' int rtb = 70; //used a separate variable for row touched in touchZone 'b' so as to not interfere with row in touchZone 'a' byte showFlagCnt = 0; //just a usefull flag to increment with // 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 } // 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 12 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('a' == dwgCmd) { col = parser.getTouchedCol(); row = parser.getTouchedRow(); } if('b' == dwgCmd) { ctb = parser.getTouchedCol(); rtb = parser.getTouchedRow(); // if((ctb + 10) > 195) { ctb = 175; } if((rtb + 10) > 130) { rtb = 105; } } if('c' == dwgCmd) { showFlagCnt++; } if('s' == dwgCmd) { rtb-= 5; } if('t' == dwgCmd) { rtb+= 5; } 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 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>~User Touches 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 create a touchzone dwgs.rectangle().size(150, 40).offset(10, 10).color(142).rounded().filled().send(); //button dwgs.label().fontSize(8).bold().offset(80.00, 30.00).color(1).text(F("Drag Selection Input\n(Filter 2, Drag)")).send(); //label dwgs.touchZone().cmd('a').size(140, 30).offset(15.00, 15.00).filter(2).send(); //create a touchzone here, filter drag dwgs.touchZone().cmd('b').size(140, 50).offset(10.00, 70.00).filter(1).send(); //create a touchzone here, filter touch dwgs.label().fontSize(8).bold().offset(130, 80).text(F("Just\nTouch\n(Filter 1, Down)")).color(0).send(); // dwgs.touchZone().cmd('c').size(50, 50).offset(15.00, 145.00).filter(5).send(); //create a touchzone here, filter touch and up dwgs.touchZone().cmd('d').size(30, 30).offset(85.00, 145.00).filter(4).send(); //create a touchzone here, just touch dwgs.touchZone().cmd('e').size(30, 30).offset(145.00, 145.00).filter(16).send(); //create a touchzone here, long press dwgs.touchZone().cmd('s').size(0.1, 0.1).offset(180.00, 80.00).filter(0).send(); //create a touchzone here, for move rect ^ dwgs.touchZone().cmd('t').size(0.1, 0.1).offset(180.00, 95.00).filter(0).send(); //create a touchzone here, for move rect v dwgs.rectangle().size(10, 10).offset(175, 75).color(0).rounded().filled().send(); //button for rect ^ dwgs.rectangle().size(10, 10).offset(175, 90).color(0).rounded().filled().send(); //button for rect v dwgs.label().fontSize(12).bold().offset(180, 82).text(F("^")).color(11).send(); dwgs.label().fontSize(9).bold().offset(180, 95).text(F("v")).color(11).send(); // dwgs.label().fontSize(8).bold().offset(170, 20).text(F("Col")).color(12).send(); dwgs.label().fontSize(8).bold().offset(187, 20).text(F("Row")).color(12).send(); dwgs.label().idx(1).fontSize(8).bold().offset(170, 30).floatReading(col).decimals(0).color(12).send(); dwgs.label().idx(2).fontSize(8).bold().offset(187, 30).floatReading(row).decimals(0).color(12).send(); dwgs.rectangle().idx(3).size(12, 12).offset(ctb, rtb).color(37).filled().send(); dwgs.rectangle().size(60, 60).offset(10, 140).color(165).filled().send(); dwgs.label().idx(5).fontSize(7).bold().offset(40, 165).text(F("Down to Show\nLift to Hide\n(Filter 1 & Filter 4)")).color(0).send(); dwgs.rectangle().size(40, 40).offset(80, 140).color(160).filled().send(); dwgs.label().fontSize(7).bold().offset(100, 160).text(F("When Stylus\nor Finger Up\n(Filter 4, Up)")).color(0).send(); dwgs.rectangle().size(40, 40).offset(140, 140).color(4).filled().send(); dwgs.label().fontSize(7).bold().offset(160, 160).text(F("Long Press\nNo Drag\n(Filter 16,\nLong Press)")).color(15).send(); dwgs.hide().idx(5).send(); 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.label().idx(1).fontSize(8).bold().offset(170, 30).floatReading(col).decimals(0).color(12).send(); //update variable col dwgs.label().idx(2).fontSize(8).bold().offset(187, 30).floatReading(row).decimals(0).color(12).send(); //update variable row dwgs.rectangle().idx(3).size(12, 12).offset(ctb, rtb).color(37).filled().send(); //move rectangle to spot touched if(showFlagCnt == 1) { dwgs.unhide().idx(5).send(); } if(showFlagCnt == 2) { dwgs.hide().idx(5).send(); showFlagCnt = 0; } dwgs.end(); } int swap01(int in) { return (in==0)?1:0; } // ============= end generated code =========