backlight-control.c 975 B

123456789101112131415161718192021222324252627282930313233343536
  1. #include "flipper_v2.h"
  2. static void event_cb(const void* value, void* ctx) {
  3. xSemaphoreGive((SemaphoreHandle_t*)ctx);
  4. }
  5. const uint32_t BACKLIGHT_TIME = 10000;
  6. void backlight_control(void* p) {
  7. // TODO open record
  8. const GpioPin* backlight_record = &backlight_gpio;
  9. // configure pin
  10. gpio_init(backlight_record, GpioModeOutputPushPull);
  11. gpio_write(backlight_record, true);
  12. StaticSemaphore_t event_descriptor;
  13. SemaphoreHandle_t update = xSemaphoreCreateCountingStatic(255, 0, &event_descriptor);
  14. // open record
  15. PubSub* event_record = furi_open("input_events");
  16. furi_check(event_record);
  17. subscribe_pubsub(event_record, event_cb, (void*)update);
  18. // we ready to work
  19. furiac_ready();
  20. while(1) {
  21. // wait for event
  22. if(xSemaphoreTake(update, BACKLIGHT_TIME) == pdTRUE) {
  23. gpio_write(backlight_record, true);
  24. } else {
  25. gpio_write(backlight_record, false);
  26. }
  27. }
  28. }