backlight-control.c 994 B

12345678910111213141516171819202122232425262728293031
  1. #include <furi.h>
  2. #include <api-hal.h>
  3. #include <notification/notification-messages.h>
  4. #define BACKLIGHT_TIME 30000
  5. #define BACKLIGHT_FLAG_ACTIVITY 0x00000001U
  6. static void event_cb(const void* value, void* ctx) {
  7. osThreadFlagsSet((osThreadId_t)ctx, BACKLIGHT_FLAG_ACTIVITY);
  8. }
  9. int32_t backlight_control(void* p) {
  10. // open record
  11. NotificationApp* notifications = furi_record_open("notification");
  12. PubSub* event_record = furi_record_open("input_events");
  13. subscribe_pubsub(event_record, event_cb, (void*)osThreadGetId());
  14. notification_internal_message(notifications, &sequence_display_on);
  15. while(1) {
  16. // wait for event
  17. if(osThreadFlagsWait(BACKLIGHT_FLAG_ACTIVITY, osFlagsWaitAny, BACKLIGHT_TIME) ==
  18. BACKLIGHT_FLAG_ACTIVITY) {
  19. notification_internal_message(notifications, &sequence_display_on);
  20. } else {
  21. notification_internal_message(notifications, &sequence_display_off);
  22. }
  23. }
  24. return 0;
  25. }