mirror of
https://github.com/meshtastic/firmware.git
synced 2025-02-01 02:09:57 +00:00
Update RAK2560 code (#5844)
* * Update RAK9154 sensor to tx remote power telemetry * remove uf2 script, pio run does that inline * move sensor module to correct position * disable LED and Accelerometer code on rak2560 * trunk fmt * mention epaper variant * attention, revert, revert * Enable Environment Telemetry of these values * fix float values
This commit is contained in:
parent
950341d1f9
commit
973b453d43
@ -87,7 +87,7 @@ MAX17048Sensor max17048Sensor;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if HAS_RAKPROT && !defined(ARCH_PORTDUINO)
|
||||
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && HAS_RAKPROT && !defined(ARCH_PORTDUINO)
|
||||
RAK9154Sensor rak9154Sensor;
|
||||
#endif
|
||||
|
||||
@ -243,7 +243,8 @@ class AnalogBatteryLevel : public HasBatteryLevel
|
||||
virtual uint16_t getBattVoltage() override
|
||||
{
|
||||
|
||||
#if defined(HAS_RAKPROT) && !defined(ARCH_PORTDUINO) && !defined(HAS_PMU)
|
||||
#if HAS_TELEMETRY && defined(HAS_RAKPROT) && !defined(ARCH_PORTDUINO) && !defined(HAS_PMU) && \
|
||||
!MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
|
||||
if (hasRAK()) {
|
||||
return getRAKVoltage();
|
||||
}
|
||||
@ -406,7 +407,8 @@ class AnalogBatteryLevel : public HasBatteryLevel
|
||||
/// we can't be smart enough to say 'full'?
|
||||
virtual bool isCharging() override
|
||||
{
|
||||
#if defined(HAS_RAKPROT) && !defined(ARCH_PORTDUINO) && !defined(HAS_PMU)
|
||||
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && defined(HAS_RAKPROT) && !defined(ARCH_PORTDUINO) && \
|
||||
!defined(HAS_PMU)
|
||||
if (hasRAK()) {
|
||||
return (rak9154Sensor.isCharging()) ? OptTrue : OptFalse;
|
||||
}
|
||||
@ -447,7 +449,7 @@ class AnalogBatteryLevel : public HasBatteryLevel
|
||||
float last_read_value = (OCV[NUM_OCV_POINTS - 1] * NUM_CELLS);
|
||||
uint32_t last_read_time_ms = 0;
|
||||
|
||||
#if defined(HAS_RAKPROT)
|
||||
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && defined(HAS_RAKPROT)
|
||||
|
||||
uint16_t getRAKVoltage() { return rak9154Sensor.getBusVoltageMv(); }
|
||||
|
||||
|
@ -163,6 +163,12 @@ int32_t EnvironmentTelemetryModule::runOnce()
|
||||
result = max17048Sensor.runOnce();
|
||||
if (cgRadSens.hasSensor())
|
||||
result = cgRadSens.runOnce();
|
||||
// this only works on the wismesh hub with the solar option. This is not an I2C sensor, so we don't need the
|
||||
// sensormap here.
|
||||
#ifdef HAS_RAKPROT
|
||||
|
||||
result = rak9154Sensor.runOnce();
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
return result;
|
||||
@ -480,6 +486,10 @@ bool EnvironmentTelemetryModule::getEnvironmentTelemetry(meshtastic_Telemetry *m
|
||||
valid = valid && cgRadSens.getMetrics(m);
|
||||
hasSensor = true;
|
||||
}
|
||||
#ifdef HAS_RAKPROT
|
||||
valid = valid && rak9154Sensor.getMetrics(m);
|
||||
hasSensor = true;
|
||||
#endif
|
||||
#endif
|
||||
return valid && hasSensor;
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ void PowerTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *s
|
||||
{
|
||||
display->setTextAlignment(TEXT_ALIGN_LEFT);
|
||||
display->setFont(FONT_SMALL);
|
||||
|
||||
|
||||
if (lastMeasurementPacket == nullptr) {
|
||||
// In case of no valid packet, display "Power Telemetry", "No measurement"
|
||||
display->drawString(x, y, "Power Telemetry");
|
||||
@ -121,23 +121,23 @@ void PowerTelemetryModule::drawFrame(OLEDDisplay *display, OLEDDisplayUiState *s
|
||||
}
|
||||
|
||||
// Display "Pow. From: ..."
|
||||
display->drawString(x, y, "Pow. From: " + String(lastSender) + "(" + String(agoSecs) + "s)");
|
||||
display->drawString(x, y, "Pow. From: " + String(lastSender) + "(" + String(agoSecs) + "s)");
|
||||
|
||||
// Display current and voltage based on ...power_metrics.has_[channel/voltage/current]... flags
|
||||
if (lastMeasurement.variant.power_metrics.has_ch1_voltage || lastMeasurement.variant.power_metrics.has_ch1_current) {
|
||||
display->drawString(x, y += _fontHeight(FONT_SMALL),
|
||||
"Ch1: " + String(lastMeasurement.variant.power_metrics.ch1_voltage, 2) +
|
||||
"V " + String(lastMeasurement.variant.power_metrics.ch1_current, 0) + "mA");
|
||||
"Ch1: " + String(lastMeasurement.variant.power_metrics.ch1_voltage, 2) + "V " +
|
||||
String(lastMeasurement.variant.power_metrics.ch1_current, 0) + "mA");
|
||||
}
|
||||
if (lastMeasurement.variant.power_metrics.has_ch2_voltage || lastMeasurement.variant.power_metrics.has_ch2_current) {
|
||||
display->drawString(x, y += _fontHeight(FONT_SMALL),
|
||||
"Ch2: " + String(lastMeasurement.variant.power_metrics.ch2_voltage, 2) +
|
||||
"V " + String(lastMeasurement.variant.power_metrics.ch2_current, 0) + "mA");
|
||||
"Ch2: " + String(lastMeasurement.variant.power_metrics.ch2_voltage, 2) + "V " +
|
||||
String(lastMeasurement.variant.power_metrics.ch2_current, 0) + "mA");
|
||||
}
|
||||
if (lastMeasurement.variant.power_metrics.has_ch3_voltage || lastMeasurement.variant.power_metrics.has_ch3_current) {
|
||||
display->drawString(x, y += _fontHeight(FONT_SMALL),
|
||||
"Ch3: " + String(lastMeasurement.variant.power_metrics.ch3_voltage, 2) +
|
||||
"V " + String(lastMeasurement.variant.power_metrics.ch3_current, 0) + "mA");
|
||||
"Ch3: " + String(lastMeasurement.variant.power_metrics.ch3_voltage, 2) + "V " +
|
||||
String(lastMeasurement.variant.power_metrics.ch3_current, 0) + "mA");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,10 @@
|
||||
#ifdef HAS_RAKPROT
|
||||
#include "../variants/rak2560/RAK9154Sensor.h"
|
||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||
#include "../modules/Telemetry/Sensor/TelemetrySensor.h"
|
||||
#include "configuration.h"
|
||||
|
||||
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && defined(HAS_RAKPROT)
|
||||
|
||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||
#include "RAK9154Sensor.h"
|
||||
#include "TelemetrySensor.h"
|
||||
#include "concurrency/Periodic.h"
|
||||
#include <RAK-OneWireSerial.h>
|
||||
|
||||
@ -25,6 +26,8 @@ static uint16_t dc_vol = 0;
|
||||
static uint8_t dc_prec = 0;
|
||||
static uint8_t provision = 0;
|
||||
|
||||
extern RAK9154Sensor rak9154Sensor;
|
||||
|
||||
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) {
|
||||
@ -78,6 +81,7 @@ static void onewire_evt(const uint8_t pid, const uint8_t sid, const SNHUBAPI_EVT
|
||||
default:
|
||||
break;
|
||||
}
|
||||
rak9154Sensor.setLastRead(millis());
|
||||
|
||||
break;
|
||||
case SNHUBAPI_EVT_REPORT:
|
||||
@ -106,6 +110,7 @@ static void onewire_evt(const uint8_t pid, const uint8_t sid, const SNHUBAPI_EVT
|
||||
default:
|
||||
break;
|
||||
}
|
||||
rak9154Sensor.setLastRead(millis());
|
||||
|
||||
break;
|
||||
|
||||
@ -145,15 +150,18 @@ static int32_t onewireHandle()
|
||||
|
||||
int32_t RAK9154Sensor::runOnce()
|
||||
{
|
||||
onewirePeriodic = new Periodic("onewireHandle", onewireHandle);
|
||||
if (!rak9154Sensor.isInitialized()) {
|
||||
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 DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||
}
|
||||
|
||||
void RAK9154Sensor::setup()
|
||||
@ -163,7 +171,16 @@ void RAK9154Sensor::setup()
|
||||
|
||||
bool RAK9154Sensor::getMetrics(meshtastic_Telemetry *measurement)
|
||||
{
|
||||
return true;
|
||||
if (getBusVoltageMv() > 0) {
|
||||
measurement->variant.environment_metrics.has_voltage = true;
|
||||
measurement->variant.environment_metrics.has_current = true;
|
||||
|
||||
measurement->variant.environment_metrics.voltage = (float)getBusVoltageMv() / 1000;
|
||||
measurement->variant.environment_metrics.current = (float)getCurrentMa() / 1000;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t RAK9154Sensor::getBusVoltageMv()
|
||||
@ -171,6 +188,11 @@ uint16_t RAK9154Sensor::getBusVoltageMv()
|
||||
return dc_vol;
|
||||
}
|
||||
|
||||
int16_t RAK9154Sensor::getCurrentMa()
|
||||
{
|
||||
return dc_cur;
|
||||
}
|
||||
|
||||
int RAK9154Sensor::getBusBatteryPercent()
|
||||
{
|
||||
return (int)dc_prec;
|
||||
@ -180,4 +202,8 @@ bool RAK9154Sensor::isCharging()
|
||||
{
|
||||
return (dc_cur > 0) ? true : false;
|
||||
}
|
||||
void RAK9154Sensor::setLastRead(uint32_t lastRead)
|
||||
{
|
||||
this->lastRead = lastRead;
|
||||
}
|
||||
#endif // HAS_RAKPROT
|
@ -1,23 +1,30 @@
|
||||
#ifdef HAS_RAKPROT
|
||||
#include "configuration.h"
|
||||
|
||||
#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && defined(HAS_RAKPROT)
|
||||
|
||||
#ifndef _RAK9154SENSOR_H
|
||||
#define _RAK9154SENSOR_H 1
|
||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||
#include "../modules/Telemetry/Sensor/TelemetrySensor.h"
|
||||
#include "../modules/Telemetry/Sensor/VoltageSensor.h"
|
||||
#include "CurrentSensor.h"
|
||||
#include "TelemetrySensor.h"
|
||||
#include "VoltageSensor.h"
|
||||
|
||||
class RAK9154Sensor : public TelemetrySensor, VoltageSensor
|
||||
class RAK9154Sensor : public TelemetrySensor, VoltageSensor, CurrentSensor
|
||||
{
|
||||
private:
|
||||
protected:
|
||||
virtual void setup() override;
|
||||
uint32_t lastRead = 0;
|
||||
|
||||
public:
|
||||
RAK9154Sensor();
|
||||
virtual int32_t runOnce() override;
|
||||
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
|
||||
virtual uint16_t getBusVoltageMv() override;
|
||||
virtual int16_t getCurrentMa() override;
|
||||
int getBusBatteryPercent();
|
||||
bool isCharging();
|
||||
void setLastRead(uint32_t lastRead);
|
||||
};
|
||||
#endif // _RAK9154SENSOR_H
|
||||
#endif // HAS_RAKPROT
|
@ -4,7 +4,7 @@
|
||||
|
||||
BMX160Sensor::BMX160Sensor(ScanI2C::FoundDevice foundDevice) : MotionSensor::MotionSensor(foundDevice) {}
|
||||
|
||||
#ifdef RAK_4631
|
||||
#if defined(RAK_4631) && !defined(RAK2560)
|
||||
#if !defined(MESHTASTIC_EXCLUDE_SCREEN)
|
||||
|
||||
// screen is defined in main.cpp
|
||||
|
@ -7,7 +7,7 @@
|
||||
|
||||
#if !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) && !MESHTASTIC_EXCLUDE_I2C
|
||||
|
||||
#ifdef RAK_4631
|
||||
#if defined(RAK_4631) && !defined(RAK2560)
|
||||
|
||||
#include "Fusion/Fusion.h"
|
||||
#include <Rak_BMX160.h>
|
||||
|
@ -1,5 +1,4 @@
|
||||
#pragma once
|
||||
#include "../variants/rak2560/RAK9154Sensor.h"
|
||||
#include "PowerStatus.h"
|
||||
#include "concurrency/OSThread.h"
|
||||
#include "configuration.h"
|
||||
@ -56,8 +55,8 @@ extern INA3221Sensor ina3221Sensor;
|
||||
extern MAX17048Sensor max17048Sensor;
|
||||
#endif
|
||||
|
||||
#if HAS_RAKPROT && !defined(ARCH_PORTDUINO)
|
||||
#include "../variants/rak2560/RAK9154Sensor.h"
|
||||
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && HAS_RAKPROT && !defined(ARCH_PORTDUINO)
|
||||
#include "modules/Telemetry/Sensor/RAK9154Sensor.h"
|
||||
extern RAK9154Sensor rak9154Sensor;
|
||||
#endif
|
||||
|
||||
|
@ -1,113 +0,0 @@
|
||||
import struct
|
||||
|
||||
Import("env") # noqa: F821
|
||||
|
||||
|
||||
# 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
|
||||
print("#########################################################")
|
||||
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:
|
||||
inpbuf = f.read()
|
||||
|
||||
outbuf = convert_from_hex_to_uf2(inpbuf.decode("utf-8"))
|
||||
|
||||
write_file(target, outbuf)
|
||||
print("#########################################################")
|
||||
print(target + " is ready to flash to target device")
|
||||
print("#########################################################")
|
||||
|
||||
|
||||
# Add callback after .hex file was created
|
||||
env.AddPostAction("$BUILD_DIR/${PROGNAME}.hex", create_uf2) # noqa: F821
|
||||
|
||||
# UF2 creation taken from uf2conv.py
|
||||
UF2_MAGIC_START0 = 0x0A324655 # "UF2\n"
|
||||
UF2_MAGIC_START1 = 0x9E5D5157 # Randomly selected
|
||||
UF2_MAGIC_END = 0x0AB16F30 # Ditto
|
||||
|
||||
familyid = 0xADA52840
|
||||
|
||||
|
||||
class Block:
|
||||
def __init__(self, addr):
|
||||
self.addr = addr
|
||||
self.bytes = bytearray(256)
|
||||
|
||||
def encode(self, blockno, numblocks):
|
||||
global familyid
|
||||
flags = 0x0
|
||||
if familyid:
|
||||
flags |= 0x2000
|
||||
hd = struct.pack(
|
||||
"<IIIIIIII",
|
||||
UF2_MAGIC_START0,
|
||||
UF2_MAGIC_START1,
|
||||
flags,
|
||||
self.addr,
|
||||
256,
|
||||
blockno,
|
||||
numblocks,
|
||||
familyid,
|
||||
)
|
||||
hd += self.bytes[0:256]
|
||||
while len(hd) < 512 - 4:
|
||||
hd += b"\x00"
|
||||
hd += struct.pack("<I", UF2_MAGIC_END)
|
||||
return hd
|
||||
|
||||
|
||||
def write_file(name, buf):
|
||||
with open(name, "wb") as f:
|
||||
f.write(buf)
|
||||
# print("Wrote %d bytes to %s." % (len(buf), name))
|
||||
|
||||
|
||||
def convert_from_hex_to_uf2(buf):
|
||||
global appstartaddr
|
||||
appstartaddr = None
|
||||
upper = 0
|
||||
currblock = None
|
||||
blocks = []
|
||||
for line in buf.split("\n"):
|
||||
if line[0] != ":":
|
||||
continue
|
||||
i = 1
|
||||
rec = []
|
||||
while i < len(line) - 1:
|
||||
rec.append(int(line[i : i + 2], 16))
|
||||
i += 2
|
||||
tp = rec[3]
|
||||
if tp == 4:
|
||||
upper = ((rec[4] << 8) | rec[5]) << 16
|
||||
elif tp == 2:
|
||||
upper = ((rec[4] << 8) | rec[5]) << 4
|
||||
assert (upper & 0xFFFF) == 0
|
||||
elif tp == 1:
|
||||
break
|
||||
elif tp == 0:
|
||||
addr = upper | (rec[1] << 8) | rec[2]
|
||||
if appstartaddr is None:
|
||||
appstartaddr = addr
|
||||
i = 4
|
||||
while i < len(rec) - 1:
|
||||
if not currblock or currblock.addr & ~0xFF != addr & ~0xFF:
|
||||
currblock = Block(addr & ~0xFF)
|
||||
blocks.append(currblock)
|
||||
currblock.bytes[addr & 0xFF] = rec[i]
|
||||
addr += 1
|
||||
i += 1
|
||||
numblocks = len(blocks)
|
||||
resfile = b""
|
||||
for i in range(0, numblocks):
|
||||
resfile += blocks[i].encode(i, numblocks)
|
||||
return resfile
|
@ -15,8 +15,6 @@ lib_deps =
|
||||
${nrf52840_base.lib_deps}
|
||||
${networking_base.lib_deps}
|
||||
melopero/Melopero RV3028@^1.1.0
|
||||
rakwireless/RAKwireless NCP5623 RGB LED library@^1.0.2
|
||||
beegee-tokyo/RAKwireless RAK12034@^1.0.0
|
||||
https://github.com/beegee-tokyo/RAK-OneWireSerial.git#0.0.2
|
||||
debug_tool = jlink
|
||||
; If not set we will default to uploading over serial (first it forces bootloader entry by talking 1200bps to cdcacm)
|
||||
|
Loading…
Reference in New Issue
Block a user