Skip to content

Commit

Permalink
Merge pull request #23 from greatscottgadgets/led-control
Browse files Browse the repository at this point in the history
Support static bitmasks as LED patterns
  • Loading branch information
mossmann committed Mar 7, 2024
2 parents b994838 + 5f68e61 commit 12e6b47
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 21 deletions.
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

0 comments on commit 12e6b47

Please sign in to comment.