Ein Roboter mit bürstenlosem Antrieb, differenzial und NRF24L01 Funk. Großflächig gebaut um ein großes Solarpanel aufzunehmen. https://gitlab.informatik.hs-fulda.de/fdai5253/roboter
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.

83 lines
1.7 KiB

  1. /*
  2. * TMRh20 2015
  3. *
  4. */
  5. #include "gpio.h"
  6. GPIO::GPIO() {
  7. // Prophet: basic members initialization
  8. gpio_ce_pin = -1;
  9. //gpio_cs_pin = -1;
  10. gpio_0 = NULL;
  11. //gpio_1 = NULL;
  12. }
  13. GPIO::~GPIO() {
  14. // Prophet: this should free memory, and unexport pins when RF24 and/or GPIO gets deleted or goes out of scope
  15. this->close(gpio_ce_pin);
  16. //this->close(gpio_cs_pin);
  17. }
  18. void GPIO::begin(uint8_t ce_pin, uint8_t cs_pin)
  19. {
  20. gpio_ce_pin = ce_pin;
  21. //gpio_cs_pin = cs_pin;
  22. // Prophet: owner can be set here, because we use our pins exclusively, and are making mraa:Gpio context persistent
  23. // so pins will be unexported only if close is called, or on destruction
  24. gpio_0 = new mraa::Gpio(ce_pin/*,0*/);
  25. //gpio_1 = new mraa::Gpio(cs_pin/*,0*/);
  26. }
  27. void GPIO::open(int port, int DDR)
  28. {
  29. if(port == gpio_ce_pin){
  30. gpio_0 = new mraa::Gpio(port,0);
  31. gpio_0->useMmap(true);
  32. gpio_0->dir( (mraa::Dir)DDR);
  33. }/*else
  34. if(port == gpio_cs_pin){
  35. gpio_1 = new mraa::Gpio(port,0);
  36. gpio_1->useMmap(true);
  37. gpio_1->dir( (mraa::Dir)DDR);
  38. }*/
  39. }
  40. void GPIO::close(int port)
  41. {
  42. // Prophet: using same theme of working with port numbers as with GPIO::open,
  43. // checking for mraa::Gpio context existence to be sure, that GPIO::begin was called
  44. if(port == gpio_ce_pin)
  45. {
  46. if (gpio_0 != NULL) {
  47. delete gpio_0;
  48. }
  49. }
  50. /*if(port == gpio_cs_pin) {
  51. if (gpio_1 != NULL) {
  52. delete gpio_1;
  53. }
  54. }*/
  55. }
  56. int GPIO::read(int port)
  57. {
  58. if(port == gpio_ce_pin){
  59. return gpio_0->read();
  60. }/*else
  61. if(port == gpio_cs_pin){
  62. return gpio_1->read();
  63. }*/
  64. return -1;
  65. }
  66. void GPIO::write(int port, int value){
  67. if(port == gpio_ce_pin){
  68. gpio_0->write( value);
  69. }/*else
  70. if(port == gpio_cs_pin){
  71. gpio_1->write( value);
  72. }*/
  73. }