target.cpp 1.3 KB

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