Skip to content

Commit

Permalink
Merge branch 'main' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
TokenRat committed Sep 1, 2024
2 parents a972939 + ce3b3ba commit 64608d3
Show file tree
Hide file tree
Showing 7 changed files with 123 additions and 92 deletions.
Binary file modified docs/assets/techspecs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
134 changes: 68 additions & 66 deletions lib/EFBoard/EFBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ RTC_DATA_ATTR uint32_t bootCount = 0;
volatile int8_t ota_last_progress = -1;

EFBoardClass::EFBoardClass()
: power_state(EFBoardPowerState::UNKNOWN) {
: power_state(EFBoardPowerState::UNKNOWN) {
bootCount++;
}

Expand Down Expand Up @@ -67,14 +67,17 @@ void EFBoardClass::setup() {
analogReadResolution(12);
LOG_DEBUG("(EFBoard) Set ADC read resolution to: 12 bit");
pinMode(EFBOARD_PIN_VBAT, INPUT);
LOG_INFO("(EFBoard) Inizialized battery sense ADC")
LOG_INFO("(EFBoard) Initialized battery sense ADC")

// Check power state
const EFBoardPowerState pwrstate = this->getPowerState();
if (pwrstate == EFBoardPowerState::BAT_BROWN_OUT_HARD) {
LOGF_ERROR("(EFBoard) HARD BROWN OUT DETECTED (V_BAT = %.2f V). Panic!\r\n", this->getBatteryVoltage());
while(1) {
delay(1000);
while (1) {
// TODO: use actual hard brownout code here
// sleep most of the time.
esp_sleep_enable_timer_wakeup(5 * 1000000);
esp_light_sleep_start();
}
} else if (pwrstate == EFBoardPowerState::BAT_BROWN_OUT_SOFT) {
LOGF_WARNING("(EFBoard) Soft brown out detected (V_BAT = %.2f V)\r\n", this->getBatteryVoltage());
Expand All @@ -98,16 +101,16 @@ unsigned int EFBoardClass::getWakeupCount() {
return bootCount;
}

const char* EFBoardClass::getWakeupReason() {
const char *EFBoardClass::getWakeupReason() {
esp_sleep_wakeup_cause_t wakeup_reason;
wakeup_reason = esp_sleep_get_wakeup_cause();

switch(wakeup_reason) {
switch (wakeup_reason) {
case ESP_SLEEP_WAKEUP_EXT0:
return "Wakeup caused by external signal using RTC_IO";
case ESP_SLEEP_WAKEUP_EXT1:
return "Wakeup caused by external signal using RTC_CNTL";
case ESP_SLEEP_WAKEUP_TIMER:
case ESP_SLEEP_WAKEUP_TIMER:
return "Wakeup caused by timer";
case ESP_SLEEP_WAKEUP_TOUCHPAD:
return "Wakeup caused by touchpad";
Expand All @@ -125,7 +128,7 @@ const char* EFBoardClass::getWakeupReason() {
return "Wakeup caused by coprocessor CRASH";
case ESP_SLEEP_WAKEUP_BT:
return "Wakeup caused by Bluetooth";
default:
default:
return "Wakeup was not caused by deep sleep (regular boot)";
}
}
Expand Down Expand Up @@ -170,7 +173,6 @@ const EFBoardPowerState EFBoardClass::updatePowerState() {
} else {
this->power_state = EFBoardPowerState::BAT_NORMAL;
}

}

return this->power_state;
Expand All @@ -185,7 +187,7 @@ const EFBoardPowerState EFBoardClass::resetPowerState() {
return this->updatePowerState();
}

bool EFBoardClass::connectToWifi(const char* ssid, const char* password) {
bool EFBoardClass::connectToWifi(const char *ssid, const char *password) {
LOGF_INFO("(EFBoard) Connecting to WiFi network: %s ", ssid);

// Try to connect to wifi
Expand All @@ -194,7 +196,7 @@ bool EFBoardClass::connectToWifi(const char* ssid, const char* password) {
for (int32_t timeout_ms = 10000; timeout_ms >= 0; timeout_ms -= 200) {
LOGF(".", 0);
delay(200);

// Check if connection failed
if (WiFi.status() == WL_CONNECT_FAILED) {
LOG(" FAILED!");
Expand Down Expand Up @@ -231,7 +233,7 @@ bool EFBoardClass::disableWifi() {
return true;
}

void EFBoardClass::enableOTA(const char* password) {
void EFBoardClass::enableOTA(const char *password) {
LOG_INFO("(EFBoard) Initializing OTA ... ");

if (password) {
Expand All @@ -242,59 +244,59 @@ void EFBoardClass::enableOTA(const char* password) {
}

ArduinoOTA
.onStart([]() {
if (ArduinoOTA.getCommand() == U_FLASH) {
LOG_INFO("(OTA) Start OTA update of U_FLASH ...");
} else {
LOG_INFO("(OTA) Starting OTA update of U_SPIFFS ...");
}

// Reset progress
ota_last_progress = -1;

// Setup LEDs
EFLed.clear();
EFLed.setBrightness(50);
EFLed.setDragonEye(CRGB::Blue);
})
.onEnd([]() {
LOG_INFO("(OTA) Finished! Rebooting ...");
for (uint8_t i = 0; i < 3; i++) {
EFLed.setDragonEye(CRGB::Green);
delay(500);
EFLed.setDragonEye(CRGB::Black);
delay(500);
}
EFLed.clear();
})
.onProgress([](unsigned int progress, unsigned int total) {
uint8_t progresspercent = (progress / (total / 100));
if (ota_last_progress < progresspercent) {
ota_last_progress = progresspercent;
EFLed.fillEFBarProportionally(progresspercent, CRGB::Red, CRGB::Black);
LOGF_INFO("(OTA) Progress: %u%%\r\n", progresspercent);
}
})
.onError([](ota_error_t error) {
LOGF_ERROR("(OTA) Error[%u]: ", error);
EFLed.setDragonNose(CRGB::Red);
if (error == OTA_AUTH_ERROR) {
LOG_WARNING("(OTA) Auth Failed");
EFLed.setDragonNose(CRGB::Purple);
} else if (error == OTA_BEGIN_ERROR) {
EFLed.setDragonNose(CRGB::Green);
LOG_ERROR("(OTA) Begin Failed");
} else if (error == OTA_CONNECT_ERROR) {
EFLed.setDragonNose(CRGB::Purple);
LOG_ERROR("(OTA) Connect Failed");
} else if (error == OTA_RECEIVE_ERROR) {
EFLed.setDragonNose(CRGB::Blue);
LOG_ERROR("(OTA) Receive Failed");
} else if (error == OTA_END_ERROR) {
EFLed.setDragonNose(CRGB::Yellow);
LOG_ERROR("(OTA) End Failed");
}
});
.onStart([]() {
if (ArduinoOTA.getCommand() == U_FLASH) {
LOG_INFO("(OTA) Start OTA update of U_FLASH ...");
} else {
LOG_INFO("(OTA) Starting OTA update of U_SPIFFS ...");
}

// Reset progress
ota_last_progress = -1;

// Setup LEDs
EFLed.clear();
EFLed.setBrightness(50);
EFLed.setDragonEye(CRGB::Blue);
})
.onEnd([]() {
LOG_INFO("(OTA) Finished! Rebooting ...");
for (uint8_t i = 0; i < 3; i++) {
EFLed.setDragonEye(CRGB::Green);
delay(500);
EFLed.setDragonEye(CRGB::Black);
delay(500);
}
EFLed.clear();
})
.onProgress([](unsigned int progress, unsigned int total) {
uint8_t progresspercent = (progress / (total / 100));
if (ota_last_progress < progresspercent) {
ota_last_progress = progresspercent;
EFLed.fillEFBarProportionally(progresspercent, CRGB::Red, CRGB::Black);
LOGF_INFO("(OTA) Progress: %u%%\r\n", progresspercent);
}
})
.onError([](ota_error_t error) {
LOGF_ERROR("(OTA) Error[%u]: ", error);
EFLed.setDragonNose(CRGB::Red);
if (error == OTA_AUTH_ERROR) {
LOG_WARNING("(OTA) Auth Failed");
EFLed.setDragonNose(CRGB::Purple);
} else if (error == OTA_BEGIN_ERROR) {
EFLed.setDragonNose(CRGB::Green);
LOG_ERROR("(OTA) Begin Failed");
} else if (error == OTA_CONNECT_ERROR) {
EFLed.setDragonNose(CRGB::Purple);
LOG_ERROR("(OTA) Connect Failed");
} else if (error == OTA_RECEIVE_ERROR) {
EFLed.setDragonNose(CRGB::Blue);
LOG_ERROR("(OTA) Receive Failed");
} else if (error == OTA_END_ERROR) {
EFLed.setDragonNose(CRGB::Yellow);
LOG_ERROR("(OTA) End Failed");
}
});

ArduinoOTA.begin();

Expand Down Expand Up @@ -364,5 +366,5 @@ void EFBoardClass::printCredits() {
}

#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_EFBOARD)
EFBoardClass EFBoard;
EFBoardClass EFBoard;
#endif
15 changes: 8 additions & 7 deletions lib/EFBoard/EFBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@
#define EFBOARD_SERIAL_DEVICE USBSerial //!< Serial device to use for logging
#define EFBOARD_SERIAL_BAUD 115200 //!< Baudrate for the serial device

// The Step-Down converter still manages to hold 3.00V with 3,32V input. The ESP needs 3.0V at least
#define EFBOARD_PIN_VBAT 10 //!< Pin the analog voltage divider for V_BAT is connected to
#define EFBOARD_NUM_BATTERIES 3 //!< Number of battery cells used for V_BAT
#define EFBOARD_VBAT_MAX (1.60 * EFBOARD_NUM_BATTERIES) //!< Voltage at which battery cells are considered full
#define EFBOARD_VBAT_MIN (1.16 * EFBOARD_NUM_BATTERIES) //!< Voltage at which battery cells are considered empty
#define EFBOARD_VBAT_MIN (1.12 * EFBOARD_NUM_BATTERIES) //!< Voltage at which battery cells are considered empty

#define EFBOARD_BROWN_OUT_SOFT EFBOARD_VBAT_MIN //!< V_BAT threshold after which a soft brown out is triggered
#define EFBOARD_BROWN_OUT_HARD 3.35 //!< V_BAT threshold after which a hard brown out is triggered
#define EFBOARD_BROWN_OUT_HARD 3.30 //!< V_BAT threshold after which a hard brown out is triggered


/**
Expand Down Expand Up @@ -72,7 +73,7 @@ class EFBoardClass {
unsigned int getWakeupCount();

/**
* @brief Retrieves the cause for the last wakeup in a human readable form.
* @brief Retrieves the cause for the last wakeup in a human-readable form.
*
* @return Wakeup reason as string
*/
Expand Down Expand Up @@ -126,16 +127,16 @@ class EFBoardClass {
const EFBoardPowerState resetPowerState();

/**
* @brief Tries to connect to the given Wifi access point
* @brief Tries to connect to the given WiFi access point
*
* @param ssid SSID of the Wifi network to connect to
* @param password WPA2 password for the Wifi network
* @param ssid SSID of the WiFi network to connect to
* @param password WPA2 password for the WiFi network
* @return True, if the connection was successful
*/
bool connectToWifi(const char* ssid, const char* password);

/**
* @brief Disconnects from any wifi network and disables the radio modem
* @brief Disconnects from any WiFi network and disables the radio modem
*
* @return True if the radio modem was sucessfully disabled
*/
Expand Down
5 changes: 3 additions & 2 deletions lib/EFLed/EFLed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ void EFLedClass::init(const uint8_t max_brightness) {
FastLED.setBrightness(this->max_brightness);
LOGF_DEBUG("(EFLed) Set max_brightness=%d\r\n", this->max_brightness)

this->enablePower();
enablePower();

}

void EFLedClass::enablePower() {
Expand Down Expand Up @@ -83,7 +84,7 @@ void EFLedClass::setBrightness(uint8_t brightness) {
FastLED.show();
}

uint8_t EFLedClass::getBrightness() {
uint8_t EFLedClass::getBrightness() const {
return (uint8_t) round(FastLED.getBrightness() / (float) this->max_brightness * 100);
}

Expand Down
22 changes: 15 additions & 7 deletions lib/EFLed/EFLed.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@
#define EFLED_PIN_LED_DATA 21
#define EFLED_PIN_5VBOOST_ENABLE 9

/**
* @brief Initial value for global maximum for the LED brightness, 0–255
* Has a huge impact on battery life.
*
* WARNING: The 5V boost converter is unable to power all LEDs on a high brightness level! Max brightness of 255 works
* only, if only a few LEDs are used at the same time. When using all LEDs even in a single color, values over 60 can
* overwhelm it and cause the colors to glitch. To be safe, choose a value below 50!
*/
#define EFLED_MAX_BRIGHTNESS_DEFAULT 50

#define EFLED_TOTAL_NUM 17
Expand Down Expand Up @@ -89,20 +97,20 @@ class EFLedClass {
/**
* @brief Enables the +5V power domain
*/
void enablePower();
static void enablePower();

/**
* @brief Disabled the +5V power domain
*/
void disablePower();
static void disablePower();

/**
* @brief Disables all LEDs
*/
void clear();

/**
* @brief Sets the global brightness for all LEDs
* @brief Sets the global brightness for all LEDs within range of the defined max brightness
*
* @param brightness Value between 0 (off) and 100 (high)
*/
Expand All @@ -113,7 +121,7 @@ class EFLedClass {
*
* @return Value between 0 (off) and 100 (high)
*/
uint8_t getBrightness();
uint8_t getBrightness() const;

/**
* @brief Sets all LEDs according to the given color array
Expand Down Expand Up @@ -172,14 +180,14 @@ class EFLedClass {
void setDragonEarTop(const CRGB color);

/**
* @brief Sets all of the dragon LEDs to the given colors
* @brief Sets all the dragon LEDs to the given colors
*
* @param color Array of colors to set
*/
void setDragon(const CRGB color[EFLED_DRAGON_NUM]);

/**
* @brief Sets all of the EF bar LEDs to the given colors
* @brief Sets all the EF bar LEDs to the given colors
*
* @param color Array of colors to set
*/
Expand All @@ -197,7 +205,7 @@ class EFLedClass {
* @brief Sets a single LED of the EFBar to one color and the remaining LEDs
* to another color
*
* @param idx Number of the led to set active (from top to bottom)
* @param idx Number of the LED to set active (from top to bottom)
* @param color_on Color to use for active LEDs
* @param color_off Color to use for inactive LEDs
*/
Expand Down
9 changes: 7 additions & 2 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ board_build.f_cpu = 80000000L
board_build.f_flash = 80000000L
framework = arduino
lib_deps =
fastled/FastLED@^3.7.3
build_unflags = -std=gnu++11
fastled/FastLED@^3.7.4
build_unflags =
-std=gnu++11
-std=gnu++14
-std=gnu++17
; Current compiler supports up to 2a (alias for 20)
build_flags = -std=gnu++2a

; upload_protocol = espota
; upload_port = 192.168.1.42
; upload_flags =
Expand Down
Loading

0 comments on commit 64608d3

Please sign in to comment.