|
| 1 | +#include <Arduino.h> |
| 2 | +#include "target.h" |
| 3 | +#include <helpers/ArduinoHelpers.h> |
| 4 | +#include <helpers/sensors/LocationProvider.h> |
| 5 | + |
| 6 | +class WM1110LocationProvider : public LocationProvider { |
| 7 | +public: |
| 8 | + long getLatitude() override { return 0; } |
| 9 | + long getLongitude() override { return 0; } |
| 10 | + long getAltitude() override { return 0; } |
| 11 | + long satellitesCount() override { return 0; } |
| 12 | + bool isValid() override { return false; } |
| 13 | + long getTimestamp() override { return 0; } |
| 14 | + void sendSentence(const char* sentence) override {} |
| 15 | + void reset() override {} |
| 16 | + void begin() override {} |
| 17 | + void stop() override {} |
| 18 | + void loop() override {} |
| 19 | + bool isEnabled() override { return false; } |
| 20 | +}; |
| 21 | + |
| 22 | +WioWM1110Board board; |
| 23 | + |
| 24 | +RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI); |
| 25 | + |
| 26 | +WRAPPER_CLASS radio_driver(radio, board); |
| 27 | + |
| 28 | +VolatileRTCClock rtc_clock; |
| 29 | +WM1110LocationProvider location_provider; |
| 30 | +EnvironmentSensorManager sensors(location_provider); |
| 31 | + |
| 32 | +#ifndef LORA_CR |
| 33 | + #define LORA_CR 5 |
| 34 | +#endif |
| 35 | + |
| 36 | +#ifdef RF_SWITCH_TABLE |
| 37 | +static const uint32_t rfswitch_dios[Module::RFSWITCH_MAX_PINS] = { |
| 38 | + RADIOLIB_LR11X0_DIO5, |
| 39 | + RADIOLIB_LR11X0_DIO6, |
| 40 | + RADIOLIB_LR11X0_DIO7, |
| 41 | + RADIOLIB_LR11X0_DIO8, |
| 42 | + RADIOLIB_NC |
| 43 | +}; |
| 44 | + |
| 45 | +static const Module::RfSwitchMode_t rfswitch_table[] = { |
| 46 | + // mode DIO5 DIO6 DIO7 DIO8 |
| 47 | + { LR11x0::MODE_STBY, {LOW, LOW, LOW, LOW }}, |
| 48 | + { LR11x0::MODE_RX, {HIGH, LOW, LOW, HIGH }}, |
| 49 | + { LR11x0::MODE_TX, {HIGH, HIGH, LOW, HIGH }}, |
| 50 | + { LR11x0::MODE_TX_HP, {LOW, HIGH, LOW, HIGH }}, |
| 51 | + { LR11x0::MODE_TX_HF, {LOW, LOW, LOW, LOW }}, |
| 52 | + { LR11x0::MODE_GNSS, {LOW, LOW, HIGH, LOW }}, |
| 53 | + { LR11x0::MODE_WIFI, {LOW, LOW, LOW, LOW }}, |
| 54 | + END_OF_MODE_TABLE, |
| 55 | +}; |
| 56 | +#endif |
| 57 | + |
| 58 | +bool radio_init() { |
| 59 | + board.enableSensorPower(true); |
| 60 | + |
| 61 | +#ifdef LR11X0_DIO3_TCXO_VOLTAGE |
| 62 | + float tcxo = LR11X0_DIO3_TCXO_VOLTAGE; |
| 63 | +#else |
| 64 | + float tcxo = 1.8f; |
| 65 | +#endif |
| 66 | + |
| 67 | + SPI.setPins(P_LORA_MISO, P_LORA_SCLK, P_LORA_MOSI); |
| 68 | + SPI.begin(); |
| 69 | + |
| 70 | + int status = radio.begin(LORA_FREQ, LORA_BW, LORA_SF, LORA_CR, RADIOLIB_LR11X0_LORA_SYNC_WORD_PRIVATE, LORA_TX_POWER, 16, tcxo); |
| 71 | + if (status != RADIOLIB_ERR_NONE) { |
| 72 | + Serial.print("ERROR: radio init failed: "); |
| 73 | + Serial.println(status); |
| 74 | + return false; // fail |
| 75 | + } |
| 76 | + |
| 77 | + radio.setCRC(2); |
| 78 | + radio.explicitHeader(); |
| 79 | + |
| 80 | +#ifdef RF_SWITCH_TABLE |
| 81 | + radio.setRfSwitchTable(rfswitch_dios, rfswitch_table); |
| 82 | +#endif |
| 83 | + |
| 84 | +#ifdef RX_BOOSTED_GAIN |
| 85 | + radio.setRxBoostedGainMode(RX_BOOSTED_GAIN); |
| 86 | +#endif |
| 87 | + |
| 88 | + return true; // success |
| 89 | +} |
| 90 | + |
| 91 | +uint32_t radio_get_rng_seed() { |
| 92 | + return radio.random(0x7FFFFFFF); |
| 93 | +} |
| 94 | + |
| 95 | +void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) { |
| 96 | + radio.setFrequency(freq); |
| 97 | + radio.setSpreadingFactor(sf); |
| 98 | + radio.setBandwidth(bw); |
| 99 | + radio.setCodingRate(cr); |
| 100 | +} |
| 101 | + |
| 102 | +void radio_set_tx_power(uint8_t dbm) { |
| 103 | + radio.setOutputPower(dbm); |
| 104 | +} |
| 105 | + |
| 106 | +mesh::LocalIdentity radio_new_identity() { |
| 107 | + RadioNoiseListener rng(radio); |
| 108 | + return mesh::LocalIdentity(&rng); // create new random identity |
| 109 | +} |
| 110 | + |
0 commit comments