暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

pulse.c 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "sequence.h"
  23. #include "pulse.h"
  24. static uint32_t out_time[NUM_CHANNELS] = {0};
  25. static uint32_t led_time[LED_COUNT] = {0};
  26. static void pulse_trigger(uint32_t i, uint32_t t_ms, bool out) {
  27. uint32_t off_t = t_ms + to_ms_since_boot(get_absolute_time());
  28. if (out) {
  29. ch_set(i, true);
  30. if (out_time[i % NUM_CHANNELS] == 0) {
  31. out_time[i % NUM_CHANNELS] = off_t;
  32. } else {
  33. printf("%s: skip retrigger out %"PRIu32"\n", __func__, i);
  34. }
  35. } else {
  36. led_set(i, true);
  37. if (led_time[i % LED_COUNT] == 0) {
  38. led_time[i % LED_COUNT] = off_t;
  39. } else {
  40. printf("%s: skip retrigger led %"PRIu32"\n", __func__, i);
  41. }
  42. }
  43. }
  44. void pulse_trigger_out(uint32_t i, uint32_t t_ms) {
  45. pulse_trigger(i, t_ms, true);
  46. }
  47. void pulse_trigger_led(uint32_t i, uint32_t t_ms) {
  48. pulse_trigger(i, t_ms, false);
  49. }
  50. void pulse_run(void) {
  51. uint32_t now = to_ms_since_boot(get_absolute_time());
  52. for (uint i = 0; i < NUM_CHANNELS; i++) {
  53. if (out_time[i] != 0) {
  54. if (out_time[i] <= now) {
  55. ch_set(i, false);
  56. out_time[i] = 0;
  57. }
  58. }
  59. }
  60. for (uint i = 0; i < LED_COUNT; i++) {
  61. if (led_time[i] != 0) {
  62. if (led_time[i] <= now) {
  63. led_set(i, false);
  64. led_time[i] = 0;
  65. }
  66. }
  67. }
  68. }