target.cpp 1.5 KB

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