Hardware LED blinking (#1303)

* Hardware LED blinking notification messages
* Blink: fix crash on exit, reset blinking on exit
* Lib: remove unused UNUSED

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
Nikolay Minaylov
2022-06-09 10:33:46 +03:00
committed by GitHub
parent 41cf421234
commit cfb1a0d01c
10 changed files with 322 additions and 52 deletions

View File

@@ -1,6 +1,7 @@
#pragma once
#include "stdint.h"
#include "stdbool.h"
#include <furi_hal_resources.h>
#ifdef __cplusplus
extern "C" {
@@ -30,9 +31,16 @@ typedef struct {
float display_brightness;
} NotificationMessageDataForcedSettings;
typedef struct {
uint16_t on_time;
uint16_t period;
Light color;
} NotificationMessageDataLedBlink;
typedef union {
NotificationMessageDataSound sound;
NotificationMessageDataLed led;
NotificationMessageDataLedBlink led_blink;
NotificationMessageDataVibro vibro;
NotificationMessageDataDelay delay;
NotificationMessageDataForcedSettings forced_settings;
@@ -48,6 +56,10 @@ typedef enum {
NotificationMessageTypeLedGreen,
NotificationMessageTypeLedBlue,
NotificationMessageTypeLedBlinkStart,
NotificationMessageTypeLedBlinkStop,
NotificationMessageTypeLedBlinkColor,
NotificationMessageTypeDelay,
NotificationMessageTypeLedDisplayBacklight,

View File

@@ -1,3 +1,4 @@
#include "furi_hal_light.h"
#include <furi.h>
#include <furi_hal.h>
#include <storage/storage.h>
@@ -17,6 +18,7 @@ static const uint8_t reset_blue_mask = 1 << 2;
static const uint8_t reset_vibro_mask = 1 << 3;
static const uint8_t reset_sound_mask = 1 << 4;
static const uint8_t reset_display_mask = 1 << 5;
static const uint8_t reset_blink_mask = 1 << 6;
void notification_vibro_on();
void notification_vibro_off();
@@ -100,6 +102,9 @@ void notification_reset_notification_layer(NotificationApp* app, uint8_t reset_m
if(reset_mask & reset_blue_mask) {
notification_reset_notification_led_layer(&app->led[2]);
}
if(reset_mask & reset_blink_mask) {
furi_hal_light_blink_stop();
}
if(reset_mask & reset_vibro_mask) {
notification_vibro_off();
}
@@ -229,6 +234,24 @@ void notification_process_notification_message(
app->led[2].value_last[LayerNotification] = led_values[2];
reset_mask |= reset_blue_mask;
break;
case NotificationMessageTypeLedBlinkStart:
// store and send on delay or after seq
led_active = true;
furi_hal_light_blink_start(
notification_message->data.led_blink.color,
app->settings.led_brightness * 255,
notification_message->data.led_blink.on_time,
notification_message->data.led_blink.period);
reset_mask |= reset_blink_mask;
break;
case NotificationMessageTypeLedBlinkColor:
led_active = true;
furi_hal_light_blink_set_color(notification_message->data.led_blink.color);
break;
case NotificationMessageTypeLedBlinkStop:
furi_hal_light_blink_stop();
reset_mask &= ~reset_blink_mask;
break;
case NotificationMessageTypeVibro:
if(notification_message->data.vibro.on) {
if(vibro_setting) notification_vibro_on();

View File

@@ -1,3 +1,4 @@
#include "furi_hal_resources.h"
#include "notification.h"
#include "notification_messages_notes.h"
#include <stddef.h>
@@ -60,6 +61,59 @@ const NotificationMessage message_blue_0 = {
.data.led.value = 0x00,
};
const NotificationMessage message_blink_start_10 = {
.type = NotificationMessageTypeLedBlinkStart,
.data.led_blink.color = 0,
.data.led_blink.on_time = 10,
.data.led_blink.period = 100,
};
const NotificationMessage message_blink_start_100 = {
.type = NotificationMessageTypeLedBlinkStart,
.data.led_blink.color = 0,
.data.led_blink.on_time = 100,
.data.led_blink.period = 1000,
};
const NotificationMessage message_blink_stop = {
.type = NotificationMessageTypeLedBlinkStop,
};
const NotificationMessage message_blink_set_color_red = {
.type = NotificationMessageTypeLedBlinkColor,
.data.led_blink.color = LightRed,
};
const NotificationMessage message_blink_set_color_green = {
.type = NotificationMessageTypeLedBlinkColor,
.data.led_blink.color = LightGreen,
};
const NotificationMessage message_blink_set_color_blue = {
.type = NotificationMessageTypeLedBlinkColor,
.data.led_blink.color = LightBlue,
};
const NotificationMessage message_blink_set_color_cyan = {
.type = NotificationMessageTypeLedBlinkColor,
.data.led_blink.color = LightBlue | LightGreen,
};
const NotificationMessage message_blink_set_color_magenta = {
.type = NotificationMessageTypeLedBlinkColor,
.data.led_blink.color = LightBlue | LightRed,
};
const NotificationMessage message_blink_set_color_yellow = {
.type = NotificationMessageTypeLedBlinkColor,
.data.led_blink.color = LightGreen | LightRed,
};
const NotificationMessage message_blink_set_color_white = {
.type = NotificationMessageTypeLedBlinkColor,
.data.led_blink.color = LightRed | LightGreen | LightBlue,
};
// Delay
const NotificationMessage message_delay_1 = {
.type = NotificationMessageTypeDelay,

View File

@@ -24,6 +24,19 @@ extern const NotificationMessage message_red_0;
extern const NotificationMessage message_green_0;
extern const NotificationMessage message_blue_0;
// Led hardware blink control
extern const NotificationMessage message_blink_start_10;
extern const NotificationMessage message_blink_start_100;
extern const NotificationMessage message_blink_stop;
extern const NotificationMessage message_blink_set_color_red;
extern const NotificationMessage message_blink_set_color_green;
extern const NotificationMessage message_blink_set_color_blue;
extern const NotificationMessage message_blink_set_color_cyan;
extern const NotificationMessage message_blink_set_color_magenta;
extern const NotificationMessage message_blink_set_color_yellow;
extern const NotificationMessage message_blink_set_color_white;
// Delay
extern const NotificationMessage message_delay_1;
extern const NotificationMessage message_delay_10;