Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /*
  2. * pulse.c
  3. *
  4. * Copyright (c) 2024 Thomas Buck (thomas@xythobuz.de)
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * See <http://www.gnu.org/licenses/>.
  17. */
  18. #include <stdio.h>
  19. #include <inttypes.h>
  20. #include "pico/stdlib.h"
  21. #include "led.h"
  22. #include "log.h"
  23. #include "sequence.h"
  24. #include "pulse.h"
  25. static uint32_t out_time[NUM_CHANNELS] = {0};
  26. static uint32_t led_time[LED_COUNT] = {0};
  27. static void pulse_trigger(uint32_t i, uint32_t t_ms, bool out) {
  28. uint32_t off_t = t_ms + to_ms_since_boot(get_absolute_time());
  29. if (out) {
  30. ch_set(i, true);
  31. if (out_time[i % NUM_CHANNELS] == 0) {
  32. out_time[i % NUM_CHANNELS] = off_t;
  33. } else {
  34. debug("skip retrigger out %"PRIu32, i);
  35. }
  36. } else {
  37. led_set(i, true);
  38. if (led_time[i % LED_COUNT] == 0) {
  39. led_time[i % LED_COUNT] = off_t;
  40. } else {
  41. debug("skip retrigger led %"PRIu32, i);
  42. }
  43. }
  44. }
  45. void pulse_trigger_out(uint32_t i, uint32_t t_ms) {
  46. pulse_trigger(i, t_ms, true);
  47. }
  48. void pulse_trigger_led(uint32_t i, uint32_t t_ms) {
  49. pulse_trigger(i, t_ms, false);
  50. }
  51. void pulse_run(void) {
  52. uint32_t now = to_ms_since_boot(get_absolute_time());
  53. for (uint i = 0; i < NUM_CHANNELS; i++) {
  54. if (out_time[i] != 0) {
  55. if (out_time[i] <= now) {
  56. ch_set(i, false);
  57. out_time[i] = 0;
  58. }
  59. }
  60. }
  61. for (uint i = 0; i < LED_COUNT; i++) {
  62. if (led_time[i] != 0) {
  63. if (led_time[i] <= now) {
  64. led_set(i, false);
  65. led_time[i] = 0;
  66. }
  67. }
  68. }
  69. }