Smart-Home am Beispiel der Präsenzerkennung im Raum Projektarbeit Lennart Heimbs, Johannes Krug, Sebastian Dohle und Kevin Holzschuh bei Prof. Oliver Hofmann SS2019
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.

MyLeds.cpp 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * The MySensors Arduino library handles the wireless radio link and protocol
  3. * between your home built sensors/actuators and HA controller of choice.
  4. * The sensors forms a self healing radio network with optional repeaters. Each
  5. * repeater and gateway builds a routing tables in EEPROM which keeps track of the
  6. * network topology allowing messages to be routed to nodes.
  7. *
  8. * Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
  9. * Copyright (C) 2013-2018 Sensnology AB
  10. * Full contributor list: https://github.com/mysensors/MySensors/graphs/contributors
  11. *
  12. * Documentation: http://www.mysensors.org
  13. * Support Forum: http://forum.mysensors.org
  14. *
  15. * This program is free software; you can redistribute it and/or
  16. * modify it under the terms of the GNU General Public License
  17. * version 2 as published by the Free Software Foundation.
  18. */
  19. #include "MyLeds.h"
  20. #define LED_ON_OFF_RATIO (4) // Power of 2 please
  21. #define LED_PROCESS_INTERVAL_MS (MY_DEFAULT_LED_BLINK_PERIOD/LED_ON_OFF_RATIO)
  22. // these variables don't need to be volatile, since we are not using interrupts
  23. static uint8_t countRx;
  24. static uint8_t countTx;
  25. static uint8_t countErr;
  26. static unsigned long prevTime;
  27. inline void ledsInit()
  28. {
  29. // initialize counters
  30. countRx = 0;
  31. countTx = 0;
  32. countErr = 0;
  33. // Setup led pins
  34. #if defined(MY_DEFAULT_RX_LED_PIN)
  35. hwPinMode(MY_DEFAULT_RX_LED_PIN, OUTPUT);
  36. #endif
  37. #if defined(MY_DEFAULT_TX_LED_PIN)
  38. hwPinMode(MY_DEFAULT_TX_LED_PIN, OUTPUT);
  39. #endif
  40. #if defined(MY_DEFAULT_ERR_LED_PIN)
  41. hwPinMode(MY_DEFAULT_ERR_LED_PIN, OUTPUT);
  42. #endif
  43. prevTime = hwMillis() -
  44. LED_PROCESS_INTERVAL_MS; // Subtract some, to make sure leds gets updated on first run.
  45. ledsProcess();
  46. }
  47. void ledsProcess()
  48. {
  49. // Just return if it is not the time...
  50. if ((hwMillis() - prevTime) < LED_PROCESS_INTERVAL_MS) {
  51. return;
  52. }
  53. prevTime = hwMillis();
  54. #if defined(MY_DEFAULT_RX_LED_PIN) || defined(MY_DEFAULT_TX_LED_PIN) || defined(MY_DEFAULT_ERR_LED_PIN)
  55. uint8_t state;
  56. #endif
  57. // For an On/Off ratio of 4, the pattern repeated will be [on, on, on, off]
  58. // until the counter becomes 0.
  59. #if defined(MY_DEFAULT_RX_LED_PIN)
  60. if (countRx) {
  61. --countRx;
  62. }
  63. state = (countRx & (LED_ON_OFF_RATIO-1)) ? LED_ON : LED_OFF;
  64. hwDigitalWrite(MY_DEFAULT_RX_LED_PIN, state);
  65. #endif
  66. #if defined(MY_DEFAULT_TX_LED_PIN)
  67. if (countTx) {
  68. --countTx;
  69. }
  70. state = (countTx & (LED_ON_OFF_RATIO-1)) ? LED_ON : LED_OFF;
  71. hwDigitalWrite(MY_DEFAULT_TX_LED_PIN, state);
  72. #endif
  73. #if defined(MY_DEFAULT_ERR_LED_PIN)
  74. if (countErr) {
  75. --countErr;
  76. }
  77. state = (countErr & (LED_ON_OFF_RATIO-1)) ? LED_ON : LED_OFF;
  78. hwDigitalWrite(MY_DEFAULT_ERR_LED_PIN, state);
  79. #endif
  80. }
  81. void ledsBlinkRx(uint8_t cnt)
  82. {
  83. if (!countRx) {
  84. countRx = cnt*LED_ON_OFF_RATIO;
  85. }
  86. ledsProcess();
  87. }
  88. void ledsBlinkTx(uint8_t cnt)
  89. {
  90. if(!countTx) {
  91. countTx = cnt*LED_ON_OFF_RATIO;
  92. }
  93. ledsProcess();
  94. }
  95. void ledsBlinkErr(uint8_t cnt)
  96. {
  97. if(!countErr) {
  98. countErr = cnt*LED_ON_OFF_RATIO;
  99. }
  100. ledsProcess();
  101. }
  102. bool ledsBlinking()
  103. {
  104. return countRx || countTx || countErr;
  105. }