target.cpp 1.2 KB

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