backlight-control.c 1023 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. // create pin
  8. GpioPin backlight = backlight_gpio;
  9. // TODO open record
  10. GpioPin* backlight_record = &backlight;
  11. // configure pin
  12. gpio_init(backlight_record, GpioModeOutputPushPull);
  13. gpio_write(backlight_record, true);
  14. StaticSemaphore_t event_descriptor;
  15. SemaphoreHandle_t update = xSemaphoreCreateCountingStatic(255, 0, &event_descriptor);
  16. // open record
  17. PubSub* event_record = furi_open("input_events");
  18. furi_check(event_record);
  19. subscribe_pubsub(event_record, event_cb, (void*)update);
  20. // we ready to work
  21. furiac_ready();
  22. while(1) {
  23. // wait for event
  24. if(xSemaphoreTake(update, BACKLIGHT_TIME) == pdTRUE) {
  25. gpio_write(backlight_record, true);
  26. } else {
  27. gpio_write(backlight_record, false);
  28. }
  29. }
  30. }