Rework Debugging Macros to also Work in Libraries (#6)
Co-authored-by: Stefan Brand <seiichiro@seiichiro0185.org> Reviewed-on: https://www.seiichiro0185.org/git/attnode/v3_firmware/pulls/6 Co-authored-by: seiichiro <seiichiro@seiichiro0185.org> Co-committed-by: seiichiro <seiichiro@seiichiro0185.org>
This commit is contained in:
parent
c862eec6d0
commit
34d8c92281
15 changed files with 45 additions and 15 deletions
|
@ -16,6 +16,15 @@ Before programming a node, copy src/config.h.example to src/config.h and set the
|
|||
|
||||
Programming is done using a [MicroUPDI Programmer](https://github.com/MCUdude/microUPDI), settings in platformio.ini are set to use it. For other pogrammer options see the PlatformIO Documentation
|
||||
|
||||
## Debugging
|
||||
|
||||
The firmware has the ability to produce some debug output via the Serial UART as long as there is no sensor using the UART. To enable it, uncomment the line -D DEBUG in platformio.ini. This will produce some debug output showing the state of the node. The following macros are available as a replacement for the normal Serial.print and Serial.println functions:
|
||||
|
||||
DEBUG_PRINT("Debug Output");
|
||||
DEBUG_PRINTLN("Debug Output with Linebreak");
|
||||
|
||||
These will only produce additional code in the firmware when the DEBUG-Flag is enabled, and will be entirely removed in the ouput binary if not. The macros work like the normal Serial.print* statements form the standard arduino functions.
|
||||
|
||||
## Payload Decoder
|
||||
|
||||
You need to specify a Payload Decoder fitting for your configured Sensors for a Node. See payload/index.html in this repository. Open it in your Browser of Choice and select the enabled sensors. It will generate the Payload Decoder fitting for the choosen Sensors. You can also use the Online Version at [attno.de](https://www.attno.de/payload-generator)
|
||||
|
|
|
@ -5,8 +5,6 @@ DebugUtils.h - Simple debugging utilities.
|
|||
#ifndef DEBUGUTILS_H
|
||||
#define DEBUGUTILS_H
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#ifdef DEBUG
|
||||
#define DEBUG_PRINT(...) Serial.print(__VA_ARGS__); Serial.flush();
|
||||
#define DEBUG_PRINTLN(...) Serial.println(__VA_ARGS__); Serial.flush();
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
BME280::BME280() {}
|
||||
|
||||
void BME280::getCalData() {
|
||||
DEBUG_PRINTLN("BME280::getCalData");
|
||||
dig_T1 = read16_LE(0x88);
|
||||
dig_T2 = readS16_LE(0x8A);
|
||||
dig_T3 = readS16_LE(0x8C);
|
||||
|
@ -82,6 +83,8 @@ uint8_t BME280::getSensorData(char *payload, uint8_t startbyte) {
|
|||
int32_t UP, UT, UH;
|
||||
int32_t rawP, rawT;
|
||||
|
||||
DEBUG_PRINTLN("BME280::geSensorData");
|
||||
|
||||
// Trigger Measurement
|
||||
// Set Sensor Config
|
||||
write8(0xF2, 0b00000001); // 1x Oversampling for Humidity
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
#define BME280_H
|
||||
|
||||
#include "../../include/attsensor.h"
|
||||
#include "../../include/debug.h"
|
||||
|
||||
#define BME280_I2CADDR 0x76
|
||||
|
||||
|
|
|
@ -50,6 +50,7 @@ DS18B20::DS18B20(uint8_t owpin, uint8_t resbits = 12, bool para = false) {
|
|||
}
|
||||
|
||||
void DS18B20::initialize(void){
|
||||
DEBUG_PRINTLN("DS18B20::initialize");
|
||||
onewire->reset();
|
||||
onewire->reset_search();
|
||||
sensorcount = 0;
|
||||
|
@ -84,6 +85,8 @@ uint8_t DS18B20::getSensorData(char *payload, uint8_t startbyte){
|
|||
uint8_t data[9];
|
||||
int16_t value;
|
||||
|
||||
DEBUG_PRINTLN("DS18B20::getSensorData");
|
||||
|
||||
// Start Conversation on all Sensors
|
||||
onewire->reset();
|
||||
onewire->skip();
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#define DS18B20_H
|
||||
|
||||
#include "../../include/attsensor.h"
|
||||
#include "../../include/debug.h"
|
||||
#include <OneWire.h>
|
||||
|
||||
// Sensor Resolutions
|
||||
|
|
|
@ -35,6 +35,8 @@ HM330x::HM330x() {};
|
|||
// Initialize the Sensor
|
||||
void HM330x::initialize(void) {
|
||||
uint8_t retryCount = 0;
|
||||
|
||||
DEBUG_PRINTLN("HM330x::initialize");
|
||||
// Send select command
|
||||
while (!sendCmd(HM330x_SELECT)) {
|
||||
if (retryCount++ >= 0) {
|
||||
|
@ -50,6 +52,8 @@ uint8_t HM330x::getSensorData(char *payload, uint8_t startbyte) {
|
|||
uint8_t data[HM330x_DATA_LEN] = {0};
|
||||
uint16_t value = 0;
|
||||
|
||||
DEBUG_PRINTLN("HM330x::getSensorData");
|
||||
|
||||
// Initialize Payload with 0s
|
||||
for (uint8_t i=startbyte; i < startbyte+6; i++)
|
||||
payload[i] = 0;
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#define HM330x_H
|
||||
|
||||
#include "../../include/attsensor.h"
|
||||
#include "../../include/debug.h"
|
||||
|
||||
// Sensor I2C Address
|
||||
#define HM330x_ADDR 0x40
|
||||
|
|
|
@ -41,6 +41,8 @@ SCD30::SCD30(uint8_t interval, bool selfcalib) {
|
|||
// Initialize the Sensor, Enable Constant Measurement, Set Autocalibration and Interval
|
||||
void SCD30::initialize(void) {
|
||||
uint8_t fw[3];
|
||||
|
||||
DEBUG_PRINTLN("SCD30::initialize");
|
||||
// Soft Reset
|
||||
reset();
|
||||
// Send Get Firmware, Workaround to Avoid First Real Command to be Ignored
|
||||
|
@ -63,6 +65,9 @@ void SCD30::initialize(void) {
|
|||
uint8_t SCD30::getSensorData(char *payload, uint8_t startbyte) {
|
||||
uint8_t ready[2] = {0};
|
||||
uint8_t data[18] = {0};
|
||||
|
||||
DEBUG_PRINTLN("SCD30::getSensorData");
|
||||
|
||||
// Check if Sensor Data is Available
|
||||
getBytes(SCD30_DATA_READY, ready, 2);
|
||||
if (ready[1] == 1){
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#define SCD30_H
|
||||
|
||||
#include "../../include/attsensor.h"
|
||||
#include "../../include/debug.h"
|
||||
|
||||
// Sensor I2C Address
|
||||
#define SCD30_ADDR 0x61
|
||||
|
|
|
@ -53,6 +53,8 @@ uint16_t SHT21::sensorRead(uint8_t command) {
|
|||
}
|
||||
|
||||
uint8_t SHT21::getSensorData(char *payload, uint8_t startbyte) {
|
||||
DEBUG_PRINTLN("SHT21::getSensorData");
|
||||
|
||||
// Temperature
|
||||
int32ToPayload((int32_t)((-46.85 + 175.72 / 65536.0 * (float)(sensorRead(SHT21_TEMPHOLD)))*100), payload, startbyte);
|
||||
// Humidity
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#define SHT21_H
|
||||
|
||||
#include "../../include/attsensor.h"
|
||||
#include "../../include/debug.h"
|
||||
|
||||
#define SHT21_I2CADDR 0x40
|
||||
|
||||
|
|
|
@ -24,13 +24,20 @@ board_hardware.bod = disabled
|
|||
monitor_speed = 115200
|
||||
monitor_port = /dev/ttyACM1
|
||||
|
||||
## LMIC Config via Build Flags ##
|
||||
## LMIC Config and Debug Mode via Build Flags ##
|
||||
#**************************************************************************************************************************
|
||||
# Uncomment -D DEBUG to enable Serial Debugging. Parameters for the Serial Port are 115200 Baud 8n1
|
||||
# By default the Firmware will output some messages about LoRa-Status and indicate sending
|
||||
# The Macros DEBUG_PRINT() and DEBUG_PRINTLN() can be used to produce debug output depending on this define
|
||||
# Please be aware that this will not work when a Serial Sensor like the SG112A/MH-Z19C or Sensair S8 ist used
|
||||
#*************************************************************************************************************************/
|
||||
build_flags =
|
||||
-D CFG_eu868
|
||||
-D CFG_sx1276_radio
|
||||
-D DISABLE_PING
|
||||
-D DISABLE_BEACONS
|
||||
-D ARDUINO_LMIC_PROJECT_CONFIG_H_SUPPRESS
|
||||
# -D DEBUG
|
||||
|
||||
## Programmer Config (MicroUPDI) ##
|
||||
upload_port = usb
|
||||
|
|
|
@ -26,15 +26,6 @@
|
|||
*************************************************************************************************************************/
|
||||
// #define BTN_PIN PIN_PC2
|
||||
|
||||
/**************************************************************************************************************************
|
||||
* Enable Serial Debugging. Parameters for the Serial Port are 115200 Baud 8n1
|
||||
* By default the Firmware will output some messages about LoRa-Status and indicate sending
|
||||
* The Macros DEBUG_PRINT() and DEBUG_PRINTLN() can be used to produce debug output depending on this define
|
||||
* Please be aware that this will not work when a Serial Sensor like the SG112A/MH-Z19C or Sensair S8 ist used
|
||||
*************************************************************************************************************************/
|
||||
// #define DEBUG
|
||||
|
||||
|
||||
/**************************************************************************************************************************
|
||||
* Number of active Sensors (used as long as HAS_NO_SENSOR is not enabled)
|
||||
* Set to the correct number of enabled sensors below
|
||||
|
|
|
@ -13,8 +13,8 @@
|
|||
|
||||
// Include Config and Helpers
|
||||
#include "config.h"
|
||||
#include "debug.h"
|
||||
#include "attsensor.h"
|
||||
#include <debug.h>
|
||||
#include <attsensor.h>
|
||||
|
||||
// Include All Sensors Activated in config.h
|
||||
#ifndef HAS_NO_SENSOR
|
||||
|
@ -189,11 +189,14 @@ void onEvent(ev_t ev) {
|
|||
}
|
||||
|
||||
// Got to sleep for specified Time
|
||||
DEBUG_PRINTLN("Going to Sleep");
|
||||
DEBUG_PRINT("Going to Sleep for ");
|
||||
DEBUG_PRINT(sleep_time*64);
|
||||
DEBUG_PRINTLN(" Seconds");
|
||||
for (uint16_t i = 0; i < sleep_time*2; i++) {
|
||||
// Cancel sleep Cycle if Button was Pressed
|
||||
#ifdef BTN_PIN
|
||||
if (btn_pressed && digitalRead(BTN_PIN) == HIGH) {
|
||||
DEBUG_PRINTLN("Button Pressed, waking up");
|
||||
i = sleep_time*2;
|
||||
btn_pressed = 0;
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue