Skip to content

Commit

Permalink
app: led: Add LED pattern for FOTA
Browse files Browse the repository at this point in the history
Add pattern (purple blinking) when FOTA image is downloading.

Signed-off-by: Jan Tore Guggedal <[email protected]>
  • Loading branch information
jtguggedal committed Dec 11, 2024
1 parent b1e3958 commit f4370f1
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
48 changes: 48 additions & 0 deletions app/src/modules/led/led.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ enum state {
STATE_POLL,
/* Sub-state to STATE_LED_NOT_SET */
STATE_NORMAL,
/* Sub-state to STATE_LED_NOT_SET */
STATE_FOTA,
STATE_ERROR,
};

Expand Down Expand Up @@ -331,6 +333,15 @@ static void led_not_set_running(void *o)
smf_set_state(SMF_CTX(user_object), &states[STATE_LED_SET]);
return;
}

if (&FOTA_STATUS_CHAN == user_object->chan) {
const enum fota_status *status = zbus_chan_const_msg(user_object->chan);

if (*status == FOTA_STATUS_START) {
smf_set_state(SMF_CTX(user_object), &states[STATE_FOTA]);
return;
}
}
}

/* STATE_POLL */
Expand Down Expand Up @@ -415,6 +426,36 @@ static void normal_running(void *o)
}
}

/* STATE_FOTA */

static void fota_entry(void *o)
{
ARG_UNUSED(o);

LOG_DBG("fota_entry");

transition_list_clear();
transition_list_append(LED_FOTA, HOLD_FOREVER, 0, 0, 0);

k_work_reschedule(&led_pattern_update_work, K_NO_WAIT);
}

static void fota_running(void *o)
{
struct s_object *user_object = o;

LOG_DBG("fota_running");

if (&FOTA_STATUS_CHAN == user_object->chan) {
const enum fota_status *status = zbus_chan_const_msg(user_object->chan);

if (*status == FOTA_STATUS_STOP) {
smf_set_state(SMF_CTX(user_object), &states[STATE_LED_NOT_SET]);
return;
}
}
}

/* STATE_ERROR */

static void error_entry(void *o)
Expand Down Expand Up @@ -469,6 +510,13 @@ static const struct smf_state states[] = {
&states[STATE_LED_NOT_SET],
NULL
),
[STATE_FOTA] = SMF_CREATE_STATE(
fota_entry,
fota_running,
NULL,
&states[STATE_LED_NOT_SET],
NULL
),
[STATE_ERROR] = SMF_CREATE_STATE(
error_entry,
NULL,
Expand Down
2 changes: 2 additions & 0 deletions app/src/modules/led/led.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ extern "C" {
#define LED_LTE_CONNECTING_COLOR LED_COLOR_YELLOW
#define LED_LOCATION_SEARCHING_COLOR LED_COLOR_GREEN
#define LED_POLL_MODE_COLOR LED_COLOR_BLUE
#define LED_FOTA_COLOR LED_COLOR_PURPLE
#define LED_ERROR_SYSTEM_FAULT_COLOR LED_COLOR_RED
#define LED_OFF_COLOR LED_COLOR_OFF

Expand All @@ -66,6 +67,7 @@ enum led_state {
LED_LOCATION_SEARCHING,
LED_ERROR_SYSTEM_FAULT,
LED_ERROR_IRRECOVERABLE,
LED_FOTA,
LED_CONFIGURED,
LED_OFF,
LED_PATTERN_COUNT,
Expand Down
5 changes: 5 additions & 0 deletions app/src/modules/led/led_pwm.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ static const struct led_effect effect[] = {
LED_OFF_PERIOD_NORMAL,
LED_LOCATION_SEARCHING_COLOR
),
[LED_FOTA] = LED_EFFECT_LED_BREATHE(
LED_ON_PERIOD_NORMAL,
LED_OFF_PERIOD_NORMAL,
LED_FOTA_COLOR
),
[LED_ERROR_SYSTEM_FAULT] = LED_EFFECT_LED_BREATHE(
LED_ON_PERIOD_ERROR,
LED_OFF_PERIOD_ERROR,
Expand Down
2 changes: 2 additions & 0 deletions docs/about.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ The following table describes the supported LED states:
+----------------+------------+----------------------------------------------+-----------------------------------------------------+
| Blinking slow | Blue | Device is actively polling cloud | 10 minutes after last config update or button press |
+----------------+------------+----------------------------------------------+-----------------------------------------------------+
| Blinking | Purple | Device is downloading FOTA image | Until the download has completed or failed |
+----------------+------------+----------------------------------------------+-----------------------------------------------------+
| Solid | Configured | Device has received an LED configuration | NA |
+----------------+------------+----------------------------------------------+-----------------------------------------------------+
| Blinking rapid | Red | Fatal error, the device will reboot | NA |
Expand Down

0 comments on commit f4370f1

Please sign in to comment.