#include <PicoModel.h>
Public Member Functions | |
PicoModel () | |
void | onStart () |
float | getTemperature () |
void | setLedState (bool state) |
bool | getLedState () |
bool | getGpioState (int pin) |
void | setGpioState (int pin, bool state) |
void | saveState () |
void | restoreState () |
void | onNetworkReady () |
![]() | |
FrameworkModel (const std::string &path) | |
Constructor. | |
bool | load () |
Loads the JSON collection from storage. | |
bool | save () |
Saves the current collection to storage. | |
std::vector< nlohmann::json > | all () const |
Returns all items in the collection. | |
std::optional< nlohmann::json > | find (const std::string &id) const |
Finds an item by ID. | |
bool | create (const nlohmann::json &item) |
Adds a new item to the collection. | |
bool | update (const std::string &id, const nlohmann::json &updatedItem) |
Updates an item by ID. | |
bool | remove (const std::string &id) |
Removes an item by ID. | |
nlohmann::json | toJson () const |
Returns the full collection as a JSON array object. | |
nlohmann::json | findAsJson (const std::string &id) const |
Finds a single item by ID and returns it as JSON or null. | |
bool | save (const std::string &id, const json &data) |
Saves a single item by ID and JSON object. | |
bool | createFromJson (const nlohmann::json &obj) |
bool | updateFromJson (const std::string &id, const nlohmann::json &updates) |
nlohmann::json | deleteAsJson (const std::string &id) |
bool | saveAll () |
template<typename T > | |
T | getValue (const std::string &key, const T &defaultValue=T()) |
Reads a single top-level key from the model file. | |
template<typename T > | |
void | setValue (const std::string &key, const T &value) |
Sets a single top-level key in the model file. | |
Private Attributes | |
std::vector< int > | activePins = { 2, 3, 4, 5, 6, 7, 8, 9, 16, 17, 18, 19 } |
bool | suppressSave = false |
Additional Inherited Members | |
![]() | |
virtual std::string | getIdField () const |
Returns the JSON key used as the record ID. | |
![]() | |
nlohmann::json | collection = nlohmann::json::array() |
In-memory array of records. | |
Definition at line 5 of file PicoModel.h.
PicoModel::PicoModel | ( | ) |
Definition at line 13 of file PicoModel.cpp.
bool PicoModel::getGpioState | ( | int | pin | ) |
Definition at line 53 of file PicoModel.cpp.
Referenced by GpioController::getState(), GpioController::handleGetMultipleGpios(), and saveState().
bool PicoModel::getLedState | ( | ) |
Definition at line 43 of file PicoModel.cpp.
Referenced by DashboardController::getLedState(), saveState(), and setLedState().
float PicoModel::getTemperature | ( | ) |
Definition at line 24 of file PicoModel.cpp.
Referenced by DashboardController::getTemperature().
void PicoModel::onNetworkReady | ( | ) |
Definition at line 86 of file PicoModel.cpp.
References FrameworkModel::getValue(), setLedState(), and suppressSave.
Referenced by App::onEvent().
void PicoModel::onStart | ( | ) |
Definition at line 18 of file PicoModel.cpp.
References restoreState().
Referenced by App::onStart().
void PicoModel::restoreState | ( | ) |
Definition at line 95 of file PicoModel.cpp.
References FrameworkModel::getValue(), Network::isConnected(), FrameworkModel::load(), setGpioState(), setLedState(), and suppressSave.
Referenced by onStart().
void PicoModel::saveState | ( | ) |
Definition at line 70 of file PicoModel.cpp.
References activePins, getGpioState(), getLedState(), FrameworkModel::save(), and FrameworkModel::setValue().
Referenced by setGpioState(), and setLedState().
void PicoModel::setGpioState | ( | int | pin, |
bool | state | ||
) |
Definition at line 59 of file PicoModel.cpp.
References saveState(), and suppressSave.
Referenced by restoreState(), and GpioController::setState().
void PicoModel::setLedState | ( | bool | state | ) |
Definition at line 34 of file PicoModel.cpp.
References getLedState(), saveState(), FrameworkModel::setValue(), and suppressSave.
Referenced by onNetworkReady(), restoreState(), and DashboardController::setLedState().
|
private |
Definition at line 31 of file PicoModel.h.
Referenced by saveState().
|
private |
Definition at line 33 of file PicoModel.h.
Referenced by onNetworkReady(), restoreState(), setGpioState(), and setLedState().