From 1fbfc5a61a0a30cb25f49c28558925476980699d Mon Sep 17 00:00:00 2001 From: coreglitch Date: Sat, 7 Nov 2020 15:24:40 +0600 Subject: [PATCH] Blink strobe (#213) * blink all led and control freq by button * rename to strobe --- applications/applications.h | 4 +-- applications/applications.mk | 1 + applications/examples/blink.c | 1 - applications/examples/strobe.c | 58 ++++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 applications/examples/strobe.c diff --git a/applications/applications.h b/applications/applications.h index 50098f73..697f2f9a 100644 --- a/applications/applications.h +++ b/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 diff --git a/applications/applications.mk b/applications/applications.mk index e911a526..5a5f9970 100644 --- a/applications/applications.mk +++ b/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 diff --git a/applications/examples/blink.c b/applications/examples/blink.c index 4a1bff15..d44d130e 100644 --- a/applications/examples/blink.c +++ b/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) { diff --git a/applications/examples/strobe.c b/applications/examples/strobe.c new file mode 100644 index 00000000..fad250e9 --- /dev/null +++ b/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); + } +} \ No newline at end of file