Skip to content

Commit

Permalink
Inverted operation
Browse files Browse the repository at this point in the history
  • Loading branch information
mrbig committed Jun 19, 2016
1 parent 53daa91 commit 77ba074
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 9 deletions.
4 changes: 2 additions & 2 deletions alertled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ void AlertLED::init(EventManager* eventManager) {
pinMode(CFG_LED_ALERT1, OUTPUT);
pinMode(CFG_LED_ALERT2, OUTPUT);
pinMode(CFG_BEEPER, OUTPUT);
digitalWrite(CFG_LED_ALERT1, 1);
digitalWrite(CFG_LED_ALERT2, 1);
digitalWrite(CFG_LED_ALERT1, 1 - INVERTED);
digitalWrite(CFG_LED_ALERT2, 1 - INVERTED);
digitalWrite(CFG_BEEPER, 1);

alertStatus = ALERT_NONE;
Expand Down
13 changes: 9 additions & 4 deletions alertled.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,22 @@ class AlertLED {
if (alertStatus == ALERT_NONE) {
if (!animPtr) return;
animPtr = 0;
analogWrite(CFG_LED_ALERT1, 1023);
analogWrite(CFG_LED_ALERT2, 1023);
analogWrite(CFG_LED_ALERT1, INVERTED ? 0 : 1023);
analogWrite(CFG_LED_ALERT2, INVERTED ? 0 : 1023);
analogWrite(CFG_BEEPER, 1023);
return;
}

if (animPtr >= sizeof(anim_warning[alertStatus])/sizeof(ALED_CFG)) animPtr = 0;

memcpy_P(&anim, &anim_warning[alertStatus][animPtr], sizeof(ALED_CFG));
analogWrite(CFG_LED_ALERT1, (anim.lft - 1023) * mult + 1023);
analogWrite(CFG_LED_ALERT2, (anim.rgt - 1023) * mult + 1023);
if (INVERTED) {
analogWrite(CFG_LED_ALERT1, (1024 -anim.lft) * mult);
analogWrite(CFG_LED_ALERT2, (1024 - anim.rgt) * mult);
} else {
analogWrite(CFG_LED_ALERT1, (anim.lft - 1023) * mult + 1023);
analogWrite(CFG_LED_ALERT2, (anim.rgt - 1023) * mult + 1023);
}
analogWrite(CFG_BEEPER, anim.beeper);

animPtr++;
Expand Down
2 changes: 2 additions & 0 deletions config.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
// Software version
#define FW_VERSION "1.4"

#define INVERTED 1

// Enable / disabled modules
#define ENABLE_STATUSLED 1
#define ENABLE_ALERTLED 1
Expand Down
12 changes: 9 additions & 3 deletions statusled.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,19 @@ void StatusLED::setStatus(byte state) {
void StatusLED::tick() {
if (!gpsStatus) {
// Display sweep animation whene there is no reception
analogWrite(CFG_LED_STATUS, animPulse[pos]);
analogWrite(CFG_LED_STATUS, INVERTED ? 1023 - animPulse[pos] : animPulse[pos]);
pos++;
if (pos >= sizeof(animPulse) / 2) pos = 0;
} else {
// Short pings when reception acquired
if (pos == 0) analogWrite(CFG_LED_STATUS, GPS::isNight() ? 900 : 1);
else analogWrite(CFG_LED_STATUS, 1023);
if (pos == 0) {
if (GPS::isNight()) {
analogWrite(CFG_LED_STATUS, INVERTED ? 123 : 900);
} else {
analogWrite(CFG_LED_STATUS, INVERTED ? 1023 : 1);
}
}
else analogWrite(CFG_LED_STATUS, INVERTED ? 0 : 1023);
if (++pos >= 150) pos = 0;
}
}
Expand Down

0 comments on commit 77ba074

Please sign in to comment.