flipperzero-firmware/applications/backlight-control/backlight-control.c
Vadim Kaushan bb68fca20b
Implement ValueManager and ValueComposer (#183)
* Fix ValueManager implementation
* Implement ValueComposer
* Add constructor for ValueManager
* Add value-expanders.h to flipper_v2.h set
* Move COPY_COMPOSE body into a .c file
* Add test for ValueManager
* Add destructors for ValueMutex, ValueManager and ValueComposer
* Use destructors in tests
* Move composition logic into perform_compose()
* Add docs for perform_compose()
* Add test for ValueComposer
* Replace atomic_bool with bool as g++ compiler doesn't support C11 atomics
* Add Event type
* Add semaphore support to the local target
* Add test for Event
* Update input records and relevant examples
* Rename Event to AppEvent in the cc1101-workaround example
* Rename Event to AppEvent in the irda example
* Use Event in ValueComposer to wait for update request
* Add perform_compose_internal() function
* fix Event/AppEvent

Co-authored-by: aanper <mail@s3f.ru>
2020-10-26 12:26:15 +03:00

32 lines
990 B
C

#include "flipper_v2.h"
static void event_cb(const void* value, void* ctx) {
xSemaphoreGive((SemaphoreHandle_t*)ctx);
}
const uint32_t BACKLIGHT_TIME = 10000;
void backlight_control(void* p) {
// TODO use FURI
HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_SET);
StaticSemaphore_t event_descriptor;
SemaphoreHandle_t update = xSemaphoreCreateCountingStatic(255, 0, &event_descriptor);
// open record
PubSub* event_record = furi_open("input_events");
assert(event_record != NULL);
subscribe_pubsub(event_record, event_cb, (void*)update);
// we ready to work
furiac_ready();
while(1) {
// wait for event
if(xSemaphoreTake(update, BACKLIGHT_TIME) == pdTRUE) {
HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_SET);
} else {
HAL_GPIO_WritePin(DISPLAY_BACKLIGHT_GPIO_Port, DISPLAY_BACKLIGHT_Pin, GPIO_PIN_RESET);
}
}
}