raspberrypi_io.c 781 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * raspberrypi_io.c
  3. *
  4. * Created on: 23.06.2014
  5. * Author: root
  6. */
  7. #include "raspberrypi_io.h"
  8. #ifdef RASPI
  9. int readTemp(float *temp){
  10. FILE *ptr_file;
  11. char buf[1000];
  12. char delimiter[] = "=";
  13. char *ptr_temp;
  14. long temperaturInmC;
  15. ptr_file =fopen("/sys/bus/w1/devices/10-000802c607f3/w1_slave","r");
  16. if (!ptr_file){
  17. puts("ERROR: no sensor");
  18. return 1;
  19. }
  20. fgets(buf, 1000, ptr_file);
  21. fgets(buf, 1000, ptr_file);
  22. ptr_temp = strtok(buf, (char*) delimiter);
  23. ptr_temp = strtok((void*)0, (char*) delimiter);
  24. temperaturInmC = atol(ptr_temp);
  25. fclose(ptr_file);
  26. *temp = (float)temperaturInmC/1000;
  27. return 0;
  28. }
  29. int writeLEDred(int state){
  30. if (wiringPiSetup() == -1){
  31. return 1;
  32. }
  33. pinMode(0, OUTPUT);
  34. digitalWrite(0, state);
  35. return 0;
  36. }
  37. #endif