Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update RAK2560 code #5844

Merged
merged 6 commits into from
Jan 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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(); }

Expand Down
10 changes: 10 additions & 0 deletions src/modules/Telemetry/EnvironmentTelemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 8 additions & 8 deletions src/modules/Telemetry/PowerTelemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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>

Expand All @@ -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) {
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}

status = true;
initialized = true;
return 0;
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
}

void RAK9154Sensor::setup()
Expand All @@ -163,14 +171,28 @@ 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()
{
return dc_vol;
}

int16_t RAK9154Sensor::getCurrentMa()
{
return dc_cur;
}

int RAK9154Sensor::getBusBatteryPercent()
{
return (int)dc_prec;
Expand All @@ -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
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion src/motion/BMX160Sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/motion/BMX160Sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
5 changes: 2 additions & 3 deletions src/power.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#pragma once
#include "../variants/rak2560/RAK9154Sensor.h"
#include "PowerStatus.h"
#include "concurrency/OSThread.h"
#include "configuration.h"
Expand Down Expand Up @@ -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

Expand Down
113 changes: 0 additions & 113 deletions variants/rak2560/create_uf2.py

This file was deleted.

2 changes: 0 additions & 2 deletions variants/rak2560/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Loading