strobe.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include "flipper_v2.h"
  2. static void event_cb(const void* value, void* ctx) {
  3. const InputEvent* event = value;
  4. uint32_t* delay_time = acquire_mutex(ctx, 0);
  5. if(delay_time == NULL) return;
  6. if(event->input == InputUp && *delay_time < 1000) {
  7. *delay_time += 5;
  8. }
  9. if(event->input == InputDown && *delay_time > 10) {
  10. *delay_time -= 5;
  11. }
  12. release_mutex(ctx, delay_time);
  13. }
  14. void application_strobe(void* p) {
  15. // WAT
  16. osDelay(100);
  17. // create pins
  18. GpioPin red = {.pin = LED_RED_Pin, .port = LED_RED_GPIO_Port};
  19. GpioPin green = {.pin = LED_GREEN_Pin, .port = LED_GREEN_GPIO_Port};
  20. GpioPin blue = {.pin = LED_BLUE_Pin, .port = LED_BLUE_GPIO_Port};
  21. GpioPin* red_record = &red;
  22. GpioPin* green_record = &green;
  23. GpioPin* blue_record = &blue;
  24. // configure pins
  25. gpio_init(red_record, GpioModeOutputOpenDrain);
  26. gpio_init(green_record, GpioModeOutputOpenDrain);
  27. gpio_init(blue_record, GpioModeOutputOpenDrain);
  28. uint32_t delay_time_holder = 100;
  29. ValueMutex delay_mutex;
  30. init_mutex(&delay_mutex, &delay_time_holder, sizeof(delay_time_holder));
  31. PubSub* event_record = furi_open("input_events");
  32. furi_check(event_record);
  33. subscribe_pubsub(event_record, event_cb, &delay_mutex);
  34. while(1) {
  35. uint32_t delay_time = 100;
  36. read_mutex_block(&delay_mutex, &delay_time, sizeof(delay_time));
  37. gpio_write(red_record, false);
  38. gpio_write(green_record, false);
  39. gpio_write(blue_record, false);
  40. osDelay(delay_time / 10);
  41. gpio_write(red_record, true);
  42. gpio_write(green_record, true);
  43. gpio_write(blue_record, true);
  44. osDelay(delay_time);
  45. }
  46. }