test sending sensor results over lora radio. Accelerometer and temp/pressure.
Serial terminal operates at 115200.
This project provides a text-based menu over serial port.
Operating the program only requires using the arrow keys, enter key to activate a control, or entering numbers.
Two sensors provided:
LIS12DH12
accelerometer operates in a continuous sampling mode. Enable control for accelerometer enables this continuous sampling, approx every 3 seconds.
LPS22HH temperature / pressure sensor operates as single shot, where pressing the control button on terminal causes single sample to be performed.
poll rate
control will enable repeated reading of pressure/temperature-sensor or photo-sensor when poll rate is greater than zero.
target must be: DISCO_L072CZ_LRWAN1
radio.h@2:972a5704f152, 2019-04-29 (annotated)
- Committer:
- Wayne Roberts
- Date:
- Mon Apr 29 13:54:35 2019 -0700
- Revision:
- 2:972a5704f152
- Parent:
- 0:e1e70da93044
add Ticker for polling photo-sensor and pressure/temp-sensor
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Wayne Roberts |
0:e1e70da93044 | 1 | #include "sx12xx.h" |
Wayne Roberts |
0:e1e70da93044 | 2 | |
Wayne Roberts |
0:e1e70da93044 | 3 | #ifdef SX127x_H |
Wayne Roberts |
0:e1e70da93044 | 4 | #include "sx127x_lora.h" |
Wayne Roberts |
0:e1e70da93044 | 5 | #include "sx127x_fsk.h" |
Wayne Roberts |
0:e1e70da93044 | 6 | #endif /* SX127x_H */ |
Wayne Roberts |
0:e1e70da93044 | 7 | |
Wayne Roberts |
0:e1e70da93044 | 8 | #define PA_OFF_DBM -127 |
Wayne Roberts |
0:e1e70da93044 | 9 | |
Wayne Roberts |
0:e1e70da93044 | 10 | typedef enum { |
Wayne Roberts |
0:e1e70da93044 | 11 | _READ_, |
Wayne Roberts |
0:e1e70da93044 | 12 | _WRITE_ |
Wayne Roberts |
0:e1e70da93044 | 13 | } action_e; |
Wayne Roberts |
0:e1e70da93044 | 14 | |
Wayne Roberts |
0:e1e70da93044 | 15 | typedef struct { |
Wayne Roberts |
0:e1e70da93044 | 16 | uint8_t row; |
Wayne Roberts |
0:e1e70da93044 | 17 | uint8_t col; |
Wayne Roberts |
0:e1e70da93044 | 18 | } pos_t; |
Wayne Roberts |
0:e1e70da93044 | 19 | |
Wayne Roberts |
0:e1e70da93044 | 20 | #define _ITEM_VALUE 0xbb |
Wayne Roberts |
0:e1e70da93044 | 21 | #define _ITEM_DROPDOWN 0xaa |
Wayne Roberts |
0:e1e70da93044 | 22 | #define _ITEM_BUTTON 0xcc |
Wayne Roberts |
0:e1e70da93044 | 23 | #define _ITEM_TOGGLE 0xdd |
Wayne Roberts |
0:e1e70da93044 | 24 | |
Wayne Roberts |
0:e1e70da93044 | 25 | typedef enum { |
Wayne Roberts |
0:e1e70da93044 | 26 | MENUMODE_NONE = 0, |
Wayne Roberts |
0:e1e70da93044 | 27 | MENUMODE_ENTRY, |
Wayne Roberts |
0:e1e70da93044 | 28 | MENUMODE_DROPDOWN, |
Wayne Roberts |
0:e1e70da93044 | 29 | MENUMODE_REDRAW, |
Wayne Roberts |
0:e1e70da93044 | 30 | MENUMODE_REINIT_MENU, |
Wayne Roberts |
0:e1e70da93044 | 31 | } menuMode_e; |
Wayne Roberts |
0:e1e70da93044 | 32 | |
Wayne Roberts |
0:e1e70da93044 | 33 | typedef struct { |
Wayne Roberts |
0:e1e70da93044 | 34 | uint8_t itemType; |
Wayne Roberts |
0:e1e70da93044 | 35 | |
Wayne Roberts |
0:e1e70da93044 | 36 | const char* const * printed_strs; // displayed values index from read callback return |
Wayne Roberts |
0:e1e70da93044 | 37 | const char* const * selectable_strs; // choices |
Wayne Roberts |
0:e1e70da93044 | 38 | |
Wayne Roberts |
0:e1e70da93044 | 39 | unsigned (*const read)(bool forWriting); |
Wayne Roberts |
0:e1e70da93044 | 40 | menuMode_e (*const write)(unsigned); |
Wayne Roberts |
0:e1e70da93044 | 41 | } dropdown_item_t; |
Wayne Roberts |
0:e1e70da93044 | 42 | |
Wayne Roberts |
0:e1e70da93044 | 43 | typedef struct { |
Wayne Roberts |
0:e1e70da93044 | 44 | uint8_t itemType; |
Wayne Roberts |
0:e1e70da93044 | 45 | |
Wayne Roberts |
0:e1e70da93044 | 46 | unsigned width; // num columns printed |
Wayne Roberts |
0:e1e70da93044 | 47 | |
Wayne Roberts |
0:e1e70da93044 | 48 | void (*const print)(void); |
Wayne Roberts |
0:e1e70da93044 | 49 | bool (*const write)(const char*); // NULL for read-only. return true: redraw menu |
Wayne Roberts |
0:e1e70da93044 | 50 | } value_item_t; |
Wayne Roberts |
0:e1e70da93044 | 51 | |
Wayne Roberts |
0:e1e70da93044 | 52 | typedef struct { |
Wayne Roberts |
0:e1e70da93044 | 53 | uint8_t itemType; |
Wayne Roberts |
0:e1e70da93044 | 54 | |
Wayne Roberts |
0:e1e70da93044 | 55 | const char * const label; |
Wayne Roberts |
0:e1e70da93044 | 56 | void (*const push)(void); |
Wayne Roberts |
0:e1e70da93044 | 57 | } button_item_t; |
Wayne Roberts |
0:e1e70da93044 | 58 | |
Wayne Roberts |
0:e1e70da93044 | 59 | typedef struct { |
Wayne Roberts |
0:e1e70da93044 | 60 | uint8_t itemType; |
Wayne Roberts |
0:e1e70da93044 | 61 | |
Wayne Roberts |
0:e1e70da93044 | 62 | const char * const label0; |
Wayne Roberts |
0:e1e70da93044 | 63 | const char * const label1; |
Wayne Roberts |
0:e1e70da93044 | 64 | bool (*const read)(void); |
Wayne Roberts |
0:e1e70da93044 | 65 | bool (*const push)(void); |
Wayne Roberts |
0:e1e70da93044 | 66 | } toggle_item_t; |
Wayne Roberts |
0:e1e70da93044 | 67 | |
Wayne Roberts |
0:e1e70da93044 | 68 | #define FLAG_MSGTYPE_ALL 0x07 |
Wayne Roberts |
0:e1e70da93044 | 69 | #define FLAG_MSGTYPE_PKT 0x01 |
Wayne Roberts |
0:e1e70da93044 | 70 | #define FLAG_MSGTYPE_PER 0x02 |
Wayne Roberts |
0:e1e70da93044 | 71 | #define FLAG_MSGTYPE_PING 0x04 |
Wayne Roberts |
0:e1e70da93044 | 72 | |
Wayne Roberts |
0:e1e70da93044 | 73 | typedef struct { |
Wayne Roberts |
0:e1e70da93044 | 74 | pos_t pos; // on screen position, both row & col with 1 starting value |
Wayne Roberts |
0:e1e70da93044 | 75 | const char* const label; |
Wayne Roberts |
0:e1e70da93044 | 76 | |
Wayne Roberts |
0:e1e70da93044 | 77 | const void* const itemPtr; |
Wayne Roberts |
0:e1e70da93044 | 78 | |
Wayne Roberts |
0:e1e70da93044 | 79 | uint8_t flags; |
Wayne Roberts |
0:e1e70da93044 | 80 | |
Wayne Roberts |
0:e1e70da93044 | 81 | const void* refreshReadItem; |
Wayne Roberts |
0:e1e70da93044 | 82 | } menu_t; |
Wayne Roberts |
0:e1e70da93044 | 83 | #define FIRST_CHIP_MENU_ROW 3 |
Wayne Roberts |
0:e1e70da93044 | 84 | |
Wayne Roberts |
0:e1e70da93044 | 85 | |
Wayne Roberts |
0:e1e70da93044 | 86 | typedef struct { |
Wayne Roberts |
0:e1e70da93044 | 87 | menuMode_e mode; |
Wayne Roberts |
0:e1e70da93044 | 88 | uint8_t sel_idx; |
Wayne Roberts |
0:e1e70da93044 | 89 | const menu_t* sm; |
Wayne Roberts |
0:e1e70da93044 | 90 | uint8_t dropdown_col; |
Wayne Roberts |
0:e1e70da93044 | 91 | } menuState_t; |
Wayne Roberts |
0:e1e70da93044 | 92 | |
Wayne Roberts |
0:e1e70da93044 | 93 | extern menuState_t menuState; |
Wayne Roberts |
0:e1e70da93044 | 94 | #define MAX_MENU_COLUMNS 6 |
Wayne Roberts |
0:e1e70da93044 | 95 | extern menu_t* menu[][MAX_MENU_COLUMNS]; |
Wayne Roberts |
0:e1e70da93044 | 96 | extern int8_t StopMenuCols[]; |
Wayne Roberts |
0:e1e70da93044 | 97 | |
Wayne Roberts |
0:e1e70da93044 | 98 | extern uint8_t entry_buf_idx; |
Wayne Roberts |
0:e1e70da93044 | 99 | extern char entry_buf[]; |
Wayne Roberts |
0:e1e70da93044 | 100 | |
Wayne Roberts |
0:e1e70da93044 | 101 | void log_printf(const char* format, ...); |
Wayne Roberts |
0:e1e70da93044 | 102 | |
Wayne Roberts |
0:e1e70da93044 | 103 | typedef struct |
Wayne Roberts |
0:e1e70da93044 | 104 | { |
Wayne Roberts |
0:e1e70da93044 | 105 | void (*const TxDone_botHalf)(void); // read irqAt for timestamp of interrupt |
Wayne Roberts |
0:e1e70da93044 | 106 | void (*const RxDone)(uint8_t size, float rssi, float snr); // read radio.rx_buf for payload, irqAt for timestamp of interrupt |
Wayne Roberts |
0:e1e70da93044 | 107 | } RadioEvents_t; |
Wayne Roberts |
0:e1e70da93044 | 108 | |
Wayne Roberts |
0:e1e70da93044 | 109 | class Radio { |
Wayne Roberts |
0:e1e70da93044 | 110 | public: |
Wayne Roberts |
0:e1e70da93044 | 111 | static const char* const chipNum_str; |
Wayne Roberts |
0:e1e70da93044 | 112 | |
Wayne Roberts |
0:e1e70da93044 | 113 | static void boardInit(const RadioEvents_t* e); |
Wayne Roberts |
0:e1e70da93044 | 114 | static void hw_reset(void); |
Wayne Roberts |
0:e1e70da93044 | 115 | static void clearIrqFlags(void); |
Wayne Roberts |
0:e1e70da93044 | 116 | static void readChip(void); |
Wayne Roberts |
0:e1e70da93044 | 117 | static void tx_carrier(void); |
Wayne Roberts |
0:e1e70da93044 | 118 | static void tx_preamble(void); |
Wayne Roberts |
0:e1e70da93044 | 119 | static void txPkt(void); |
Wayne Roberts |
0:e1e70da93044 | 120 | static void Rx(void); |
Wayne Roberts |
0:e1e70da93044 | 121 | static void setFS(void); |
Wayne Roberts |
0:e1e70da93044 | 122 | |
Wayne Roberts |
0:e1e70da93044 | 123 | static const value_item_t tx_dbm_item; |
Wayne Roberts |
0:e1e70da93044 | 124 | |
Wayne Roberts |
0:e1e70da93044 | 125 | static const menu_t* get_modem_menu(void); |
Wayne Roberts |
0:e1e70da93044 | 126 | static const menu_t* get_modem_sub_menu(void); |
Wayne Roberts |
0:e1e70da93044 | 127 | |
Wayne Roberts |
0:e1e70da93044 | 128 | static unsigned pktType_read(bool); |
Wayne Roberts |
0:e1e70da93044 | 129 | static menuMode_e pktType_write(unsigned); |
Wayne Roberts |
0:e1e70da93044 | 130 | static const char* const pktType_strs[]; |
Wayne Roberts |
0:e1e70da93044 | 131 | |
Wayne Roberts |
0:e1e70da93044 | 132 | static void tx_dbm_print(void); |
Wayne Roberts |
0:e1e70da93044 | 133 | static bool tx_dbm_write(const char*); |
Wayne Roberts |
0:e1e70da93044 | 134 | |
Wayne Roberts |
0:e1e70da93044 | 135 | static unsigned tx_ramp_read(bool); |
Wayne Roberts |
0:e1e70da93044 | 136 | static menuMode_e tx_ramp_write(unsigned); |
Wayne Roberts |
0:e1e70da93044 | 137 | static const char* tx_ramp_strs[]; |
Wayne Roberts |
0:e1e70da93044 | 138 | |
Wayne Roberts |
0:e1e70da93044 | 139 | static const char* const opmode_status_strs[]; |
Wayne Roberts |
0:e1e70da93044 | 140 | static const char* const opmode_select_strs[]; |
Wayne Roberts |
0:e1e70da93044 | 141 | static unsigned opmode_read(bool); |
Wayne Roberts |
0:e1e70da93044 | 142 | static menuMode_e opmode_write(unsigned); |
Wayne Roberts |
0:e1e70da93044 | 143 | |
Wayne Roberts |
0:e1e70da93044 | 144 | static uint8_t get_payload_length(void); |
Wayne Roberts |
0:e1e70da93044 | 145 | static void set_payload_length(uint8_t); |
Wayne Roberts |
0:e1e70da93044 | 146 | |
Wayne Roberts |
0:e1e70da93044 | 147 | static void tx_payload_length_print(void); |
Wayne Roberts |
0:e1e70da93044 | 148 | static bool tx_payload_length_write(const char*); |
Wayne Roberts |
0:e1e70da93044 | 149 | #ifdef SX127x_H |
Wayne Roberts |
0:e1e70da93044 | 150 | static SX127x radio; |
Wayne Roberts |
0:e1e70da93044 | 151 | static SX127x_lora lora; |
Wayne Roberts |
0:e1e70da93044 | 152 | static SX127x_fsk fsk; |
Wayne Roberts |
0:e1e70da93044 | 153 | static void rfsw_callback(void); |
Wayne Roberts |
0:e1e70da93044 | 154 | static void ocp(uint8_t ma); |
Wayne Roberts |
0:e1e70da93044 | 155 | static InterruptIn dio0; |
Wayne Roberts |
0:e1e70da93044 | 156 | static InterruptIn dio1; |
Wayne Roberts |
0:e1e70da93044 | 157 | #elif defined(SX126x_H) |
Wayne Roberts |
0:e1e70da93044 | 158 | static SX126x radio; |
Wayne Roberts |
0:e1e70da93044 | 159 | static ModulationParams_t mpFSK, mpLORA; |
Wayne Roberts |
0:e1e70da93044 | 160 | static PacketParams_t ppFSK, ppLORA; |
Wayne Roberts |
0:e1e70da93044 | 161 | #elif defined(SX128x_H) |
Wayne Roberts |
0:e1e70da93044 | 162 | static SX128x radio; |
Wayne Roberts |
0:e1e70da93044 | 163 | static uint8_t tx_param_buf[]; |
Wayne Roberts |
0:e1e70da93044 | 164 | static ModulationParams_t mpFLRC, mpBLE_GFSK, mpLORA; |
Wayne Roberts |
0:e1e70da93044 | 165 | static PacketParams_t ppGFSK, ppFLRC, ppLORA, ppBLE; |
Wayne Roberts |
0:e1e70da93044 | 166 | #else |
Wayne Roberts |
0:e1e70da93044 | 167 | #error import radio driver library |
Wayne Roberts |
0:e1e70da93044 | 168 | #endif |
Wayne Roberts |
0:e1e70da93044 | 169 | static bool service(int8_t); |
Wayne Roberts |
0:e1e70da93044 | 170 | static const menu_t common_menu[]; |
Wayne Roberts |
0:e1e70da93044 | 171 | |
Wayne Roberts |
0:e1e70da93044 | 172 | static void test(void); |
Wayne Roberts |
0:e1e70da93044 | 173 | |
Wayne Roberts |
0:e1e70da93044 | 174 | static unsigned read_register(unsigned); |
Wayne Roberts |
0:e1e70da93044 | 175 | static void write_register(unsigned, unsigned); |
Wayne Roberts |
0:e1e70da93044 | 176 | |
Wayne Roberts |
0:e1e70da93044 | 177 | private: |
Wayne Roberts |
0:e1e70da93044 | 178 | static const RadioEvents_t* RadioEvents; |
Wayne Roberts |
0:e1e70da93044 | 179 | |
Wayne Roberts |
0:e1e70da93044 | 180 | static void txDoneBottom(void); |
Wayne Roberts |
0:e1e70da93044 | 181 | |
Wayne Roberts |
0:e1e70da93044 | 182 | static const menu_t lora_menu[]; |
Wayne Roberts |
0:e1e70da93044 | 183 | |
Wayne Roberts |
0:e1e70da93044 | 184 | static LowPowerTimer lpt; |
Wayne Roberts |
0:e1e70da93044 | 185 | |
Wayne Roberts |
0:e1e70da93044 | 186 | #if defined(SX128x_H) |
Wayne Roberts |
0:e1e70da93044 | 187 | #include "radio_sx128x_private.h" |
Wayne Roberts |
0:e1e70da93044 | 188 | #elif defined(SX127x_H) |
Wayne Roberts |
0:e1e70da93044 | 189 | #include "radio_sx127x_private.h" |
Wayne Roberts |
0:e1e70da93044 | 190 | #elif defined(SX126x_H) |
Wayne Roberts |
0:e1e70da93044 | 191 | #include "radio_sx126x_private.h" |
Wayne Roberts |
0:e1e70da93044 | 192 | #endif |
Wayne Roberts |
0:e1e70da93044 | 193 | }; |
Wayne Roberts |
0:e1e70da93044 | 194 | |
Wayne Roberts |
0:e1e70da93044 | 195 | extern RawSerial pc; |
Wayne Roberts |
0:e1e70da93044 | 196 |