1#include <pico/cyw43_arch.h>
2#include <hardware/adc.h>
27 adc_set_temp_sensor_enabled(
true);
29 float voltage = adc_read() * (3.3f / (1 << 12));
30 return 27.0f - (voltage - 0.706f) / 0.001721f;
36 cyw43_arch_gpio_put(0, state ? 1 : 0);
45 if (cyw43_is_initialized){
46 return cyw43_arch_gpio_get(0);
55 bool state = gpio_get(pin);
62 gpio_set_dir(pin, GPIO_OUT);
82 printf(
"[PicoModel] Saving state to storage...\n");
90 bool ledState =
getValue(
"led",
false);
99 printf(
"[PicoModel] Restoring state from storage...\n");
104 bool ledState =
getValue(
"led",
false);
109 printf(
"[PicoModel] Network not connected, deferring LED initialization\n");
113 auto gpioStates = getValue<json>(
"gpio_states", {});
114 for (
auto &[pinStr, stateJson] : gpioStates.items())
116 int pin = std::stoi(pinStr);
117 bool state = stateJson.get<
bool>();
Manages Wi-Fi initialization, connection status, and power management for Pico W.
RAII-style scoped flag setter. Temporarily sets a boolean flag and restores it on destruction.
Provides a basic JSON-backed record model.
bool load()
Loads the JSON collection from storage.
T getValue(const std::string &key, const T &defaultValue=T())
Reads a single top-level key from the model file.
bool save()
Saves the current collection to storage.
void setValue(const std::string &key, const T &value)
Sets a single top-level key in the model file.
static bool isConnected()
Check whether the device is connected to Wi-Fi.
void setLedState(bool state)
void setGpioState(int pin, bool state)
bool getGpioState(int pin)
std::vector< int > activePins
Temporarily sets a boolean flag and restores it automatically.