141 #include "em_device.h" 164 #define WAKE_UP_PERIOD_S 180 // On buoy: 1800 167 #define STORM_INTERRUPTS 8 170 #define ADXL_THRESHOLD 7 173 #define ADXL_RANGE ADXL_RANGE_8G 176 #define ADXL_ODR ADXL_ODR_12_5_HZ 181 #define LED_ENABLED 0 207 #if DEBUG_DBPRINT == 1 220 #if DEBUG_DBPRINT == 1 240 bool stormDetected =
false;
243 bool firstBoot =
true;
246 uint32_t remainingSleeptime = 0;
259 #if DEBUG_DBPRINT == 1 260 #if CUSTOM_BOARD == 1 262 dbwarn(
"CUSTOM board pinout selected");
265 dbwarn(
"REGULAR board pinout selected");
320 #if DEBUG_DBPRINT == 1 345 #if DEBUG_DBPRINT == 1 358 if (firstBoot && (data.
index > 0))
361 #if DEBUG_DBPRINT == 1 362 dbwarn(
"Sending first measurements ...");
394 #if DEBUG_DBPRINT == 1 420 #if DEBUG_DBPRINT == 1 421 dbwarnInt(
"STORM DETECTED! Sending ", data.
index,
" measurement(s) ...");
437 stormDetected =
true;
471 remainingSleeptime = 0;
482 remainingSleeptime = 0;
500 #if DEBUG_DBPRINT == 1 511 stormDetected =
false;
bool checkBTNinterrupts(void)
Method to check if any interrupts are triggered by buttons.
void initADC(ADC_Measurement_t peripheral)
Method to initialize the ADC to later check the battery voltage or internal temperature.
void dbprintln(char *message)
Print a string (char array) to USARTx and go to the next line.
void dbinfoInt(char *message1, int32_t value, char *message2)
Print an info value surrounded by two strings (char array) to USARTx.
void SVC_Handler(void)
SVC interrupt service routine.
bool checkCable(MeasurementData_t data)
Method to check if the wire is broken.
void ADXL_readValues(void)
Read and display "g" values forever with a 100ms interval.
All code for the ADXL362 accelerometer.
bool ADXL_getTriggered(void)
Getter for the ADXL_triggered variable.
Definitions of the custom data-types used.
void ADXL_configODR(ADXL_ODR_t givenODR)
Configure the Output Data Rate (ODR).
void dbwarn(char *message)
Print a warning string (char array) in yellow to USARTx and go to the next line.
void ADXL_clearCounter(void)
Method to set the ADXL_triggercounter variable back to zero.
void dbwarnInt(char *message1, int32_t value, char *message2)
Print a warning value surrounded by two strings (char array) to USARTx.
void BTN_setTriggered(uint8_t number, bool value)
Setter for the PB0_triggered and PB1_triggered variable.
void sendStormDetected(bool stormDetected)
Send a packet to the cloud using LoRaWAN to indicate that a storm has been detected.
uint16_t ADXL_getCounter(void)
Getter for the ADXL_triggercounter variable.
void ADXL_enableMeasure(bool enabled)
Enable or disable measurement mode.
ADC functionality for reading the (battery) voltage and internal temperature.
bool BTN_getTriggered(uint8_t number)
Getter for the PB0_triggered and PB1_triggered variables.
void testADXL(void)
This method goes through all of the ODR settings to see the influence they have on power usage...
void initADXL(void)
Initialize the accelerometer.
void ADXL_enableSPI(bool enabled)
Enable or disable the SPI pins and USART0/1 clock and peripheral to the accelerometer.
Cable checking functionality.
void PendSV_Handler(void)
PendSV interrupt service routine.
void error(uint8_t number)
Error method.
void sendMeasurements(MeasurementData_t data)
Send measured battery voltages and internal and external temperatures to the cloud using LoRaWAN...
void ADXL_ackInterrupt(void)
Acknowledge the interrupt from the accelerometer.
uint32_t RTC_getPassedSleeptime(void)
Method to get the time spend sleeping (in seconds) in the case of GPIO wake-up.
void disableLoRaWAN(void)
Disable LoRaWAN functionality.
void initGPIOwakeup(void)
Initialize GPIO wake-up functionality.
The pin definitions for the regular and custom Happy Gecko board.
void initLoRaWAN(void)
Initialize LoRaWAN functionality.
void dbprint_INIT(USART_TypeDef *pointer, uint8_t location, bool vcom, bool interrupts)
Initialize USARTx.
void sendStatus(uint8_t status)
Send a packet to indicate a status.
void RTC_clearWakeup(void)
Method to clear RTC_sleep_wakeup.
Enable or disable printing to UART with dbprint.
void delay(uint32_t msDelay)
Wait for a certain amount of milliseconds in EM2/3.
void ADXL_configRange(ADXL_Range_t givenRange)
Configure the measurement range and store the selected one in a global variable for later (internal) ...
void ADXL_configActivity(uint8_t gThreshold)
Configure the accelerometer to work in (referenced) activity threshold mode.
static MCU_State_t MCUstate
enum mcu_states MCU_State_t
int32_t readADC(ADC_Measurement_t peripheral)
Method to read the battery voltage or internal temperature.
void HardFault_Handler(void)
HardFault interrupt service routine.
void NMI_Handler(void)
NMI interrupt service routine.
bool RTC_checkWakeup(void)
Method to check if the wakeup was caused by the RTC.
void dbprintln_color(char *message, dbprint_color_t color)
Print a string (char array) to USARTx in a given color and go to the next line.
void sleep(uint32_t sSleep)
Sleep for a certain amount of seconds in EM2/3.
int main(void)
Main function.
void led(bool enabled)
Enable or disable the LED.
int32_t readTempDS18B20(void)
Get a temperature value from the DS18B20.
All code for the DS18B20 temperature sensor.