diff --git a/tides2/bootloader/bootloader.cc b/tides2/bootloader/bootloader.cc index 94df7eae2..b3bd24483 100755 --- a/tides2/bootloader/bootloader.cc +++ b/tides2/bootloader/bootloader.cc @@ -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; diff --git a/tides2/drivers/switches.h b/tides2/drivers/switches.h index 97ab9fc0e..60bf484da 100755 --- a/tides2/drivers/switches.h +++ b/tides2/drivers/switches.h @@ -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; } diff --git a/tides2/settings.h b/tides2/settings.h index 78ed7b051..01ec82466 100644 --- a/tides2/settings.h +++ b/tides2/settings.h @@ -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 }; diff --git a/tides2/ui.cc b/tides2/ui.cc index 51aecd43c..b00054813 100755 --- a/tides2/ui.cc +++ b/tides2/ui.cc @@ -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); @@ -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(); @@ -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; diff --git a/tides2/ui.h b/tides2/ui.h index 899820537..aed374ce9 100755 --- a/tides2/ui.h +++ b/tides2/ui.h @@ -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_;