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.

compatibility.cpp 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <time.h>
  20. #include <sys/time.h>
  21. #include <stdlib.h>
  22. #include "Arduino.h"
  23. // For millis()
  24. static unsigned long millis_at_start = 0;
  25. void yield(void) {}
  26. unsigned long millis(void)
  27. {
  28. timeval curTime;
  29. if (millis_at_start == 0) {
  30. gettimeofday(&curTime, NULL);
  31. millis_at_start = curTime.tv_sec;
  32. }
  33. gettimeofday(&curTime, NULL);
  34. return ((curTime.tv_sec - millis_at_start) * 1000) + (curTime.tv_usec / 1000);
  35. }
  36. unsigned long micros()
  37. {
  38. timeval curTime;
  39. if (millis_at_start == 0) {
  40. gettimeofday(&curTime, NULL);
  41. millis_at_start = curTime.tv_sec;
  42. }
  43. gettimeofday(&curTime, NULL);
  44. return ((curTime.tv_sec - millis_at_start) * 1000000) + (curTime.tv_usec);
  45. }
  46. void _delay_milliseconds(unsigned int millis)
  47. {
  48. struct timespec sleeper;
  49. sleeper.tv_sec = (time_t)(millis / 1000);
  50. sleeper.tv_nsec = (long)(millis % 1000) * 1000000;
  51. nanosleep(&sleeper, NULL);
  52. }
  53. void _delay_microseconds(unsigned int micro)
  54. {
  55. struct timespec sleeper;
  56. sleeper.tv_sec = (time_t)(micro / 1000000);
  57. sleeper.tv_nsec = (long)(micro % 1000000) * 1000;
  58. nanosleep(&sleeper, NULL);
  59. }
  60. void randomSeed(unsigned long seed)
  61. {
  62. if (seed != 0) {
  63. srand(seed);
  64. }
  65. }
  66. long randMax(long howbig)
  67. {
  68. if (howbig == 0) {
  69. return 0;
  70. }
  71. return rand() % howbig;
  72. }
  73. long randMinMax(long howsmall, long howbig)
  74. {
  75. if (howsmall >= howbig) {
  76. return howsmall;
  77. }
  78. long diff = howbig - howsmall;
  79. return randMax(diff) + howsmall;
  80. }