//====================================================== // examples for C4001 wrapper //====================================================== #include char _statusStr[60]; const char* getStatusString() { cSFA(sfStatusStr, _statusStr); sfStatusStr.clear(); sSensorStatus_t status = _sensor->getStatus(); . . sfStatusStr.print(...); . . return sfStatusStr.c_str(); } int maxDist = getMaxRange(); void setMaxDist(const byte *inputBytes) { char* inputStr = (char*)inputBytes; // try converting to float float input = 0; // wrap in as SafeString cSFP(sfInputStr, inputStr); if (!sfInputStr.toFloat(input)) { Serial.print("Invalid MaxDist input: '"); Serial.print(input); Serial.println("'"); return; } // else valid float // limit to valid range 240~2000 int dist = (int)input; // get int if (dist < 240) { dist = 240; } if (dist > 2000) { dist = 2000; } // need to check consistency min <= trig <= max maxDist = dist; _sensor.setDetectionRange(minDist,maxDist,triggerDist); } //====================================================== //====================================================== // examples for updating Dwg_.. files //====================================================== // in Dwg_buttonSave handling save button #include "C4001_SafeString_Wrapper.h" bool Dwg_buttonSave::processDwgCmds() { // byte dwgCmd = parserPtr->parseDwgCmd(); // pfodParse calls this automagically before calling this method if (!(*(parserPtr->getDwgCmd()))) { // ==> getDwgCmd returned pointer to empty string return false; // not dwg cmd, not handled } if (parserPtr->dwgCmdEquals(cmd_button)) { // handle touchZone cmd_button // parserPtr->printDwgCmdReceived(debugPtr); // does nothing if passed NULL // add your cmd handling code here C4001_controls.buttonStart(); // handle start button sendUpdate(); return true; } // if (debugPtr) { debugPtr->print("dwgCmd did not match:"); debugPtr->println(cmd_c1); } return false; // not handled } // handling text inputs // e.g. in Dwg_TrigDistInput #include "C4001_SafeString_Wrapper.h" bool Dwg_TrigDistInput::processDwgCmds() { // byte dwgCmd = parserPtr->parseDwgCmd(); // pfodParse calls this automagically before calling this method if (!(*(parserPtr->getDwgCmd()))) { // ==> getDwgCmd returned pointer to empty string return false; // not dwg cmd, not handled } if (parserPtr->dwgCmdEquals(cmd_input)) { // handle touchZone cmd_input // parserPtr->printDwgCmdReceived(debugPtr); // does nothing if passed NULL // add your cmd handling code here C4001_controls.setTrigDist(parserPtr->getEditedText()); sendUpdate(); return true; } // if (debugPtr) { debugPtr->print("dwgCmd did not match:"); debugPtr->println(cmd_c1); } return false; // not handled } void Dwg_TrigDistInput::sendIndexedItems() { dwgsPtr->label().idx(idx_trigDist).color(dwgsPtr->WHITE).text("").fontSize(-16).bold().offset(2.5,0.5).left().decimals(0).value(C4001_controls.getTrigDist()).send(); } // handling sliders // Dwg_keepSlider.cpp #include "C4001_SafeString_Wrapper.h" bool Dwg_keepSlider::processDwgCmds() { // byte dwgCmd = parserPtr->parseDwgCmd(); // pfodParse calls this automagically before calling this method if (!(*(parserPtr->getDwgCmd()))) { // ==> getDwgCmd returned pointer to empty string return false; // not dwg cmd, not handled } if (parserPtr->dwgCmdEquals(cmd_buttonSlider)) { // handle touchZone cmd_buttonSlider // parserPtr->printDwgCmdReceived(debugPtr); // does nothing if passed NULL // add your cmd handling code here C4001_controls.setKeepSensitivity(parserPtr->getTouchedCol()); sendUpdate(); return true; } // if (debugPtr) { debugPtr->print("dwgCmd did not match:"); debugPtr->println(cmd_c1); } return false; // not handled } void Dwg_keepSlider::sendIndexedItems() { dwgsPtr->circle().filled().idx(idx_sliderButton).color(dwgsPtr->RED).radius(0.3).offset(C4001_controls.getKeepSensitivity(),1.5).send(); dwgsPtr->label().idx(idx_label).color(dwgsPtr->BLACK_WHITE).text("Keep Sensitivity ").fontSize(-12).offset(4.5,2.4).center().intValue(C4001_controls.getKeepSensitivity()).maxValue(9).minValue(0).displayMax(9).displayMin(0).decimals(0).send(); } //====================================================== // examples for .ino file setup() //====================================================== void setup() { . . . setDebugPtr(&Serial); //set global debug debugPtr = getDebugPtr(); // enable extra debug here Serial.println(" C4001.begin() "); if (!C4001.begin()) { while (1) { Serial.println("C4001 failed to start."); delay(3000); } } C4001_controls.setSensor(&C4001); . . . }