Skip to content

Commit

Permalink
Minor bugs with the flashlight application 🔦 (#370)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmicro authored Sep 24, 2023
2 parents e1ed032 + 814d721 commit 2cddafd
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion emulator/include/RtcDS3231.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class RtcDateTime {
RtcDateTime() {};
virtual ~RtcDateTime() {};

void InitWithEpoch32Time(time_t time);
void InitWithUnix32Time(time_t time);

uint32_t Hour();
uint32_t Minute();
Expand Down
2 changes: 1 addition & 1 deletion emulator/src/RtcDS3231.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "../include/RtcDS3231.h"

void RtcDateTime::InitWithEpoch32Time(time_t time) {
void RtcDateTime::InitWithUnix32Time(time_t time) {
this->time = time;
}

Expand Down
1 change: 0 additions & 1 deletion include/apps/tools/OswAppFlashLight.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ class OswAppFlashLight : public OswAppV2 {
const OswIcon& getAppIcon() override;

void onStart() override;
void onLoop() override;
void onDraw() override;
void onStop() override;

Expand Down
33 changes: 17 additions & 16 deletions src/apps/tools/OswAppFlashLight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ void OswAppFlashLight::onStart() {
this->knownButtonStates[Button::BUTTON_DOWN] = ButtonStateNames::SHORT_PRESS;
}

void OswAppFlashLight::onLoop() {
OswAppV2::onLoop();

this->hal->setBrightness(flashlightBrightness, false); // sets the brighntess, but doesn't store it
}

void OswAppFlashLight::onDraw() {
OswAppV2::onDraw();

Expand All @@ -46,33 +40,40 @@ void OswAppFlashLight::onDraw() {
this->hal->gfx()->setTextColor(ui->getBackgroundColor());
this->hal->gfx()->print(int(hal->screenBrightness())); //displays the current brightness
} else {
this->hal->setBrightness(OswConfigAllKeys::settingDisplayBrightness.get()); //sets the brighntess to the initial value
this->hal->gfx()->fillCircle(120, 120, 115, ui->getBackgroundColor());
this->hal->gfx()->setTextSize(3.5);
this->hal->gfx()->setTextCenterAligned();
this->hal->gfx()->setTextCursor(120, 125);
this->hal->gfx()->setTextColor(ui->getForegroundColor());
this->hal->gfx()->print("Flashlight");
}

}

void OswAppFlashLight::onButton(Button id, bool up, OswAppV2::ButtonStateNames state) {
OswAppV2::onButton(id, up, state); // always make sure to call the base class method!
if(!up) return;
this->needsRedraw = true; // we need to redraw the screen, regardless of what happens next
if(id == Button::BUTTON_SELECT)
if(id == Button::BUTTON_SELECT) {
this->on = !this->on;
else if(id == Button::BUTTON_UP) {
this->flashlightBrightness = this->flashlightBrightness + 50;
this->hal->setBrightness(flashlightBrightness, false);
} else if(id == Button::BUTTON_DOWN) {
this->flashlightBrightness = this->flashlightBrightness - 50;
this->hal->setBrightness(flashlightBrightness, false);
// whenever the flashlight is active, we should not let the screen go to sleep
if(this->on)
this->viewFlags = (OswAppV2::ViewFlags) (this->viewFlags | OswAppV2::ViewFlags::KEEP_DISPLAY_ON); // on
else
this->viewFlags = (OswAppV2::ViewFlags) (this->viewFlags ^ OswAppV2::ViewFlags::KEEP_DISPLAY_ON); // toggle (on->off)
}
// if flashlight is active, allow brightness adjustment
if(this->on) {
if(id == Button::BUTTON_UP)
this->flashlightBrightness = this->flashlightBrightness + 50;
else if(id == Button::BUTTON_DOWN)
this->flashlightBrightness = this->flashlightBrightness - 50;
this->hal->setBrightness(flashlightBrightness, false); // sets the brightness to the current value
} else {
this->hal->setBrightness(OswConfigAllKeys::settingDisplayBrightness.get()); //sets the brightness to the initial value
}
}

void OswAppFlashLight::onStop() {
OswAppV2::onStop();
this->hal->setBrightness(OswConfigAllKeys::settingDisplayBrightness.get(), false); // sets the brighntess to the initial value
this->hal->setBrightness(OswConfigAllKeys::settingDisplayBrightness.get(), false); // reset the brightness to the initial value
}
8 changes: 4 additions & 4 deletions src/devices/ds3231mz.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void OswDevices::DS3231MZ::setup() {
}

void OswDevices::DS3231MZ::update() {
uint32_t temp = Rtc.GetDateTime().Epoch32Time();
uint32_t temp = Rtc.GetDateTime().Unix32Time();
if (!Rtc.LastError()) {
// success on first attempt
_utcTime = temp;
Expand All @@ -45,7 +45,7 @@ void OswDevices::DS3231MZ::update() {
// try harder
uint8_t tries = 10;
while (_utcTime == 0 && tries > 0) {
temp = Rtc.GetDateTime().Epoch32Time();
temp = Rtc.GetDateTime().Unix32Time();
if (!Rtc.LastError()) {
// success on n-th attempt
_utcTime = temp;
Expand All @@ -55,7 +55,7 @@ void OswDevices::DS3231MZ::update() {
}

// fail, assume compile time as closest time in the past
_utcTime = RtcDateTime(__DATE__, __TIME__).Epoch32Time();
_utcTime = RtcDateTime(__DATE__, __TIME__).Unix32Time();
}

time_t OswDevices::DS3231MZ::getUTCTime() {
Expand All @@ -65,7 +65,7 @@ time_t OswDevices::DS3231MZ::getUTCTime() {

void OswDevices::DS3231MZ::setUTCTime(const time_t& epoch) {
RtcDateTime t = RtcDateTime();
t.InitWithEpoch32Time(epoch);
t.InitWithUnix32Time(epoch);
Rtc.SetDateTime(t);
}

Expand Down

0 comments on commit 2cddafd

Please sign in to comment.