sensor_driver.c.reference.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /*
  2. * sensor number: 1
  3. * sensor name: +12V
  4. * brief: ltc4280
  5. */
  6. int sensor_1_init(void)
  7. {
  8. return 0;
  9. }
  10. int sensor_1_write(void)
  11. {
  12. return 0;
  13. }
  14. int sensor_1_read(uint8_t *reading)
  15. {
  16. uint8_t buf = 5;
  17. int ret;
  18. int fd = open("/dev/i2c3", O_RDWR);
  19. ret = stm32_i2c_master_write(fd, 0xAA, &buf, 1);
  20. if(ret == 0)
  21. {
  22. ret = stm32_i2c_master_read(fd, 0xAA, &buf, 1);
  23. if(ret != 0)
  24. {
  25. printf("Sensor 1 read error!\n");
  26. }
  27. }
  28. else
  29. {
  30. printf("Sensor 1 write error!\n");
  31. }
  32. close(fd);
  33. //printf("read sensor 1: %#x!\n", buf);
  34. *reading = buf;
  35. return 0;
  36. }
  37. /*
  38. * sensor number: 2
  39. * sensor name: +12V_Current
  40. * brief: ltc4280
  41. */
  42. int sensor_2_init(void)
  43. {
  44. // log("init sensor 2!\r\n");
  45. return 0;
  46. }
  47. int sensor_2_write(void)
  48. {
  49. // log("write sensor 2!\r\n");
  50. return 0;
  51. }
  52. int sensor_2_read(uint8_t *reading)
  53. {
  54. uint8_t buf = 4;
  55. int ret;
  56. int fd = open("/dev/i2c3", O_RDWR);
  57. ret = stm32_i2c_master_write(fd, 0xAA, &buf, 1);
  58. if(ret == 0)
  59. {
  60. ret = stm32_i2c_master_read(fd, 0xAA, &buf, 1);
  61. if(ret != 0)
  62. printf("Sensor 2 read error!\n");
  63. }
  64. else
  65. printf("Sensor 2 write error!\n");
  66. close(fd);
  67. *reading = buf;
  68. return 0;
  69. }
  70. /*
  71. * sensor number: 3
  72. * sensor name: Temp_Board
  73. * brief: G780 local
  74. */
  75. int sensor_3_init(void)
  76. {
  77. // log("init sensor 2!\r\n");
  78. return 0;
  79. }
  80. int sensor_3_write(void)
  81. {
  82. // log("write sensor 2!\r\n");
  83. return 0;
  84. }
  85. int sensor_3_read(uint8_t *reading)
  86. {
  87. uint8_t buf = 0;
  88. int ret;
  89. int fd = open("/dev/i2c3", O_RDWR);
  90. ret = stm32_i2c_master_write(fd, 0x98, &buf, 1);
  91. if(ret == 0)
  92. {
  93. ret = stm32_i2c_master_read(fd, 0x98, &buf, 1);
  94. if(ret != 0)
  95. printf("Sensor 3 read error!\n");
  96. }
  97. else
  98. printf("Sensor 3 write error!\n");
  99. close(fd);
  100. *reading = buf;
  101. return 0;
  102. }
  103. /*
  104. * sensor number: 4
  105. * sensor name: Temp_FPGA
  106. * brief: G780 remote
  107. */
  108. int sensor_4_init(void)
  109. {
  110. // log("init sensor 2!\r\n");
  111. return 0;
  112. }
  113. int sensor_4_write(void)
  114. {
  115. // log("write sensor 2!\r\n");
  116. return 0;
  117. }
  118. int sensor_4_read(uint8_t *reading)
  119. {
  120. uint8_t buf = 1;
  121. int ret;
  122. int fd = open("/dev/i2c3", O_RDWR);
  123. ret = stm32_i2c_master_write(fd, 0x98, &buf, 1);
  124. if(ret == 0)
  125. {
  126. ret = stm32_i2c_master_read(fd, 0x98, &buf, 1);
  127. if(ret != 0)
  128. printf("Sensor 4 read error!\n");
  129. }
  130. else
  131. printf("Sensor 4 write error\n");
  132. close(fd);
  133. *reading = buf;
  134. return 0;
  135. }
  136. /*
  137. * sensor number: 5
  138. * sensor name: +1.5V
  139. * brief: adc_ch1
  140. */
  141. int sensor_5_init(void)
  142. {
  143. return 0;
  144. }
  145. int sensor_5_write(void)
  146. {
  147. return 0;
  148. }
  149. int sensor_5_read(uint8_t *reading)
  150. {
  151. uint16_t buf;
  152. stm32_adc_get_value(1, &buf);
  153. *reading = buf>>4;
  154. return 0;
  155. }
  156. /*
  157. * sensor number: 6
  158. * sensor name: +0.75V
  159. * brief: adc_ch2
  160. */
  161. int sensor_6_init(void)
  162. {
  163. return 0;
  164. }
  165. int sensor_6_write(void)
  166. {
  167. return 0;
  168. }
  169. int sensor_6_read(uint8_t *reading)
  170. {
  171. uint16_t buf;
  172. stm32_adc_get_value(2, &buf);
  173. *reading = buf>>4;
  174. return 0;
  175. }