#include <Arduino.h>
#include <DisplayCore.h>
#include "board_profile.h"
#include "display.h"
#include "sensors.h"
#include "ui.h"
#include "network.h"
#include "storage.h"
bool ready=false,storageOk=false;uint32_t drawn=0;
void setup(){Serial.begin(115200); if(!kElectricalReviewComplete){Serial.println("STOP: complete wiring/power review in guide before enabling hardware.");return;}beginDisplay();beginSensors();
 #if DISPLAY_STAGE >= 3
 storageOk=beginStorage();beginUi(loadPage());beginNetwork();
 #else
 beginUi(0);
 #endif
 ready=true;}
 void loop(){if(!ready)return;uint32_t now=millis();pollSensors(now);const bool changed=pollUi(now);
 #if DISPLAY_STAGE >= 3
 pollNetwork();if(changed)storageOk=savePage(page());
 #endif
 if(!changed&&!displaylab::elapsed(now,drawn,250))return;drawn=now;
 #if DISPLAY_STAGE == 1
 drawConsole(0,reading(),false,0,false);
 #elif DISPLAY_STAGE == 2
 drawConsole(page(),reading(),false,0,false);
 #else
 drawConsole(page(),reading(),networkFresh(now),networkValue(),storageOk);
 #endif
 }
