target.cpp 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #include <Arduino.h>
  2. //#include "t1000e_sensors.h"
  3. #include "target.h"
  4. #include <helpers/sensors/MicroNMEALocationProvider.h>
  5. MinewsemiME25LS01Board board;
  6. RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
  7. WRAPPER_CLASS radio_driver(radio, board);
  8. VolatileRTCClock rtc_clock;
  9. MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
  10. //T1000SensorManager sensors = T1000SensorManager(nmea);
  11. me25ls01SensorManager sensors = me25ls01SensorManager(nmea);
  12. #ifdef DISPLAY_CLASS
  13. NullDisplayDriver display;
  14. #endif
  15. #ifndef LORA_CR
  16. #define LORA_CR 5
  17. #endif
  18. #ifdef RF_SWITCH_TABLE
  19. static const uint32_t rfswitch_dios[Module::RFSWITCH_MAX_PINS] = {
  20. RADIOLIB_LR11X0_DIO5,
  21. RADIOLIB_LR11X0_DIO6,
  22. RADIOLIB_LR11X0_DIO7,
  23. RADIOLIB_LR11X0_DIO8,
  24. RADIOLIB_NC
  25. };
  26. static const Module::RfSwitchMode_t rfswitch_table[] = {
  27. // mode DIO5 DIO6 DIO7 DIO8
  28. { LR11x0::MODE_STBY, {LOW, LOW, LOW, LOW }},
  29. { LR11x0::MODE_RX, {HIGH, LOW, LOW, HIGH }},
  30. { LR11x0::MODE_TX, {HIGH, HIGH, LOW, HIGH }},
  31. { LR11x0::MODE_TX_HP, {LOW, HIGH, LOW, HIGH }},
  32. { LR11x0::MODE_TX_HF, {LOW, LOW, LOW, LOW }},
  33. { LR11x0::MODE_GNSS, {LOW, LOW, HIGH, LOW }},
  34. { LR11x0::MODE_WIFI, {LOW, LOW, LOW, LOW }},
  35. END_OF_MODE_TABLE,
  36. };
  37. #endif
  38. bool radio_init() {
  39. //rtc_clock.begin(Wire);
  40. #ifdef LR11X0_DIO3_TCXO_VOLTAGE
  41. float tcxo = LR11X0_DIO3_TCXO_VOLTAGE;
  42. #else
  43. float tcxo = 1.6f;
  44. #endif
  45. SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI);
  46. SPI.begin();
  47. int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_LR11X0_LORA_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, tcxo);
  48. if (status != RADIOLIB_ERR_NONE) {
  49. Serial.print("ERROR: radio init failed: ");
  50. Serial.println(status);
  51. return false; // fail
  52. }
  53. radio.setCRC(1);
  54. #ifdef RF_SWITCH_TABLE
  55. radio.setRfSwitchTable(rfswitch_dios, rfswitch_table);
  56. #endif
  57. #ifdef RX_BOOSTED_GAIN
  58. radio.setRxBoostedGainMode(RX_BOOSTED_GAIN);
  59. #endif
  60. return true; // success
  61. }
  62. uint32_t radio_get_rng_seed() {
  63. return radio.random(0x7FFFFFFF);
  64. }
  65. void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
  66. radio.setFrequency(freq);
  67. radio.setSpreadingFactor(sf);
  68. radio.setBandwidth(bw);
  69. radio.setCodingRate(cr);
  70. }
  71. void radio_set_tx_power(uint8_t dbm) {
  72. radio.setOutputPower(dbm);
  73. }
  74. mesh::LocalIdentity radio_new_identity() {
  75. RadioNoiseListener rng(radio);
  76. return mesh::LocalIdentity(&rng); // create new random identity
  77. }
  78. void me25ls01SensorManager::start_gps() {
  79. gps_active = false;
  80. //_nmea->begin();
  81. // this init sequence should be better
  82. // comes from seeed examples and deals with all gps pins
  83. // pinMode(GPS_EN, OUTPUT);
  84. // digitalWrite(GPS_EN, HIGH);
  85. // delay(10);
  86. // pinMode(GPS_VRTC_EN, OUTPUT);
  87. // digitalWrite(GPS_VRTC_EN, HIGH);
  88. // delay(10);
  89. // pinMode(GPS_RESET, OUTPUT);
  90. // digitalWrite(GPS_RESET, HIGH);
  91. // delay(10);
  92. // digitalWrite(GPS_RESET, LOW);
  93. // pinMode(GPS_SLEEP_INT, OUTPUT);
  94. // digitalWrite(GPS_SLEEP_INT, HIGH);
  95. // pinMode(GPS_RTC_INT, OUTPUT);
  96. // digitalWrite(GPS_RTC_INT, LOW);
  97. // pinMode(GPS_RESETB, INPUT_PULLUP);
  98. }
  99. void me25ls01SensorManager::sleep_gps() {
  100. gps_active = false;
  101. // digitalWrite(GPS_VRTC_EN, HIGH);
  102. // digitalWrite(GPS_EN, LOW);
  103. // digitalWrite(GPS_RESET, HIGH);
  104. // digitalWrite(GPS_SLEEP_INT, HIGH);
  105. // digitalWrite(GPS_RTC_INT, LOW);
  106. // pinMode(GPS_RESETB, OUTPUT);
  107. // digitalWrite(GPS_RESETB, LOW);
  108. //_nmea->stop();
  109. }
  110. void me25ls01SensorManager::stop_gps() {
  111. gps_active = false;
  112. // digitalWrite(GPS_VRTC_EN, LOW);
  113. // digitalWrite(GPS_EN, LOW);
  114. // digitalWrite(GPS_RESET, HIGH);
  115. // digitalWrite(GPS_SLEEP_INT, HIGH);
  116. // digitalWrite(GPS_RTC_INT, LOW);
  117. // pinMode(GPS_RESETB, OUTPUT);
  118. // digitalWrite(GPS_RESETB, LOW);
  119. // //_nmea->stop();
  120. }
  121. bool me25ls01SensorManager::begin() {
  122. // init GPS
  123. Serial1.begin(115200);
  124. // make sure gps pin are off
  125. // digitalWrite(GPS_VRTC_EN, LOW);
  126. // digitalWrite(GPS_RESET, LOW);
  127. // digitalWrite(GPS_SLEEP_INT, LOW);
  128. // digitalWrite(GPS_RTC_INT, LOW);
  129. // pinMode(GPS_RESETB, OUTPUT);
  130. // digitalWrite(GPS_RESETB, LOW);
  131. return true;
  132. }
  133. bool me25ls01SensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) {
  134. if (requester_permissions & TELEM_PERM_LOCATION) { // does requester have permission?
  135. //telemetry.addGPS(TELEM_CHANNEL_SELF, node_lat, node_lon, node_altitude);
  136. }
  137. if (requester_permissions & TELEM_PERM_ENVIRONMENT) {
  138. //telemetry.addLuminosity(TELEM_CHANNEL_SELF, t1000e_get_light());
  139. //telemetry.addTemperature(TELEM_CHANNEL_SELF, t1000e_get_temperature());
  140. }
  141. return true;
  142. }
  143. void me25ls01SensorManager::loop() {
  144. static long next_gps_update = 0;
  145. //_nmea->loop();
  146. // if (millis() > next_gps_update) {
  147. // if (_nmea->isValid()) {
  148. // node_lat = ((double)_nmea->getLatitude())/1000000.;
  149. // node_lon = ((double)_nmea->getLongitude())/1000000.;
  150. // node_altitude = ((double)_nmea->getAltitude()) / 1000.0;
  151. // //Serial.printf("lat %f lon %f\r\n", _lat, _lon);
  152. // }
  153. // next_gps_update = millis() + 1000;
  154. //}
  155. }
  156. int me25ls01SensorManager::getNumSettings() const { return 1; } // just one supported: "gps" (power switch)
  157. const char* me25ls01SensorManager::getSettingName(int i) const {
  158. return i == 0 ? "gps" : NULL;
  159. }
  160. const char* me25ls01SensorManager::getSettingValue(int i) const {
  161. if (i == 0) {
  162. return gps_active ? "1" : "0";
  163. }
  164. return NULL;
  165. }
  166. bool me25ls01SensorManager::setSettingValue(const char* name, const char* value) {
  167. if (strcmp(name, "gps") == 0) {
  168. // if (strcmp(value, "0") == 0) {
  169. // sleep_gps(); // sleep for faster fix !
  170. // } else {
  171. // start_gps();
  172. // }
  173. return true;
  174. }
  175. return false; // not supported
  176. }