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.

MyInclusionMode.cpp 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 "MyInclusionMode.h"
  20. // global variables
  21. extern MyMessage _msgTmp;
  22. unsigned long _inclusionStartTime;
  23. bool _inclusionMode;
  24. inline void inclusionInit()
  25. {
  26. _inclusionMode = false;
  27. #if defined(MY_INCLUSION_BUTTON_FEATURE)
  28. // Setup digital in that triggers inclusion mode
  29. hwPinMode(MY_INCLUSION_MODE_BUTTON_PIN, INPUT_PULLUP);
  30. #endif
  31. #if defined (MY_INCLUSION_LED_PIN)
  32. // Setup LED pin that indicates inclusion mode
  33. hwPinMode(MY_INCLUSION_LED_PIN, OUTPUT);
  34. hwDigitalWrite(MY_INCLUSION_LED_PIN, LED_OFF);
  35. #endif
  36. }
  37. void inclusionModeSet(bool newMode)
  38. {
  39. if (newMode != _inclusionMode) {
  40. _inclusionMode = newMode;
  41. // Send back mode change to controller
  42. gatewayTransportSend(buildGw(_msgTmp, I_INCLUSION_MODE).set((uint8_t)(_inclusionMode?1:0)));
  43. if (_inclusionMode) {
  44. _inclusionStartTime = hwMillis();
  45. }
  46. }
  47. #if defined (MY_INCLUSION_LED_PIN)
  48. hwDigitalWrite(MY_INCLUSION_LED_PIN, _inclusionMode ? LED_ON : LED_OFF);
  49. #endif
  50. }
  51. inline void inclusionProcess()
  52. {
  53. #ifdef MY_INCLUSION_BUTTON_FEATURE
  54. if (!_inclusionMode && hwDigitalRead(MY_INCLUSION_MODE_BUTTON_PIN) == MY_INCLUSION_BUTTON_PRESSED) {
  55. // Start inclusion mode
  56. inclusionModeSet(true);
  57. }
  58. #endif
  59. if (_inclusionMode && hwMillis()-_inclusionStartTime>MY_INCLUSION_MODE_DURATION*1000L) {
  60. // inclusionTimeInMinutes minute(s) has passed.. stop inclusion mode
  61. inclusionModeSet(false);
  62. }
  63. }