target.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <Arduino.h>
  2. #include "target.h"
  3. #include <helpers/ArduinoHelpers.h>
  4. GAT562EVBProBoard board;
  5. #ifndef PIN_USER_BTN
  6. #define PIN_USER_BTN (-1)
  7. #endif
  8. #ifdef DISPLAY_CLASS
  9. DISPLAY_CLASS display;
  10. MomentaryButton user_btn(PIN_USER_BTN, 1000, true, false, false);
  11. MomentaryButton back_btn(PIN_BACK_BTN, 1000, true, false, true);
  12. #endif
  13. RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
  14. WRAPPER_CLASS radio_driver(radio, board);
  15. VolatileRTCClock fallback_clock;
  16. AutoDiscoverRTCClock rtc_clock(fallback_clock);
  17. #if ENV_INCLUDE_GPS
  18. #include <helpers/sensors/MicroNMEALocationProvider.h>
  19. MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, &rtc_clock);
  20. EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
  21. #else
  22. EnvironmentSensorManager sensors;
  23. #endif
  24. bool radio_init() {
  25. rtc_clock.begin(Wire);
  26. return radio.std_init(&SPI);
  27. }
  28. uint32_t radio_get_rng_seed() {
  29. return radio.random(0x7FFFFFFF);
  30. }
  31. void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
  32. radio.setFrequency(freq);
  33. radio.setSpreadingFactor(sf);
  34. radio.setBandwidth(bw);
  35. radio.setCodingRate(cr);
  36. }
  37. void radio_set_tx_power(int8_t dbm) {
  38. radio.setOutputPower(dbm);
  39. }
  40. mesh::LocalIdentity radio_new_identity() {
  41. RadioNoiseListener rng(radio);
  42. return mesh::LocalIdentity(&rng); // create new random identity
  43. }