Skip to content

Commit

Permalink
leds: implement static control mode
Browse files Browse the repository at this point in the history
In this mode LED is on from the moment the board is powered on or
since this mode is enabled
  • Loading branch information
paradajz committed Apr 8, 2024
1 parent 3b7591e commit 6bd65b0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/firmware/application/io/leds/LEDs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ bool LEDs::init()
}

setBlinkType(static_cast<blinkType_t>(_database.read(database::Config::Section::leds_t::GLOBAL, setting_t::BLINK_WITH_MIDI_CLOCK)));
setAllStaticOn();

return true;
}
Expand Down Expand Up @@ -608,6 +609,18 @@ void LEDs::setAllOn()
}
}

void LEDs::setAllStaticOn()
{
// turn on all static LEDs
for (size_t i = 0; i < Collection::SIZE(); i++)
{
if (_database.read(database::Config::Section::leds_t::CONTROL_TYPE, i) == static_cast<uint8_t>(controlType_t::STATIC))
{
setColor(i, color_t::RED, brightness_t::B100);
}
}
}

void LEDs::setAllOff()
{
// turn off all LEDs
Expand Down Expand Up @@ -979,8 +992,8 @@ std::optional<uint8_t> LEDs::sysConfigSet(sys::Config::Section::leds_t section,
if (section == sys::Config::Section::leds_t::CONTROL_TYPE)
{
setColor(index,
color_t::OFF,
brightness_t::OFF);
value == static_cast<uint8_t>(controlType_t::STATIC) ? color_t::RED : color_t::OFF,
value == static_cast<uint8_t>(controlType_t::STATIC) ? brightness_t::B100 : brightness_t::OFF);
}

// find out if RGB led is enabled for this led index
Expand Down
3 changes: 3 additions & 0 deletions src/firmware/application/io/leds/LEDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ namespace io
LOCAL_NOTE_MULTI_VAL,
MIDI_IN_CC_MULTI_VAL,
LOCAL_CC_MULTI_VAL,
STATIC,
AMOUNT
};

Expand Down Expand Up @@ -152,6 +153,7 @@ namespace io
};

void setAllOn();
void setAllStaticOn();
void refresh();
void setBlinkSpeed(uint8_t ledID, blinkSpeed_t state, bool updateState = true);
void setBlinkType(blinkType_t blinkType);
Expand Down Expand Up @@ -227,6 +229,7 @@ namespace io
MIDI::messageType_t::NOTE_ON, // LOCAL_NOTE_MULTI_VAL,
MIDI::messageType_t::CONTROL_CHANGE, // MIDI_IN_CC_MULTI_VAL,
MIDI::messageType_t::CONTROL_CHANGE, // LOCAL_CC_MULTI_VAL,
MIDI::messageType_t::INVALID, // STATIC
};
};
} // namespace io
Expand Down
1 change: 1 addition & 0 deletions src/firmware/application/io/leds/stub/LEDs.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ namespace io
LOCAL_NOTE_MULTI_VAL,
MIDI_IN_CC_MULTI_VAL,
LOCAL_CC_MULTI_VAL,
STATIC,
AMOUNT
};

Expand Down
16 changes: 16 additions & 0 deletions tests/src/io/leds/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -834,4 +834,20 @@ TEST_F(LEDsTest, ProgramChangeWithOffset)
});
}

TEST_F(LEDsTest, StaticLEDsOnInitially)
{
constexpr size_t LED_INDEX = 0;
ASSERT_TRUE(_leds._database.update(database::Config::Section::leds_t::CONTROL_TYPE, LED_INDEX, LEDs::controlType_t::STATIC));

// Once init() is called, all LEDs should be turned off
EXPECT_CALL(_leds._hwa, setState(_, expectedBrightnessValue.at(0)))
.Times(LEDs::Collection::SIZE(LEDs::GROUP_DIGITAL_OUTPUTS));

// LED_INDEX should be turned on
EXPECT_CALL(_leds._hwa, setState(LED_INDEX, LEDs::brightness_t::B100))
.Times(1);

_leds._instance.init();
}

#endif

0 comments on commit 6bd65b0

Please sign in to comment.