// Dwg_LedOnOff.cpp  file ==============
// generated by pfodWeb Designer Arduino Export V3.0.2 -- 15th Novemeber 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_LedOnOff.h"
#include <pfodDebugPtr.h>
extern bool isLedOn();

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

Dwg_LedOnOff dwg_LedOnOff;

#include "Dwg_LedOn.h"
#include "Dwg_LedOff.h"

static unsigned long dwgRefresh = 2000;

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

void Dwg_LedOnOff::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_LedOnOff::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 (debugPtr) { debugPtr->print("dwgCmd did not match:"); debugPtr->println(cmd_c1); }
  return false; // not handled
}

bool Dwg_LedOnOff::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_LedOnOff::sendIndexedItems() {
  if (isLedOn()) {
    dwgsPtr->label().idx(idx_1).color(dwgsPtr->RED).text("Led is ON").bold().offset(20,11.5).center().decimals(2).send();
  } else {
    dwgsPtr->label().idx(idx_1).color(dwgsPtr->BLACK).text("Led is Off").bold().offset(20,11.5).center().decimals(2).send();
  }
}
        
void Dwg_LedOnOff::sendFullDrawing() {
    // Start the drawing
    dwgsPtr->start(40, 15, dwgsPtr->SILVER);
    parserPtr->sendRefreshAndVersion(dwgRefresh); // sets version and refresh time for dwg pfodWeb processes this
    dwgsPtr->pushZero(-8, -3, 0.7);
    dwgsPtr->insertDwg().loadCmd(dwg_LedOn).offset(0,0).send();
    dwgsPtr->pushZero(29, 0, 1);
    dwgsPtr->insertDwg().loadCmd(dwg_LedOff).offset(0,0).send();
    dwgsPtr->popZero();
    dwgsPtr->popZero();
    dwgsPtr->index().idx(idx_1).send(); // place holder for indexed item
    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_LedOnOff::sendUpdate() {
    dwgsPtr->startUpdate();
    sendIndexedItems(); // send updated indexed items        
    dwgsPtr->end();
}
// ============== end of Dwg_LedOnOff.cpp  file 
