// Dwg_LedOn.cpp  file ==============
// generated by pfodWeb Designer Arduino Export V1.1.5 -- 19th September 2025
/*   
 * (c)2025 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.
 */

#include "Dwg_LedOn.h"
#include <pfodDebugPtr.h>

extern void turnLedOn();

//#define DEBUG
static Print* debugPtr = NULL;  // local to this file


static unsigned long dwgRefresh = 0;

Dwg_LedOn::Dwg_LedOn() {
  initialized = false;
}

void Dwg_LedOn::init() {
  if (initialized) {
    return;
  }
  initialized = true;
  (void)debugPtr;  // suppress unused warning
#ifdef DEBUG
  debugPtr = getDebugPtr();
#endif
  pfodDrawing::init();
}

// return true if handled else false
// either handle cmd here or in main sketch
bool Dwg_LedOn::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_c1)) { // handle touchZone cmd_c1
    // parserPtr->printDwgCmdReceived(debugPtr); // does nothing if passed NULL
    // add your cmd handling code here
    turnLedOn();
    return false; // pass msg upto pfodMainMenu to send full update
    //sendUpdate();
    //return true;
  }

  // if (debugPtr) { debugPtr->print("dwgCmd did not match:"); debugPtr->println(cmd_c1); }
  return false; // not handled
}

bool Dwg_LedOn::sendDwg() {
  if (!parserPtr->cmdEquals(*this)) {
    return false; // not this dwg's loadCmd
  }  // else
  if (parserPtr->isRefresh()) { // refresh just send update
    sendUpdate();
  } else {
    sendFullDrawing();
  }
  return true;
}

// all the indexed items are included here, edit as needed for updates
void Dwg_LedOn::sendIndexedItems() {
    dwgsPtr->rectangle().filled().centered().rounded().idx(idx_1).color(dwgsPtr->LIME).size(18,7).offset(25,12.5).send();
    dwgsPtr->label().idx(idx_2).color(dwgsPtr->RED).text("Turn Led On").bold().offset(25,12.5).center().decimals(2).send();
}
        
void Dwg_LedOn::sendFullDrawing() {
    // Start the drawing
    dwgsPtr->start(50, 25, dwgsPtr->BLUE);
    parserPtr->sendRefreshAndVersion(dwgRefresh); // sets version and refresh time for dwg pfodWeb processes this
    dwgsPtr->index().idx(idx_1).send(); // place holder for indexed item
    dwgsPtr->index().idx(idx_2).send(); // place holder for indexed item
    dwgsPtr->touchZone().cmd(cmd_c1).centered().size(18,7).offset(25,12.5).send();
    dwgsPtr->touchAction().cmd(cmd_c1).action(dwgsPtr->rectangle().filled().centered().idx(idx_1).color(dwgsPtr->SILVER).size(18,7).offset(25,12.5)).send();
    sendIndexedItems(); // update indexed items with their real values
    dwgsPtr->end();
}
        
// only indexed items can be sent as an update
// all the indexed items are included here, edit as needed
void Dwg_LedOn::sendUpdate() {
    dwgsPtr->startUpdate();
    sendIndexedItems(); // send updated indexed items        
    dwgsPtr->end();
}
// ============== end of Dwg_LedOn.cpp  file 
