From ceb884cf1827ac13205b1bc605c42cced4d5a95e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20G=C3=B6ttgens?= Date: Sun, 16 Jun 2024 16:29:45 +0200 Subject: [PATCH] trunk fmt --- src/Power.cpp | 36 ++--- src/power.h | 40 +++--- variants/rak2560/RAK9154Sensor.cpp | 214 ++++++++++++++--------------- variants/rak2560/create_uf2.py | 35 +++-- variants/rak4631/variant.h | 103 +++++++------- 5 files changed, 214 insertions(+), 214 deletions(-) diff --git a/src/Power.cpp b/src/Power.cpp index 18dbfebe4..18a527cee 100644 --- a/src/Power.cpp +++ b/src/Power.cpp @@ -351,19 +351,19 @@ class AnalogBatteryLevel : public HasBatteryLevel virtual bool isVbusIn() override { #ifdef EXT_PWR_DETECT - #ifdef HELTEC_CAPSULE_SENSOR_V3 - // if external powered that pin will be pulled down - if (digitalRead(EXT_PWR_DETECT) == LOW) { - return true; - } - // if it's not LOW - check the battery - #else - // if external powered that pin will be pulled up - if (digitalRead(EXT_PWR_DETECT) == HIGH) { - return true; - } - // if it's not HIGH - check the battery - #endif +#ifdef HELTEC_CAPSULE_SENSOR_V3 + // if external powered that pin will be pulled down + if (digitalRead(EXT_PWR_DETECT) == LOW) { + return true; + } + // if it's not LOW - check the battery +#else + // if external powered that pin will be pulled up + if (digitalRead(EXT_PWR_DETECT) == HIGH) { + return true; + } + // if it's not HIGH - check the battery +#endif #endif return getBattVoltage() > chargingVolt; } @@ -461,11 +461,11 @@ Power::Power() : OSThread("Power") bool Power::analogInit() { #ifdef EXT_PWR_DETECT - #ifdef HELTEC_CAPSULE_SENSOR_V3 - pinMode(EXT_PWR_DETECT, INPUT_PULLUP); - #else - pinMode(EXT_PWR_DETECT, INPUT); - #endif +#ifdef HELTEC_CAPSULE_SENSOR_V3 + pinMode(EXT_PWR_DETECT, INPUT_PULLUP); +#else + pinMode(EXT_PWR_DETECT, INPUT); +#endif #endif #ifdef EXT_CHRG_DETECT pinMode(EXT_CHRG_DETECT, ext_chrg_detect_mode); diff --git a/src/power.h b/src/power.h index c343a45eb..b970dfeaf 100644 --- a/src/power.h +++ b/src/power.h @@ -1,8 +1,8 @@ #pragma once +#include "../variants/rak2560/RAK9154Sensor.h" #include "PowerStatus.h" #include "concurrency/OSThread.h" #include "configuration.h" -#include "../variants/rak2560/RAK9154Sensor.h" #ifdef ARCH_ESP32 #include @@ -56,31 +56,31 @@ extern RAK9154Sensor rak9154Sensor; class Power : private concurrency::OSThread { -public: - Observable newStatus; + public: + Observable newStatus; - Power(); + Power(); - void shutdown(); - void readPowerStatus(); - virtual bool setup(); - virtual int32_t runOnce() override; - void setStatusHandler(meshtastic::PowerStatus *handler) { statusHandler = handler; } - const uint16_t OCV[11] = {OCV_ARRAY}; + void shutdown(); + void readPowerStatus(); + virtual bool setup(); + virtual int32_t runOnce() override; + void setStatusHandler(meshtastic::PowerStatus *handler) { statusHandler = handler; } + const uint16_t OCV[11] = {OCV_ARRAY}; -protected: - meshtastic::PowerStatus *statusHandler; + protected: + meshtastic::PowerStatus *statusHandler; - /// Setup a xpowers chip axp192/axp2101, return true if found - bool axpChipInit(); - /// Setup a simple ADC input based battery sensor - bool analogInit(); + /// Setup a xpowers chip axp192/axp2101, return true if found + bool axpChipInit(); + /// Setup a simple ADC input based battery sensor + bool analogInit(); -private: - // open circuit voltage lookup table - uint8_t low_voltage_counter; + private: + // open circuit voltage lookup table + uint8_t low_voltage_counter; #ifdef DEBUG_HEAP - uint32_t lastheap; + uint32_t lastheap; #endif }; diff --git a/variants/rak2560/RAK9154Sensor.cpp b/variants/rak2560/RAK9154Sensor.cpp index 15a172c18..9f660947e 100644 --- a/variants/rak2560/RAK9154Sensor.cpp +++ b/variants/rak2560/RAK9154Sensor.cpp @@ -4,8 +4,8 @@ #include "../modules/Telemetry/Sensor/TelemetrySensor.h" #include "configuration.h" -#include #include "concurrency/Periodic.h" +#include using namespace concurrency; @@ -27,165 +27,157 @@ static uint8_t provision = 0; static void onewire_evt(const uint8_t pid, const uint8_t sid, const SNHUBAPI_EVT_E eid, uint8_t *msg, uint16_t len) { - switch (eid) - { - case SNHUBAPI_EVT_RECV_REQ: - case SNHUBAPI_EVT_RECV_RSP: - break; + switch (eid) { + case SNHUBAPI_EVT_RECV_REQ: + case SNHUBAPI_EVT_RECV_RSP: + break; - case SNHUBAPI_EVT_QSEND: - mySerial.write(msg, len); - break; + case SNHUBAPI_EVT_QSEND: + mySerial.write(msg, len); + break; - case SNHUBAPI_EVT_ADD_SID: - // LOG_INFO("+ADD:SID:[%02x]\r\n", msg[0]); - break; + case SNHUBAPI_EVT_ADD_SID: + // LOG_INFO("+ADD:SID:[%02x]\r\n", msg[0]); + break; - case SNHUBAPI_EVT_ADD_PID: - // LOG_INFO("+ADD:PID:[%02x]\r\n", msg[0]); + case SNHUBAPI_EVT_ADD_PID: + // LOG_INFO("+ADD:PID:[%02x]\r\n", msg[0]); #ifdef BOOT_DATA_REQ - provision = msg[0]; + provision = msg[0]; #endif - break; + break; - case SNHUBAPI_EVT_GET_INTV: - break; + case SNHUBAPI_EVT_GET_INTV: + break; - case SNHUBAPI_EVT_GET_ENABLE: - break; + case SNHUBAPI_EVT_GET_ENABLE: + break; - case SNHUBAPI_EVT_SDATA_REQ: + case SNHUBAPI_EVT_SDATA_REQ: - // LOG_INFO("+EVT:PID[%02x],IPSO[%02x]\r\n",pid,msg[0]); - // for( uint16_t i=1; i 100) - { - dc_prec = 100; - } - break; - case RAK_IPSO_DC_CURRENT: - dc_cur = (msg[2] << 8) + msg[1]; - break; - case RAK_IPSO_DC_VOLTAGE: - dc_vol = (msg[2] << 8) + msg[1]; - dc_vol *= 10; - break; - default: - break; - } + // LOG_INFO("+EVT:PID[%02x],IPSO[%02x]\r\n",pid,msg[0]); + // for( uint16_t i=1; i 100) { + dc_prec = 100; + } + break; + case RAK_IPSO_DC_CURRENT: + dc_cur = (msg[2] << 8) + msg[1]; + break; + case RAK_IPSO_DC_VOLTAGE: + dc_vol = (msg[2] << 8) + msg[1]; + dc_vol *= 10; + break; + default: + break; + } - break; - case SNHUBAPI_EVT_REPORT: + break; + case SNHUBAPI_EVT_REPORT: - // LOG_INFO("+EVT:PID[%02x],IPSO[%02x]\r\n",pid,msg[0]); - // for( uint16_t i=1; i 100) - { - dc_prec = 100; - } - break; - case RAK_IPSO_DC_CURRENT: - dc_cur = (msg[1] << 8) + msg[2]; - break; - case RAK_IPSO_DC_VOLTAGE: - dc_vol = (msg[1] << 8) + msg[2]; - dc_vol *= 10; - break; - default: - break; - } + switch (msg[0]) { + case RAK_IPSO_CAPACITY: + dc_prec = msg[1]; + if (dc_prec > 100) { + dc_prec = 100; + } + break; + case RAK_IPSO_DC_CURRENT: + dc_cur = (msg[1] << 8) + msg[2]; + break; + case RAK_IPSO_DC_VOLTAGE: + dc_vol = (msg[1] << 8) + msg[2]; + dc_vol *= 10; + break; + default: + break; + } - break; + break; - case SNHUBAPI_EVT_CHKSUM_ERR: - LOG_INFO("+ERR:CHKSUM\r\n"); - break; + case SNHUBAPI_EVT_CHKSUM_ERR: + LOG_INFO("+ERR:CHKSUM\r\n"); + break; - case SNHUBAPI_EVT_SEQ_ERR: - LOG_INFO("+ERR:SEQUCE\r\n"); - break; + case SNHUBAPI_EVT_SEQ_ERR: + LOG_INFO("+ERR:SEQUCE\r\n"); + break; - default: - break; - } + default: + break; + } } static int32_t onewireHandle() { - if (provision != 0) - { - RakSNHub_Protocl_API.get.data(provision); - provision = 0; - } + if (provision != 0) { + RakSNHub_Protocl_API.get.data(provision); + provision = 0; + } - while (mySerial.available()) - { - char a = mySerial.read(); - buff[bufflen++] = a; - delay(2); // continue data, timeout=2ms - } + while (mySerial.available()) { + char a = mySerial.read(); + buff[bufflen++] = a; + delay(2); // continue data, timeout=2ms + } - if (bufflen != 0) - { - RakSNHub_Protocl_API.process((uint8_t *)buff, bufflen); - bufflen = 0; - } + if (bufflen != 0) { + RakSNHub_Protocl_API.process((uint8_t *)buff, bufflen); + bufflen = 0; + } - return 50; + return 50; } int32_t RAK9154Sensor::runOnce() { - onewirePeriodic = new Periodic("onewireHandle", onewireHandle); + onewirePeriodic = new Periodic("onewireHandle", onewireHandle); - mySerial.begin(9600); + mySerial.begin(9600); - RakSNHub_Protocl_API.init(onewire_evt); + RakSNHub_Protocl_API.init(onewire_evt); - status = true; - initialized = true; - return 0; + status = true; + initialized = true; + return 0; } void RAK9154Sensor::setup() { - // Set up oversampling and filter initialization + // Set up oversampling and filter initialization } bool RAK9154Sensor::getMetrics(meshtastic_Telemetry *measurement) { - return true; + return true; } uint16_t RAK9154Sensor::getBusVoltageMv() { - return dc_vol; + return dc_vol; } int RAK9154Sensor::getBusBatteryPercent() { - return (int)dc_prec; + return (int)dc_prec; } bool RAK9154Sensor::isCharging() { - return (dc_cur > 0) ? true : false; + return (dc_cur > 0) ? true : false; } #endif // HAS_RAKPROT \ No newline at end of file diff --git a/variants/rak2560/create_uf2.py b/variants/rak2560/create_uf2.py index d14eaea02..cf6b11606 100644 --- a/variants/rak2560/create_uf2.py +++ b/variants/rak2560/create_uf2.py @@ -1,22 +1,23 @@ -import sys import struct +import sys Import("env") + # Parse input and create UF2 file def create_uf2(source, target, env): # source_hex = target[0].get_abspath() source_hex = target[0].get_string(False) - source_hex = '.\\'+source_hex + source_hex = ".\\" + source_hex print("#########################################################") - print("Create UF2 from "+source_hex) + print("Create UF2 from " + source_hex) print("#########################################################") # print("Source: " + source_hex) target = source_hex.replace(".hex", "") target = target + ".uf2" # print("Target: " + target) - with open(source_hex, mode='rb') as f: + with open(source_hex, mode="rb") as f: inpbuf = f.read() outbuf = convert_from_hex_to_uf2(inpbuf.decode("utf-8")) @@ -48,9 +49,17 @@ class Block: flags = 0x0 if familyid: flags |= 0x2000 - hd = struct.pack(" nRF52840 - IO1 <-> P0.17 (Arduino GPIO number 17) - IO2 <-> P1.02 (Arduino GPIO number 34) - IO3 <-> P0.21 (Arduino GPIO number 21) - IO4 <-> P0.04 (Arduino GPIO number 4) - IO5 <-> P0.09 (Arduino GPIO number 9) - IO6 <-> P0.10 (Arduino GPIO number 10) - IO7 <-> P0.28 (Arduino GPIO number 28) - SW1 <-> P0.01 (Arduino GPIO number 1) - A0 <-> P0.04/AIN2 (Arduino Analog A2 - A1 <-> P0.31/AIN7 (Arduino Analog A7 - SPI_CS <-> P0.26 (Arduino GPIO number 26) - */ +/* @note RAK5005-O GPIO mapping to RAK4631 GPIO ports + RAK5005-O <-> nRF52840 + IO1 <-> P0.17 (Arduino GPIO number 17) + IO2 <-> P1.02 (Arduino GPIO number 34) + IO3 <-> P0.21 (Arduino GPIO number 21) + IO4 <-> P0.04 (Arduino GPIO number 4) + IO5 <-> P0.09 (Arduino GPIO number 9) + IO6 <-> P0.10 (Arduino GPIO number 10) + IO7 <-> P0.28 (Arduino GPIO number 28) + SW1 <-> P0.01 (Arduino GPIO number 1) + A0 <-> P0.04/AIN2 (Arduino Analog A2 + A1 <-> P0.31/AIN7 (Arduino Analog A7 + SPI_CS <-> P0.26 (Arduino GPIO number 26) + */ - // RAK4630 LoRa module +// RAK4630 LoRa module - /* Setup of the SX1262 LoRa module ( https://docs.rakwireless.com/Product-Categories/WisBlock/RAK4631/Datasheet/ ) +/* Setup of the SX1262 LoRa module ( https://docs.rakwireless.com/Product-Categories/WisBlock/RAK4631/Datasheet/ ) - P1.10 NSS SPI NSS (Arduino GPIO number 42) - P1.11 SCK SPI CLK (Arduino GPIO number 43) - P1.12 MOSI SPI MOSI (Arduino GPIO number 44) - P1.13 MISO SPI MISO (Arduino GPIO number 45) - P1.14 BUSY BUSY signal (Arduino GPIO number 46) - P1.15 DIO1 DIO1 event interrupt (Arduino GPIO number 47) - P1.06 NRESET NRESET manual reset of the SX1262 (Arduino GPIO number 38) +P1.10 NSS SPI NSS (Arduino GPIO number 42) +P1.11 SCK SPI CLK (Arduino GPIO number 43) +P1.12 MOSI SPI MOSI (Arduino GPIO number 44) +P1.13 MISO SPI MISO (Arduino GPIO number 45) +P1.14 BUSY BUSY signal (Arduino GPIO number 46) +P1.15 DIO1 DIO1 event interrupt (Arduino GPIO number 47) +P1.06 NRESET NRESET manual reset of the SX1262 (Arduino GPIO number 38) - Important for successful SX1262 initialization: +Important for successful SX1262 initialization: - * Setup DIO2 to control the antenna switch - * Setup DIO3 to control the TCXO power supply - * Setup the SX1262 to use it's DCDC regulator and not the LDO - * RAK4630 schematics show GPIO P1.07 connected to the antenna switch, but it should not be initialized, as DIO2 will do the - control of the antenna switch +* Setup DIO2 to control the antenna switch +* Setup DIO3 to control the TCXO power supply +* Setup the SX1262 to use it's DCDC regulator and not the LDO +* RAK4630 schematics show GPIO P1.07 connected to the antenna switch, but it should not be initialized, as DIO2 will do the +control of the antenna switch - SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG +SO GPIO 39/TXEN MAY NOT BE DEFINED FOR SUCCESSFUL OPERATION OF THE SX1262 - TG - */ +*/ #define DETECTION_SENSOR_EN 4