#pragma once #include #include #include #include #include class ESP32FlatPanel : public INDI::DefaultDevice, public INDI::LightBoxInterface, public INDI::DustCapInterface { public: ESP32FlatPanel(); ~ESP32FlatPanel() override; // DefaultDevice const char* getDefaultName() override; bool initProperties() override; bool updateProperties() override; bool Connect() override; bool Disconnect() override; void TimerHit() override; bool ISNewText (const char* dev, const char* name, char* texts[], char* names[], int n) override; bool ISNewSwitch(const char* dev, const char* name, ISState* states, char* names[], int n) override; bool ISNewNumber(const char* dev, const char* name, double values[], char* names[], int n) override; bool ISSnoopDevice(XMLEle* root) override; // LightBoxInterface bool SetLightBoxBrightness(uint16_t value) override; bool EnableLightBox(bool enable) override; // DustCapInterface IPState ParkCap() override; IPState UnParkCap() override; private: // ---- Connection mode switch ------------------------------------------ enum ConnMode { CONN_WIFI, CONN_USB }; ConnMode m_connMode { CONN_WIFI }; ISwitch ConnModeS[2]{}; ISwitchVectorProperty ConnModeSP; // ---- WiFi / Alpaca settings ------------------------------------------ IText HostT[2]{}; ITextVectorProperty HostTP; std::string m_host {"esp32-flatpanel.local"}; int m_port {11111}; uint32_t m_clientID {1}; uint32_t m_txID {0}; // ---- USB / Alnitak settings ------------------------------------------ IText SerialPortT[1]{}; ITextVectorProperty SerialPortTP; int m_serialFd {-1}; // ---- Dew heater property -------------------------------------------- INumber DewHeaterN[1]{}; INumberVectorProperty DewHeaterNP; // ---- CURL / HTTP helpers (WiFi mode) -------------------------------- static size_t writeCallback(void* ptr, size_t size, size_t nmemb, std::string* out); std::string httpGet(const std::string& endpoint); bool httpPut(const std::string& endpoint, const std::string& body); std::string alpacaURL(const std::string& endpoint) const; std::string commonPutBody(); int alpacaGetInt (const std::string& endpoint, int defaultVal = 0); bool alpacaGetBool(const std::string& endpoint, bool defaultVal = false); bool alpacaPutVoid(const std::string& endpoint, const std::string& extraBody = ""); // ---- Alnitak serial helpers (USB mode) ------------------------------ bool openSerial(const std::string& device); void closeSerial(); std::string sendAlnitak(const std::string& cmd); int alnitakGetBrightness(); bool alnitakSetBrightness(int b); int alnitakGetCoverState(); // returns Alpaca CoverStatus int int alnitakGetDewPercent(); bool alnitakSetDewPercent(int pct); // ---- Common helpers ------------------------------------------------- void setDewHeater(int pct); void pollState(); };