Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support static bitmasks as LED patterns #23

Merged
merged 1 commit into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions firmware/src/boards/cynthion_d11/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@
static blink_pattern_t blink_pattern = BLINK_IDLE;


/**
* Sets the active LED blink pattern.
*/
void led_set_blink_pattern(blink_pattern_t pattern)
{
blink_pattern = pattern;
leds_off();
}


/**
* Sets up each of the LEDs for use.
*/
Expand Down Expand Up @@ -125,6 +115,24 @@ static void display_led_number(uint8_t number)
}


/**
* Sets the active LED blink pattern.
*/
void led_set_blink_pattern(blink_pattern_t pattern)
{
blink_pattern = pattern;
leds_off();
// Values of 0 to 31 should be set immediately as static patterns.
if (blink_pattern < 32) {
for (int i = 0; i < 5; i++) {
if (blink_pattern & (1 << i)) {
display_led_number(i);
}
}
}
}


/**
* Task that handles blinking the heartbeat LED.
*/
Expand All @@ -134,6 +142,11 @@ void heartbeat_task(void)
static uint8_t active_led = 0;
static bool count_up = true;

// Values of 0 to 31 define static patterns only.
if (blink_pattern < 32) {
return;
}

// Blink every interval ms
if ( board_millis() - start_ms < blink_pattern) return; // not enough time
start_ms += blink_pattern;
Expand Down
33 changes: 23 additions & 10 deletions firmware/src/boards/cynthion_d21/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,6 @@
static blink_pattern_t blink_pattern = BLINK_IDLE;


/**
* Sets the active LED blink pattern.
*/
void led_set_blink_pattern(blink_pattern_t pattern)
{
blink_pattern = pattern;
leds_off();
}


/**
* Sets up each of the LEDs for use.
*/
Expand Down Expand Up @@ -112,6 +102,24 @@ static void display_led_number(uint8_t number)
}


/**
* Sets the active LED blink pattern.
*/
void led_set_blink_pattern(blink_pattern_t pattern)
{
blink_pattern = pattern;
leds_off();
// Values of 0 to 31 should be set immediately as static patterns.
if (blink_pattern < 32) {
for (int i = 0; i < 5; i++) {
if (blink_pattern & (1 << i)) {
display_led_number(i);
}
}
}
}


/**
* Task that handles blinking the heartbeat LED.
*/
Expand All @@ -121,6 +129,11 @@ void heartbeat_task(void)
static uint8_t active_led = 0;
static bool count_up = true;

// Values of 0 to 31 define static patterns only.
if (blink_pattern < 32) {
return;
}

// Blink every interval ms
if ( board_millis() - start_ms < blink_pattern) return; // not enough time
start_ms += blink_pattern;
Expand Down
10 changes: 9 additions & 1 deletion firmware/src/led.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@
#include <apollo_board.h>

/**
* Different blink patterns with different semantic meanings.
* LED patterns.
*
* Values 0 to 31 will be interpreted as static bitmasks, and can be used
* to turn on specific combinations of LEDs in a fixed pattern.
*
* Other values as defined in this enum will produce dynamic blink patterns,
* with different semantic meanings.
*/
typedef enum {
BLINK_IDLE = 500,
Expand All @@ -27,6 +33,8 @@ typedef enum {

/**
* Sets the active LED blink pattern.
*
* See @ref blink_pattern_t for the meaning of the pattern argument.
*/
void led_set_blink_pattern(blink_pattern_t pattern);

Expand Down
Loading