Просмотр исходного кода

Blink strobe (#213)

* blink all led and control freq by button
* rename to strobe
coreglitch 5 лет назад
Родитель
Сommit
1fbfc5a61a

+ 2 - 2
applications/applications.h

@@ -39,7 +39,7 @@ const FlipperStartupApp FLIPPER_STARTUP[] = {
 #endif
 
 #ifdef APP_EXAMPLE_BLINK
-    {.app = application_blink, .name = "blink", .libs = {0}},
+    {.app = application_blink, .name = "blink", .libs = {1, FURI_LIB{"input_task"}}},
 #endif
 
 #ifdef APP_INPUT
@@ -112,7 +112,7 @@ const FlipperStartupApp FLIPPER_STARTUP[] = {
 
 const FlipperStartupApp FLIPPER_APPS[] = {
 #ifdef BUILD_EXAMPLE_BLINK
-    {.app = application_blink, .name = "blink", .libs = {0}},
+    {.app = application_blink, .name = "blink", .libs = {1, FURI_LIB{"input_task"}}},
 #endif
 
 #ifdef BUILD_EXAMPLE_UART_WRITE

+ 1 - 0
applications/applications.mk

@@ -79,6 +79,7 @@ BUILD_EXAMPLE_BLINK ?= 0
 ifeq ($(BUILD_EXAMPLE_BLINK), 1)
 CFLAGS		+= -DBUILD_EXAMPLE_BLINK
 C_SOURCES	+= $(APP_DIR)/examples/blink.c
+APP_INPUT = 1
 endif
 
 APP_EXAMPLE_UART_WRITE ?= 0

+ 0 - 1
applications/examples/blink.c

@@ -1,4 +1,3 @@
-#include "flipper.h"
 #include "flipper_v2.h"
 
 void rgb_set(bool r, bool g, bool b, GpioPin* led_r, GpioPin* led_g, GpioPin* led_b) {

+ 58 - 0
applications/examples/strobe.c

@@ -0,0 +1,58 @@
+#include "flipper_v2.h"
+
+static void event_cb(const void* value, void* ctx) {
+    const InputEvent* event = value;
+
+    uint32_t* delay_time = acquire_mutex(ctx, 0);
+    if(delay_time == NULL) return;
+
+    if(event->input == InputUp && *delay_time < 1000) {
+        *delay_time += 5;
+    }
+
+    if(event->input == InputDown && *delay_time > 10) {
+        *delay_time -= 5;
+    }
+    release_mutex(ctx, delay_time);
+}
+
+void application_strobe(void* p) {
+    // WAT
+    osDelay(100);
+
+    // create pins
+    GpioPin red = {.pin = LED_RED_Pin, .port = LED_RED_GPIO_Port};
+    GpioPin green = {.pin = LED_GREEN_Pin, .port = LED_GREEN_GPIO_Port};
+    GpioPin blue = {.pin = LED_BLUE_Pin, .port = LED_BLUE_GPIO_Port};
+
+    GpioPin* red_record = &red;
+    GpioPin* green_record = &green;
+    GpioPin* blue_record = &blue;
+
+    // configure pins
+    gpio_init(red_record, GpioModeOutputOpenDrain);
+    gpio_init(green_record, GpioModeOutputOpenDrain);
+    gpio_init(blue_record, GpioModeOutputOpenDrain);
+
+    uint32_t delay_time_holder = 100;
+    ValueMutex delay_mutex;
+    init_mutex(&delay_mutex, &delay_time_holder, sizeof(delay_time_holder));
+
+    PubSub* event_record = furi_open("input_events");
+    furi_check(event_record);
+    subscribe_pubsub(event_record, event_cb, &delay_mutex);
+
+    while(1) {
+        uint32_t delay_time = 100;
+        read_mutex_block(&delay_mutex, &delay_time, sizeof(delay_time));
+
+        gpio_write(red_record, false);
+        gpio_write(green_record, false);
+        gpio_write(blue_record, false);
+        osDelay(delay_time / 10);
+        gpio_write(red_record, true);
+        gpio_write(green_record, true);
+        gpio_write(blue_record, true);
+        osDelay(delay_time);
+    }
+}