strobe.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <furi.h>
  2. #include <input.h>
  3. static void event_cb(const void* value, void* ctx) {
  4. const InputEvent* event = value;
  5. uint32_t* delay_time = acquire_mutex(ctx, 0);
  6. if(delay_time == NULL) return;
  7. if(event->input == InputUp && *delay_time < 1000) {
  8. *delay_time += 5;
  9. }
  10. if(event->input == InputDown && *delay_time > 10) {
  11. *delay_time -= 5;
  12. }
  13. release_mutex(ctx, delay_time);
  14. }
  15. void application_strobe(void* p) {
  16. // WAT
  17. osDelay(100);
  18. // create pins
  19. GpioPin red = {.pin = LED_RED_Pin, .port = LED_RED_GPIO_Port};
  20. GpioPin green = {.pin = LED_GREEN_Pin, .port = LED_GREEN_GPIO_Port};
  21. GpioPin blue = {.pin = LED_BLUE_Pin, .port = LED_BLUE_GPIO_Port};
  22. GpioPin* red_record = &red;
  23. GpioPin* green_record = &green;
  24. GpioPin* blue_record = &blue;
  25. // configure pins
  26. gpio_init(red_record, GpioModeOutputOpenDrain);
  27. gpio_init(green_record, GpioModeOutputOpenDrain);
  28. gpio_init(blue_record, GpioModeOutputOpenDrain);
  29. uint32_t delay_time_holder = 100;
  30. ValueMutex delay_mutex;
  31. init_mutex(&delay_mutex, &delay_time_holder, sizeof(delay_time_holder));
  32. PubSub* event_record = furi_record_open("input_events");
  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. }