Rename MeshPocket V2 board and targets with Heltec prefix

This commit is contained in:
Quency-D committed 2026-11-16 10:26:39 +08:00
1 parent a72a75cd08
commit d6cd80e0e6
12 files changed
+42 -42

No files matched your search

@@ -0,0 +1,94 @@
#include "HeltecMeshPocketV2Board.h"
#include "PowerBankPage.h"
#include <helpers/ui/BoardUiExtension.h>
#include <helpers/ui/MomentaryButton.h>
#include <nrf_gpio.h>
class HeltecMeshPocketV2Board::UiExtension : public mesh::BoardUiExtension {
HeltecMeshPocketV2Board& board;
PowerBankPage page;
MomentaryButton secondaryButton;
public:
explicit UiExtension(HeltecMeshPocketV2Board& board) :
board(board), secondaryButton(PIN_BUTTON2, 1000, true, true, false) {}
void begin() {
secondaryButton.begin();
}
uint8_t pollEvents() override {
uint8_t events = EVENT_NONE;
const int buttonEvent = secondaryButton.check();
if (buttonEvent == BUTTON_EVENT_CLICK) {
events |= EVENT_SHOW_PAGE;
}
#ifdef MESHPOCKET_V2_USB_SWITCHABLE
else if (buttonEvent == BUTTON_EVENT_LONG_PRESS) {
events |= EVENT_PAGE_ACTION;
}
#endif
if (board.powerBank.takePageEvent()) events |= EVENT_REQUEST_FOCUS;
return events;
}
#ifdef MESHPOCKET_V2_USB_SWITCHABLE
void handlePageAction() override {
board.toggleUsbData();
}
#endif
uint32_t render(DisplayDriver& display, bool fullRefresh) override {
if (fullRefresh) page.invalidate();
display.setNativePixels(true);
page.draw(display, board.powerBank.snapshot(), board.isUsbDataEnabled());
display.setNativePixels(false);
return 500;
}
};
void HeltecMeshPocketV2Board::begin() {
NRF52Board::begin();
powerBank.begin();
pinMode(PIN_USER_BTN, INPUT_PULLUP);
uiExtension().begin();
}
HeltecMeshPocketV2Board::UiExtension& HeltecMeshPocketV2Board::uiExtension() {
static UiExtension extension(*this);
return extension;
}
mesh::BoardUiExtension* HeltecMeshPocketV2Board::getUiExtension() {
return &uiExtension();
}
uint16_t HeltecMeshPocketV2Board::getBattMilliVolts() {
const auto& status = powerBank.snapshot();
if (status.cw.ready) return status.cw.voltageMv;
return status.hltLive() ? status.hlt.batteryMv : 0;
}
void HeltecMeshPocketV2Board::setUsbDataEnabled(bool enabled) {
digitalWrite(PIN_IO_CSA, enabled ? HIGH : LOW);
}
bool HeltecMeshPocketV2Board::toggleUsbData() {
const bool enabled = !isUsbDataEnabled();
setUsbDataEnabled(enabled);
return enabled;
}
bool HeltecMeshPocketV2Board::isUsbDataEnabled() const {
return digitalRead(PIN_IO_CSA) == HIGH;
}
void HeltecMeshPocketV2Board::shutdownPeripherals() {
NRF52Board::shutdownPeripherals();
powerBank.end();
nrf_gpio_cfg_sense_input(PIN_USER_BTN, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW);
pinMode(PIN_9006_IO1, INPUT_PULLDOWN);
// A held-high IO1 must not immediately wake the board from SYSTEM OFF.
const auto sense = digitalRead(PIN_9006_IO1) ? NRF_GPIO_PIN_SENSE_LOW : NRF_GPIO_PIN_SENSE_HIGH;
nrf_gpio_cfg_sense_input(PIN_9006_IO1, NRF_GPIO_PIN_PULLDOWN, sense);
}
@@ -0,0 +1,25 @@
#pragma once
#include <helpers/NRF52Board.h>
#include "PowerBank.h"
class HeltecMeshPocketV2Board : public NRF52Board {
public:
HeltecMeshPocketV2Board() : NRF52Board("MeshPocket_V2_OTA") {}
PowerBank powerBank;
void begin() override;
void loop() override { powerBank.poll(); }
uint16_t getBattMilliVolts() override;
bool isChargerActive() override { return powerBank.snapshot().hasChargingInput(); }
bool hasChargerStatus() const override { return true; }
mesh::BoardUiExtension* getUiExtension() override;
bool toggleUsbData();
bool isUsbDataEnabled() const;
const char* getManufacturerName() const override { return "Heltec MeshPocket V2"; }
void shutdownPeripherals() override;
private:
class UiExtension;
UiExtension& uiExtension();
void setUsbDataEnabled(bool enabled);
};
+115
View File
@@ -0,0 +1,115 @@
#include "PowerBank.h"
namespace {
constexpr uint32_t hltPollMs = 100;
constexpr uint32_t hltStatusMs = 500;
constexpr uint32_t hltStaleMs = 3000;
constexpr uint32_t io1WindowMs = 120;
constexpr uint32_t gaugeNormalMs = 3000;
constexpr uint32_t gaugeFastMs = 500;
// Only the ISR writes this counter. The main loop consumes a single aligned read.
volatile uint32_t io1Pulses = 0;
void onIo1Rise() {
++io1Pulses;
}
bool stateChanged(const HLT331Serial::Status& before, const HLT331Serial::Status& after) {
return !before.valid || before.systemWorking != after.systemWorking ||
(after.systemWorking &&
(before.charging != after.charging || before.c1State != after.c1State ||
before.c2State != after.c2State || before.wirelessWork != after.wirelessWork ||
before.wirelessFull != after.wirelessFull));
}
}
bool PowerBankSnapshot::hltLive() const {
return hlt.valid && hlt.systemWorking && uint32_t(millis() - hlt.lastFrameMs) <= hltStaleMs;
}
bool PowerBankSnapshot::hasChargingInput() const {
return hltLive() && (hlt.charging || hlt.c1State == HLT331Serial::PORT_CHARGING ||
hlt.c2State == HLT331Serial::PORT_CHARGING);
}
void PowerBank::begin() {
gaugeStarted = gauge.begin(Wire);
if (gaugeStarted) readGauge();
hltStarted = hlt.begin(Serial2, PIN_SERIAL2_RX, PIN_SERIAL2_TX);
if (hltStarted) {
hlt.configurePins(PIN_CW_INT, PIN_9006_IO1, PIN_9006_IO2, -1);
attachInterrupt(digitalPinToInterrupt(PIN_9006_IO1), onIo1Rise, RISING);
readHlt();
}
// Capture the boot sample as a baseline before the UI starts.
pageEvent = false;
}
void PowerBank::updateFault(bool& sourceFault, bool active) {
const bool wasFault = cwFault || hltFault;
sourceFault = active;
if (wasFault != (cwFault || hltFault)) {
pageEvent = true;
fastGaugeReads = 3;
}
}
void PowerBank::readGauge() {
status.cw.ready = gauge.readStatus(status.cw);
lastGauge = millis();
if (fastGaugeReads) --fastGaugeReads;
if (status.cw.ready) updateFault(cwFault, !status.cw.profile.matches);
}
void PowerBank::readHlt() {
const bool valid = hlt.readStatus(status.hlt);
lastHlt = millis();
if (!valid || status.hlt.ageMs > hltStaleMs) return;
const auto& sample = status.hlt;
if (sample.systemWorking) updateFault(hltFault, sample.ntcOverTemp || sample.wirelessFod);
if (stateChanged(previous, sample)) {
pageEvent = true;
fastGaugeReads = 3;
}
previous = sample;
}
void PowerBank::poll() {
const uint32_t now = millis();
if (hltStarted && now - lastPoll >= hltPollMs) {
lastPoll = now;
hlt.poll();
}
const uint32_t pulses = io1Pulses;
if (pulses != seenPulses) {
seenPulses = pulses;
drainStarted = now;
draining = true;
fastGaugeReads = 3;
}
if (draining && now - drainStarted >= io1WindowMs) {
// Collect any bytes received since the regular UART poll.
hlt.poll();
readHlt();
pageEvent = true;
draining = false;
} else if (hltStarted && !draining && now - lastHlt >= hltStatusMs) {
readHlt();
}
const uint32_t interval = fastGaugeReads ? gaugeFastMs : gaugeNormalMs;
if (gaugeStarted && now - lastGauge >= interval) readGauge();
}
bool PowerBank::takePageEvent() {
const bool pending = pageEvent;
pageEvent = false;
return pending;
}
void PowerBank::end() {
if (hltStarted) {
detachInterrupt(digitalPinToInterrupt(PIN_9006_IO1));
Serial2.end();
}
}
+43
View File
@@ -0,0 +1,43 @@
#pragma once
#include <CW221X.h>
#include <HLT331Serial.h>
struct PowerBankSnapshot {
CW221X::Status cw{};
HLT331Serial::Status hlt{};
bool hltLive() const;
bool hasChargingInput() const;
};
class PowerBank {
public:
void begin();
void poll();
void end();
const PowerBankSnapshot& snapshot() const { return status; }
bool takePageEvent();
private:
void readGauge();
void readHlt();
void updateFault(bool& sourceFault, bool active);
CW221X gauge;
HLT331Serial hlt;
PowerBankSnapshot status;
HLT331Serial::Status previous{};
bool gaugeStarted = false;
bool hltStarted = false;
bool cwFault = false;
bool hltFault = false;
bool pageEvent = false;
bool draining = false;
uint8_t fastGaugeReads = 0;
uint32_t seenPulses = 0;
uint32_t drainStarted = 0;
uint32_t lastPoll = 0;
uint32_t lastHlt = 0;
uint32_t lastGauge = 0;
};
@@ -0,0 +1,334 @@
#include "PowerBankPage.h"
#include "PowerBank.h"
namespace {
constexpr ColorVal background = 0x0063;
constexpr ColorVal blue = 0x653d;
constexpr ColorVal purple = 0x611f;
constexpr ColorVal card = 0xdefc;
constexpr ColorVal dark = 0x31c8;
constexpr ColorVal white = 0xffff;
constexpr ColorVal green = 0x06ae;
constexpr ColorVal gold = 0xff0e;
constexpr ColorVal red = 0xfa69;
constexpr ColorVal off = 0x3a6b;
constexpr ColorVal well = 0x1127, shine = 0x47d5, track = 0x94b8;
constexpr ColorVal badgeFace = 0xffbf, tempFace = 0xf776, tempInk = 0xa465;
constexpr ColorVal divider = 0x9515, lightDivider = 0xd71e, boltInk = 0x93ba;
constexpr int temperatureCenterX = 134;
void label(DisplayDriver& d, int x, int y, const char* value, ColorVal ink, int size = 1) {
d.setColor(ink);
d.setTextSize(size);
d.setCursor(x, y);
d.print(value);
}
void panel(DisplayDriver& d, int x, int y, int w, int h, ColorVal color, int r = 6) {
d.setColor(color);
if (h > 2 * r) d.fillRect(x, y + r, w, h - 2 * r);
int span = 0;
for (int row = 0; row < r; ++row) {
int dy = r - row;
while ((span + 1) * (span + 1) + dy * dy <= r * (r + 1)) ++span;
int inset = r - span;
d.fillRect(x + inset, y + row, w - 2 * inset, 1);
d.fillRect(x + inset, y + h - 1 - row, w - 2 * inset, 1);
}
}
void drawPortCard(DisplayDriver& d, int x, const char* name) {
panel(d, x, 72, 70, 54, card);
label(d, x + 5, 78, name, dark, 2);
d.setColor(divider);
d.fillRect(x + 5, 97, 60, 1);
}
void drawUsbConnector(DisplayDriver& d, int x, ColorVal ink) {
panel(d, x + 33, 82, 25, 10, ink, 4);
panel(d, x + 34, 83, 23, 8, card, 3);
d.setColor(ink);
d.fillRect(x + 38, 87, 15, 1);
}
void drawUsbCard(DisplayDriver& d, int x, const char* name) {
drawPortCard(d, x, name);
drawUsbConnector(d, x, dark);
}
void drawLayout(DisplayDriver& d) {
d.startFrame(background);
panel(d, 2, 2, 164, 66, blue);
label(d, 8, 10, "Battery", white);
panel(d, 89, 23, 4, 9, white, 1);
panel(d, 49, 16, 40, 23, white, 4);
panel(d, 50, 17, 38, 21, well, 3);
d.setColor(white);
d.fillRect(8, 50, 85, 8);
d.setColor(track);
d.fillRect(9, 51, 83, 6);
d.setColor(white);
for (int i = 1; i < 10; ++i) d.fillRect(9 + i * 83 / 10, 51, 1, 6);
d.setColor(lightDivider);
d.fillRect(8, 44, 85, 1);
d.fillRect(101, 9, 1, 51);
panel(d, temperatureCenterX - 11, 13, 23, 23, badgeFace, 11);
panel(d, temperatureCenterX - 8, 16, 17, 17, tempFace, 8);
label(d, temperatureCenterX - 2, 21, "T", tempInk);
panel(d, 169, 2, 49, 66, purple);
panel(d, 182, 13, 23, 23, badgeFace, 11);
drawUsbCard(d, 2, "C1");
drawUsbCard(d, 75, "C2");
drawPortCard(d, 148, "Qi2");
label(d, 154, 103, "FOD:", dark);
}
bool connected(uint8_t port) {
return port == HLT331Serial::PORT_CHARGING || port == HLT331Serial::PORT_DISCHARGING;
}
// Write only the changed span inside each segment, skipping the white dividers.
void updateBar(DisplayDriver& d, int x, int y, int w, int h, int before, int after,
ColorVal filled, ColorVal empty, int segments = 1) {
int oldWidth = before > 0 ? (w * before + 50) / 100 : 0;
int newWidth = after > 0 ? (w * after + 50) / 100 : 0;
if (oldWidth == newWidth) return;
d.setColor(newWidth > oldWidth ? filled : empty);
for (int i = 0; i < segments; ++i) {
int left = max(min(oldWidth, newWidth), i * w / segments + (i != 0));
int right = min(max(oldWidth, newWidth), (i + 1) * w / segments);
if (left < right) d.fillRect(x + left, y, right - left, h);
}
}
void clearField(DisplayDriver& d, int x, int y, int w, int h, ColorVal color) {
d.setColor(color);
d.fillRect(x, y, w, h);
}
void drawTemperature(DisplayDriver& d, const char* value) {
const bool hasPoint = strchr(value, '.') != nullptr;
const int glyphs = strlen(value) - hasPoint;
const int size = glyphs <= 3 ? 2 : 1; // Leave room for the unit on longer readings.
const int advance = 5 * size + 1;
const int width = glyphs * advance + (hasPoint ? 3 : 0);
int x = temperatureCenterX - (width - 1) / 2;
clearField(d, 102, 43, 64, 14, blue);
d.setColor(white);
d.setTextSize(size);
for (const char* p = value; *p; ++p) {
if (*p == '.') {
d.fillRect(x, 55, 2, 2);
x += 3;
} else {
char glyph[] = {*p, '\0'};
d.setCursor(x, 57 - 7 * size);
d.print(glyph);
x += advance;
}
}
d.drawRect(x + 1, 49, 3, 3);
label(d, x + 5, 50, "C", white);
}
void drawPowerRays(DisplayDriver& d, ColorVal ink) {
d.setColor(ink);
d.fillRect(193, 7, 1, 4);
d.fillRect(193, 38, 1, 4);
d.fillRect(176, 24, 4, 1);
d.fillRect(207, 24, 4, 1);
for (int offset = 10; offset <= 12; ++offset) {
d.fillRect(193 - offset, 24 - offset, 1, 1);
d.fillRect(193 + offset, 24 - offset, 1, 1);
d.fillRect(193 - offset, 24 + offset, 1, 1);
d.fillRect(193 + offset, 24 + offset, 1, 1);
}
}
void drawWatts(DisplayDriver& d, int32_t wattsX10) {
char value[16] = "--";
if (wattsX10 >= 0) {
snprintf(value, sizeof(value), "%ld.%ld", long(wattsX10 / 10), long(wattsX10 % 10));
}
clearField(d, 170, 43, 47, 14, purple);
if (wattsX10 >= 1000) { // Three integer digits only fit in the small font.
d.setTextSize(1);
int digits = d.getTextWidth(value);
int x = 193 - (digits + 7) / 2;
label(d, x, 50, value, white);
label(d, x + digits + 1, 50, "W", white);
return;
}
// Budget 11 pixels per digit, 3 for the decimal point and 7 for the unit.
int width = 7;
for (const char* p = value; *p; ++p) width += (*p == '.') ? 3 : 11;
int x = 193 - width / 2;
d.setColor(white);
d.setTextSize(2);
for (const char* p = value; *p; ++p) {
if (*p == '.') {
d.fillRect(x, 55, 2, 2);
x += 3;
} else {
char digit[] = {*p, '\0'};
d.setCursor(x, 43);
d.print(digit);
x += 11;
}
}
label(d, x + 1, 50, "W", white);
}
}
void PowerBankPage::drawUsb(DisplayDriver& d, int x, UsbPort& last, uint8_t state, uint8_t mode, bool shared, bool force) {
if (!painted || force || state != last.state) {
const char* name = "--";
ColorVal badge = off;
switch (state) {
case HLT331Serial::PORT_NOT_CONNECTED: name = "OFF"; break;
case HLT331Serial::PORT_CHARGING: name = "CHG"; badge = green; break;
case HLT331Serial::PORT_DISCHARGING: name = "DCHG"; badge = gold; break;
}
clearField(d, x + 5, 102, 60, 10, card);
panel(d, x + 6, 102, 28, 10, badge, 5);
d.setTextSize(1);
label(d, x + 21 - d.getTextWidth(name) / 2, 104, name, badge == off ? white : dark);
last.state = state;
}
char protocol[sizeof(last.protocol)] = "";
if (connected(state) && mode != HLT331Serial::FAST_CHARGE_NONE) {
snprintf(protocol, sizeof(protocol), "%s%s", HLT331Serial::fastChargeName(mode), shared ? "*" : "");
}
if (!painted || force || strcmp(last.protocol, protocol) != 0) {
clearField(d, x + 6, 116, 63, 7, card);
label(d, x + 6, 116, protocol, dark);
strcpy(last.protocol, protocol);
}
}
void PowerBankPage::drawUsbDataMode(DisplayDriver& d, int x) {
drawUsbConnector(d, x, blue);
clearField(d, x + 5, 102, 60, 10, card);
panel(d, x + 21, 102, 28, 10, blue, 5);
d.setTextSize(1);
const char* badge = "USB";
label(d, x + 35 - d.getTextWidth(badge) / 2, 104, badge, white);
clearField(d, x + 6, 116, 63, 7, card);
const char* blocked = "CHG/DCHG";
const int width = d.getTextWidth(blocked);
const int textX = x + 35 - width / 2;
label(d, textX, 116, blocked, dark);
d.setColor(red);
const int dischargeX = textX + d.getTextWidth("CHG/");
d.fillRect(dischargeX, 119, d.getTextWidth("DCHG"), 1);
}
void PowerBankPage::drawBattery(DisplayDriver& d, const PowerBankSnapshot& status) {
const auto& cw = status.cw;
const int nextPercent = cw.ready ? min(100, int(cw.socPercent)) : -1;
char value[16];
if (!painted || percent != nextPercent) {
if (nextPercent < 0) strcpy(value, "--");
else snprintf(value, sizeof(value), "%d", nextPercent);
clearField(d, 8, 25, 41, 14, blue);
label(d, 8, 25, value, white, 2);
label(d, min(43, 10 + d.getTextWidth(value)), 31, "%", white);
int before = painted ? percent : 0;
updateBar(d, 52, 19, 34, 7, before, nextPercent, shine, well);
updateBar(d, 52, 26, 34, 10, before, nextPercent, green, well);
updateBar(d, 9, 51, 83, 6, before, nextPercent, green, track, 10);
percent = nextPercent;
}
const int32_t nextTemp = cw.ready ? cw.temperatureX10C : INT32_MIN;
if (!painted || nextTemp != temperature) {
if (!cw.ready) strcpy(value, "--");
else {
const int temp = cw.temperatureX10C;
snprintf(value, sizeof(value), "%s%d.%d", temp < 0 ? "-" : "", abs(temp) / 10, abs(temp) % 10);
}
drawTemperature(d, value);
temperature = nextTemp;
}
}
void PowerBankPage::drawPower(DisplayDriver& d, const PowerBankSnapshot& status, bool live) {
const auto& hlt = status.hlt;
const bool active = live && (hlt.charging || connected(hlt.c1State) || connected(hlt.c2State) || hlt.wirelessWork);
if (!painted || active != boltActive) {
static const uint8_t bolt[] = {0x0c, 0x18, 0x30, 0x7e, 0x0c, 0x18, 0x30};
drawPowerRays(d, active ? badgeFace : purple);
d.setColor(active ? dark : boltInk);
d.drawXbm(190, 21, bolt, 8, 7);
boltActive = active;
}
const int32_t nextWatts = live ? int32_t(uint32_t(hlt.busMv) * hlt.busMa / 100000) : -1;
if (!painted || nextWatts != wattsX10) {
drawWatts(d, nextWatts);
wattsX10 = nextWatts;
}
}
void PowerBankPage::drawWireless(DisplayDriver& d, const PowerBankSnapshot& status, bool live) {
const auto& hlt = status.hlt;
const char* state = "--";
if (live) {
if (hlt.wirelessFod) state = "FOD!";
else state = hlt.wirelessWork ? "ON" : "OFF";
}
if (!painted || strcmp(state, qiState) != 0) {
const bool fault = live && hlt.wirelessFod;
const bool on = live && hlt.wirelessWork;
ColorVal fill = fault ? red : off;
if (on && !fault) fill = green;
panel(d, 188, 82, 28, 11, fill, 5);
if (fault) {
label(d, 190, 84, state, dark);
} else {
panel(d, on ? 207 : 190, 84, 7, 7, white, 3);
label(d, on ? 191 : 197, 84, state, on ? dark : white);
}
qiState = state;
}
const int nextFod = live ? int(hlt.wirelessFod) : -1;
if (!painted || nextFod != fod) {
ColorVal fill = off;
if (live) fill = hlt.wirelessFod ? red : gold;
panel(d, 182, 102, 13, 10, fill, 4);
const char* value = "--";
if (live) value = hlt.wirelessFod ? "1" : "0";
label(d, live ? 186 : 183, 104, value, live ? dark : white);
fod = nextFod;
}
const char* protocol = "";
if (live && hlt.wirelessWork && hlt.wirelessProtocol != HLT331Serial::WIRELESS_NULL) {
protocol = HLT331Serial::wirelessProtocolName(hlt.wirelessProtocol);
}
if (!painted || strcmp(protocol, qiProtocol) != 0) {
clearField(d, 154, 116, 63, 7, card);
label(d, 154, 116, protocol, dark);
snprintf(qiProtocol, sizeof(qiProtocol), "%s", protocol);
}
}
void PowerBankPage::draw(DisplayDriver& d, const PowerBankSnapshot& status, bool usbDataEnabled) {
if (!painted) drawLayout(d);
const auto& hlt = status.hlt;
const bool live = status.hltLive();
const bool shared = !usbDataEnabled && connected(hlt.c1State) && connected(hlt.c2State);
const bool usbModeChanged = !painted || usbDataMode != usbDataEnabled;
drawBattery(d, status);
drawPower(d, status, live);
drawUsb(d, 2, c1, live ? hlt.c1State : HLT331Serial::PORT_RESERVED, hlt.fastCharge, shared);
if (usbDataEnabled) {
if (usbModeChanged) drawUsbDataMode(d, 75);
} else {
if (usbModeChanged) drawUsbConnector(d, 75, dark);
drawUsb(d, 75, c2, live ? hlt.c2State : HLT331Serial::PORT_RESERVED, hlt.fastCharge, shared, usbModeChanged);
}
drawWireless(d, status, live);
usbDataMode = usbDataEnabled;
painted = true;
}
@@ -0,0 +1,34 @@
#pragma once
#include <helpers/ui/DisplayDriver.h>
struct PowerBankSnapshot;
class PowerBankPage {
public:
void invalidate() { painted = false; }
void draw(DisplayDriver& display, const PowerBankSnapshot& status, bool usbDataEnabled);
private:
struct UsbPort {
uint8_t state = 0;
char protocol[16]{};
};
void drawBattery(DisplayDriver& d, const PowerBankSnapshot& status);
void drawPower(DisplayDriver& d, const PowerBankSnapshot& status, bool live);
void drawUsb(DisplayDriver& d, int x, UsbPort& last, uint8_t state, uint8_t mode, bool shared, bool force = false);
void drawUsbDataMode(DisplayDriver& d, int x);
void drawWireless(DisplayDriver& d, const PowerBankSnapshot& status, bool live);
bool painted = false;
int percent = -1;
int32_t temperature = 0;
int32_t wattsX10 = -1;
bool boltActive = false;
bool usbDataMode = false;
UsbPort c1, c2;
const char* qiState = "";
int fod = -1;
char qiProtocol[16]{};
};
@@ -0,0 +1,79 @@
[heltec_meshpocket_v2]
extends = nrf52_base
board = heltec_meshpocket_v2
board_build.ldscript = boards/nrf52840_s140_v6_extrafs.ld
board_upload.maximum_size = 712704
build_flags = ${nrf52_base.build_flags}
-I variants/heltec_meshpocket_v2
-I src/helpers/nrf52
-I lib/nrf52/s140_nrf52_6.1.1_API/include
-I lib/nrf52/s140_nrf52_6.1.1_API/include/nrf52
-D HELTEC_MESH_POCKET_V2
-D RADIO_CLASS=CustomSX1262
-D WRAPPER_CLASS=CustomSX1262Wrapper
-D LORA_TX_POWER=22
-D SX126X_CURRENT_LIMIT=140
-D SX126X_RX_BOOSTED_GAIN=1
-D DISPLAY_CLASS=NV3001BDisplay
-D ENV_INCLUDE_GPS=1
-D DISABLE_DIAGNOSTIC_OUTPUT
build_src_filter = ${nrf52_base.build_src_filter}
+<../variants/heltec_meshpocket_v2/*.cpp>
+<helpers/sensors/EnvironmentSensorManager.cpp>
+<helpers/ui/NV3001BDisplay.cpp>
lib_deps = ${nrf52_base.lib_deps}
https://github.com/Quency-D/heltec-meshpocket-v2-power/releases/download/v0.2.0/HeltecMeshPocketV2Power-0.2.0.zip
stevemarple/MicroNMEA @ ^2.0.6
bakercp/CRC32 @ ^2.0.0
debug_tool = jlink
upload_protocol = nrfutil
[heltec_meshpocket_v2_companion]
extends = heltec_meshpocket_v2
build_flags = ${heltec_meshpocket_v2.build_flags}
-I examples/companion_radio/ui-new
-D MAX_CONTACTS=350
-D MAX_GROUP_CHANNELS=40
build_src_filter = ${heltec_meshpocket_v2.build_src_filter}
+<../examples/companion_radio/*.cpp>
+<../examples/companion_radio/ui-new/*.cpp>
lib_deps = ${heltec_meshpocket_v2.lib_deps}
densaugeo/base64 @ ~1.4.0
[env:heltec_meshpocket_v2_companion_radio_ble]
extends = heltec_meshpocket_v2_companion
build_flags = ${heltec_meshpocket_v2_companion.build_flags}
-D BLE_PIN_CODE=123456
-D OFFLINE_QUEUE_SIZE=256
build_src_filter = ${heltec_meshpocket_v2_companion.build_src_filter}
+<helpers/nrf52/SerialBLEInterface.cpp>
[env:heltec_meshpocket_v2_companion_radio_usb]
extends = heltec_meshpocket_v2_companion
build_flags = ${heltec_meshpocket_v2_companion.build_flags}
-D ENABLE_USB_INTERFACE
-D MESHPOCKET_V2_USB_SWITCHABLE
[env:heltec_meshpocket_v2_repeater]
extends = heltec_meshpocket_v2
build_flags = ${heltec_meshpocket_v2.build_flags}
-D MESHPOCKET_V2_USB_SWITCHABLE
-D ADVERT_NAME='"MeshPocket V2 Repeater"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
-D ADMIN_PASSWORD='"password"'
-D MAX_NEIGHBOURS=50
build_src_filter = ${heltec_meshpocket_v2.build_src_filter}
+<../examples/simple_repeater>
[env:heltec_meshpocket_v2_room_server]
extends = heltec_meshpocket_v2
build_flags = ${heltec_meshpocket_v2.build_flags}
-D MESHPOCKET_V2_USB_SWITCHABLE
-D ADVERT_NAME='"MeshPocket V2 Room"'
-D ADVERT_LAT=0.0
-D ADVERT_LON=0.0
-D ADMIN_PASSWORD='"password"'
-D ROOM_PASSWORD='"hello"'
build_src_filter = ${heltec_meshpocket_v2.build_src_filter}
+<../examples/simple_room_server>
+21
View File
@@ -0,0 +1,21 @@
#include "target.h"
#include <helpers/sensors/MicroNMEALocationProvider.h>
HeltecMeshPocketV2Board board;
RADIO_CLASS radio = new Module(P_LORA_NSS, P_LORA_DIO_1, P_LORA_RESET, P_LORA_BUSY, SPI);
WRAPPER_CLASS radio_driver(radio, board);
VolatileRTCClock rtc_clock;
NmeaGpsDriver gps_driver(Serial1);
MicroNMEALocationProvider gps(gps_driver, &rtc_clock);
EnvironmentSensorManager sensors(gps);
DISPLAY_CLASS display(&SPI1);
MomentaryButton user_btn(PIN_USER_BTN, 1000, true, true);
bool radio_init() {
return radio.std_init(&SPI);
}
mesh::LocalIdentity radio_new_identity() {
RadioNoiseListener rng(radio);
return mesh::LocalIdentity(&rng);
}
+18
View File
@@ -0,0 +1,18 @@
#pragma once
#include <helpers/radiolib/CustomSX1262Wrapper.h>
#include <helpers/ArduinoHelpers.h>
#include <helpers/sensors/EnvironmentSensorManager.h>
#include <helpers/ui/MomentaryButton.h>
#include <helpers/ui/NV3001BDisplay.h>
#include "HeltecMeshPocketV2Board.h"
extern HeltecMeshPocketV2Board board;
extern WRAPPER_CLASS radio_driver;
extern VolatileRTCClock rtc_clock;
extern EnvironmentSensorManager sensors;
extern DISPLAY_CLASS display;
extern MomentaryButton user_btn;
bool radio_init();
mesh::LocalIdentity radio_new_identity();
+13
View File
@@ -0,0 +1,13 @@
#include <Arduino.h>
const uint32_t g_ADigitalPinMap[] = {
0xff, 0xff, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47
};
void initVariant() {
// Preload the output latch before driving the USB data switch.
digitalWrite(PIN_IO_CSA, LOW);
pinMode(PIN_IO_CSA, OUTPUT);
}
+68
View File
@@ -0,0 +1,68 @@
#pragma once
#include "WVariant.h"
#define USE_LFXO
#define VARIANT_MCK 64000000ul
#define PINS_COUNT 48
#define NUM_DIGITAL_PINS 48
#define NUM_ANALOG_INPUTS 0
#define NUM_ANALOG_OUTPUTS 0
#define PIN_LED1 (-1)
#define LED_BUILTIN PIN_LED1
#define LED_BLUE (-1)
#define LED_GREEN (-1)
#define LED_STATE_ON 1
#define PIN_USER_BTN 43
#define PIN_BUTTON2 42
#define WIRE_INTERFACES_COUNT 1
#define PIN_WIRE_SDA 13
#define PIN_WIRE_SCL 5
#define PIN_CW_INT 12
#define PIN_IO_CSA 20
#define PIN_9006_IO1 4
#define PIN_9006_IO2 41
#define PIN_SERIAL2_RX 26
#define PIN_SERIAL2_TX 15
// EnvironmentSensorManager names the UART pins from the GPS module's side.
#define PIN_GPS_TX 34
#define PIN_GPS_RX 36
#define PIN_SERIAL1_RX PIN_GPS_TX
#define PIN_SERIAL1_TX PIN_GPS_RX
#define PIN_GPS_EN 22
#define PIN_GPS_EN_ACTIVE LOW
#define PIN_GPS_RESET 38
#define PIN_GPS_RESET_ACTIVE LOW
#define PIN_GPS_PPS 10
#define GPS_BAUD_RATE 115200
#define SPI_INTERFACES_COUNT 2
#define PIN_SPI_MISO 2
#define PIN_SPI_MOSI 47
#define PIN_SPI_SCK 45
#define P_LORA_MISO PIN_SPI_MISO
#define P_LORA_MOSI PIN_SPI_MOSI
#define P_LORA_SCLK PIN_SPI_SCK
#define P_LORA_NSS 14
#define P_LORA_DIO_1 31
#define P_LORA_BUSY 29
#define P_LORA_RESET 11
#define SX126X_DIO2_AS_RF_SWITCH true
#define SX126X_DIO3_TCXO_VOLTAGE 1.8f
#define PIN_SPI1_MISO 3
#define PIN_SPI1_MOSI 39
#define PIN_SPI1_SCK 33
#define PIN_TFT_SDA PIN_SPI1_MOSI
#define PIN_TFT_SCL PIN_SPI1_SCK
#define PIN_TFT_CS 16
#define PIN_TFT_DC 32
#define PIN_TFT_RST 24
#define PIN_TFT_EN 9
#define PIN_TFT_EN_ACTIVE LOW
#define PIN_TFT_BL 25
#define PIN_TFT_BL_ACTIVE HIGH
#define SPI_FREQUENCY 4000000
#define DISPLAY_ROTATION 3 // NV3001B MADCTL MX | MV