Skip to content

Commit

Permalink
reset led driver at startup, clamp brightness down
Browse files Browse the repository at this point in the history
  • Loading branch information
BaptisteHudyma committed May 17, 2024
1 parent 58b61ea commit 0b90393
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
6 changes: 5 additions & 1 deletion LampColorControler.ino
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,14 @@
#include "src/system/physical/bluetooth.h"
#include "src/system/physical/button.h"
#include "src/system/physical/fileSystem.h"
#include "src/system/physical/led_power.h"
#include "src/system/utils/utils.h"
#include "src/user_functions.h"

void setup() {
// start by resetting the led driver
ledpower::write_current(0);

// necessary for all i2c communications
Wire.begin();

Expand All @@ -33,7 +37,7 @@ void setup() {
// set up button colors and callbacks
button::init();

if (!charger::is_powered_on()) {
if (!charger::is_usb_powered()) {
startup_sequence();
} else {
shutdown();
Expand Down
4 changes: 2 additions & 2 deletions src/system/behavior.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ void handle_alerts() {
// limit brightness to half the max value
constexpr uint8_t clampedBrightness = 0.5 * MAX_BRIGHTNESS;
MaxBrightnessLimit = clampedBrightness;
update_brightness(clampedBrightness);
update_brightness(min(clampedBrightness, BRIGHTNESS));
} else if ((current & Alerts::BATTERY_READINGS_INCOHERENT) != 0x00) {
// incohrent battery readings
button::blink(100, 100, utils::ColorSpace::GREEN);
Expand All @@ -272,7 +272,7 @@ void handle_alerts() {
// limit brightness to quarter of the max value
constexpr uint8_t clampedBrightness = 0.25 * MAX_BRIGHTNESS;
MaxBrightnessLimit = clampedBrightness;
update_brightness(clampedBrightness);
update_brightness(min(clampedBrightness, BRIGHTNESS));
} else if ((current & Alerts::LONG_LOOP_UPDATE) != 0x00) {
// fast blink red
button::blink(400, 400, utils::ColorSpace::FUSHIA);
Expand Down
3 changes: 3 additions & 0 deletions src/system/charger/charger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ bool check_vendor_device_values() {
return true;
}

bool is_usb_powered() {
return (NRF_POWER->USBREGSTATUS & POWER_USBREGSTATUS_VBUSDETECT_Msk) != 0x00;
}
bool is_powered_on() { return (digitalRead(CHARGE_OK) == HIGH); }

bool enable_charge() {
Expand Down
1 change: 1 addition & 0 deletions src/system/charger/charger.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace charger {

bool check_vendor_device_values();

bool is_usb_powered();
bool is_powered_on();

bool enable_charge();
Expand Down

0 comments on commit 0b90393

Please sign in to comment.