Skip to content

Commit

Permalink
Tides2: colorblind mode
Browse files Browse the repository at this point in the history
  • Loading branch information
Emilie Gillet committed Jun 14, 2019
1 parent 75d3b2c commit 31481e7
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 6 deletions.
2 changes: 1 addition & 1 deletion tides2/bootloader/bootloader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ int main(void) {
Init();
InitializeReception();

bool exit_updater = !switches.pressed_immediate(SWITCH_MODE);
bool exit_updater = !switches.pressed_immediate(SWITCH_RANGE);
while (!exit_updater) {
bool error = false;

Expand Down
4 changes: 3 additions & 1 deletion tides2/drivers/switches.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,10 @@ class Switches {
}

inline bool pressed_immediate(Switch s) const {
if (s == SWITCH_MODE) {
if (s == SWITCH_RANGE) {
return !GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_2);
} else if (s == SWITCH_SHIFT) {
return !GPIO_ReadInputDataBit(GPIOC, GPIO_Pin_13);
} else {
return false;
}
Expand Down
3 changes: 2 additions & 1 deletion tides2/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ struct State {
uint8_t mode;
uint8_t range;
uint8_t output_mode;
uint8_t padding[5];
uint8_t color_blind;
uint8_t padding[4];

enum { tag = 0x54415453 }; // STAT
};
Expand Down
38 changes: 35 additions & 3 deletions tides2/ui.cc
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ void Ui::Init(Settings* settings, FactoryTest* factory_test) {
factory_test_ = factory_test;
mode_ = UI_MODE_NORMAL;

if (switches_.pressed_immediate(SWITCH_SHIFT)) {
State* state = settings_->mutable_state();
if (state->color_blind == 1) {
state->color_blind = 0;
} else {
state->color_blind = 1;
}
settings_->SaveState();
}

queue_.Init();

fill(&press_time_[0], &press_time_[SWITCH_LAST], 0);
Expand Down Expand Up @@ -95,6 +105,26 @@ void Ui::Poll() {
}
}

LedColor Ui::MakeColor(uint8_t value, bool color_blind) {
LedColor color = palette_[value];
if (color_blind) {
uint8_t pwm_counter = system_clock.milliseconds() & 15;
uint8_t triangle = (system_clock.milliseconds() >> 5) & 31;
triangle = triangle < 16 ? triangle : 31 - triangle;

if (value == 0) {
color = pwm_counter < (4 + (triangle >> 2))
? LED_COLOR_GREEN
: LED_COLOR_OFF;
} else if (value == 1) {
color = LED_COLOR_YELLOW;
} else if (value == 2) {
color = pwm_counter == 0 ? LED_COLOR_RED : LED_COLOR_OFF;
}
}
return color;
}

void Ui::UpdateLEDs() {
leds_.Clear();

Expand All @@ -104,9 +134,11 @@ void Ui::UpdateLEDs() {
case UI_MODE_NORMAL:
{
const State& s = settings_->state();
leds_.set(LED_MODE, palette_[s.mode]);
leds_.set(LED_RANGE, palette_[s.range]);
leds_.set(LED_SHIFT, palette_[(s.output_mode + 3) % 4]);
bool color_blind = s.color_blind == 1;

leds_.set(LED_MODE, MakeColor(s.mode, color_blind));
leds_.set(LED_RANGE, MakeColor(s.range, color_blind));
leds_.set(LED_SHIFT, MakeColor((s.output_mode + 3) % 4, color_blind));
}
break;

Expand Down
1 change: 1 addition & 0 deletions tides2/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class Ui {
void OnSwitchPressed(const stmlib::Event& e);
void OnSwitchReleased(const stmlib::Event& e);

LedColor MakeColor(uint8_t value, bool color_blind);
void UpdateLEDs();

stmlib::EventQueue<16> queue_;
Expand Down

0 comments on commit 31481e7

Please sign in to comment.