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.

BCM.cpp 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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 "BCM.h"
  20. #include <stdlib.h>
  21. #include "log.h"
  22. // Declare a single default instance
  23. BCMClass BCM = BCMClass();
  24. uint8_t BCMClass::initialized = 0;
  25. BCMClass::~BCMClass()
  26. {
  27. if (initialized) {
  28. bcm2835_close();
  29. initialized = 0;
  30. }
  31. }
  32. uint8_t BCMClass::init()
  33. {
  34. if (!bcm2835_init()) {
  35. logError("Failed to initialized bcm2835.\n");
  36. exit(1);
  37. }
  38. initialized = 1;
  39. return 1;
  40. }
  41. void BCMClass::pinMode(uint8_t gpio, uint8_t mode)
  42. {
  43. if (!initialized) {
  44. init();
  45. }
  46. bcm2835_gpio_fsel(gpio, mode);
  47. }
  48. void BCMClass::digitalWrite(uint8_t gpio, uint8_t value)
  49. {
  50. if (!initialized) {
  51. init();
  52. }
  53. bcm2835_gpio_write(gpio, value);
  54. // Delay to allow any change in state to be reflected in the LEVn, register bit.
  55. delayMicroseconds(1);
  56. }
  57. uint8_t BCMClass::digitalRead(uint8_t gpio)
  58. {
  59. if (!initialized) {
  60. init();
  61. }
  62. return bcm2835_gpio_lev(gpio);
  63. }
  64. uint8_t BCMClass::isInitialized()
  65. {
  66. return initialized;
  67. }