mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
* new helper: AutoDiscoverRTCClock, which detects: DS3231 (on i2c addr 0x68), or RV3028 (on i2c addr 0x52)
* repeater and room server: ver bump (v5), now use AutoDiscoverRTCClock * various Board::begin() now should do Wire.begin(), with custom pin mappings if needed * examples removed: ping client/server, and test_admin
This commit is contained in:
parent
c4cc3dd1ec
commit
a6a6bef371
13 changed files with 155 additions and 755 deletions
61
src/helpers/AutoDiscoverRTCClock.cpp
Normal file
61
src/helpers/AutoDiscoverRTCClock.cpp
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
#include "AutoDiscoverRTCClock.h"
|
||||
#include "RTClib.h"
|
||||
#include <Melopero_RV3028.h>
|
||||
|
||||
static RTC_DS3231 rtc_3231;
|
||||
static bool ds3231_success = false;
|
||||
|
||||
static Melopero_RV3028 rtc_rv3028;
|
||||
static bool rv3028_success = false;
|
||||
|
||||
#define DS3231_ADDRESS 0x68
|
||||
#define RV3028_ADDRESS 0x52
|
||||
|
||||
bool AutoDiscoverRTCClock::i2c_probe(TwoWire& wire, uint8_t addr) {
|
||||
wire.beginTransmission(addr);
|
||||
uint8_t error = wire.endTransmission();
|
||||
return (error == 0);
|
||||
}
|
||||
|
||||
void AutoDiscoverRTCClock::begin(TwoWire& wire) {
|
||||
if (i2c_probe(wire, DS3231_ADDRESS)) {
|
||||
ds3231_success = rtc_3231.begin(&wire);
|
||||
}
|
||||
if (i2c_probe(wire, RV3028_ADDRESS)) {
|
||||
rtc_rv3028.initI2C(wire);
|
||||
rtc_rv3028.writeToRegister(0x35, 0x00);
|
||||
rtc_rv3028.writeToRegister(0x37, 0xB4); // Direct Switching Mode (DSM): when VDD < VBACKUP, switchover occurs from VDD to VBACKUP
|
||||
rtc_rv3028.set24HourMode(); // Set the device to use the 24hour format (default) instead of the 12 hour format
|
||||
rv3028_success = true;
|
||||
}
|
||||
}
|
||||
|
||||
uint32_t AutoDiscoverRTCClock::getCurrentTime() {
|
||||
if (ds3231_success) {
|
||||
return rtc_3231.now().unixtime();
|
||||
}
|
||||
if (rv3028_success) {
|
||||
return DateTime(
|
||||
rtc_rv3028.getYear(),
|
||||
rtc_rv3028.getMonth(),
|
||||
rtc_rv3028.getDate(),
|
||||
rtc_rv3028.getHour(),
|
||||
rtc_rv3028.getMinute(),
|
||||
rtc_rv3028.getSecond()
|
||||
).unixtime();
|
||||
}
|
||||
return _fallback->getCurrentTime();
|
||||
}
|
||||
|
||||
void AutoDiscoverRTCClock::setCurrentTime(uint32_t time) {
|
||||
if (ds3231_success) {
|
||||
rtc_3231.adjust(DateTime(time));
|
||||
} else if (rv3028_success) {
|
||||
auto dt = DateTime(time);
|
||||
uint8_t weekday = (dt.day() + (uint16_t)((2.6 * dt.month()) - 0.2) - (2 * (dt.year() / 100)) + dt.year() + (uint16_t)(dt.year() / 4) + (uint16_t)(dt.year() / 400)) % 7;
|
||||
|
||||
rtc_rv3028.setTime(dt.year(), dt.month(), weekday, dt.day(), dt.hour(), dt.minute(), dt.second());
|
||||
} else {
|
||||
_fallback->setCurrentTime(time);
|
||||
}
|
||||
}
|
||||
17
src/helpers/AutoDiscoverRTCClock.h
Normal file
17
src/helpers/AutoDiscoverRTCClock.h
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include <Mesh.h>
|
||||
#include <Arduino.h>
|
||||
#include <Wire.h>
|
||||
|
||||
class AutoDiscoverRTCClock : public mesh::RTCClock {
|
||||
mesh::RTCClock* _fallback;
|
||||
|
||||
bool i2c_probe(TwoWire& wire, uint8_t addr);
|
||||
public:
|
||||
AutoDiscoverRTCClock(mesh::RTCClock& fallback) : _fallback(&fallback) { }
|
||||
|
||||
void begin(TwoWire& wire);
|
||||
uint32_t getCurrentTime() override;
|
||||
void setCurrentTime(uint32_t time) override;
|
||||
};
|
||||
|
|
@ -27,6 +27,12 @@ public:
|
|||
pinMode(P_LORA_TX_LED, OUTPUT);
|
||||
digitalWrite(P_LORA_TX_LED, LOW);
|
||||
#endif
|
||||
|
||||
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
|
||||
Wire.begin(PIN_BOARD_SDA, PIN_BOARD_SCL);
|
||||
#else
|
||||
Wire.begin();
|
||||
#endif
|
||||
}
|
||||
|
||||
uint8_t getStartupReason() const override { return startup_reason; }
|
||||
|
|
|
|||
|
|
@ -20,6 +20,23 @@ static void disconnect_callback(uint16_t conn_handle, uint8_t reason)
|
|||
MESH_DEBUG_PRINTLN("BLE client disconnected");
|
||||
}
|
||||
|
||||
void RAK4631Board::begin() {
|
||||
// for future use, sub-classes SHOULD call this from their begin()
|
||||
startup_reason = BD_STARTUP_NORMAL;
|
||||
|
||||
pinMode(PIN_VBAT_READ, INPUT);
|
||||
|
||||
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
|
||||
Wire.begin(PIN_BOARD_SDA, PIN_BOARD_SCL);
|
||||
#else
|
||||
Wire.begin();
|
||||
#endif
|
||||
|
||||
pinMode(SX126X_POWER_EN, OUTPUT);
|
||||
digitalWrite(SX126X_POWER_EN, HIGH);
|
||||
delay(10); // give sx1262 some time to power up
|
||||
}
|
||||
|
||||
bool RAK4631Board::startOTAUpdate() {
|
||||
// Config the peripheral connection with maximum bandwidth
|
||||
// more SRAM required by SoftDevice
|
||||
|
|
|
|||
|
|
@ -25,17 +25,7 @@ protected:
|
|||
uint8_t startup_reason;
|
||||
|
||||
public:
|
||||
void begin() {
|
||||
// for future use, sub-classes SHOULD call this from their begin()
|
||||
startup_reason = BD_STARTUP_NORMAL;
|
||||
|
||||
pinMode(PIN_VBAT_READ, INPUT);
|
||||
|
||||
pinMode(SX126X_POWER_EN, OUTPUT);
|
||||
digitalWrite(SX126X_POWER_EN, HIGH);
|
||||
delay(10); // give sx1262 some time to power up
|
||||
}
|
||||
|
||||
void begin();
|
||||
uint8_t getStartupReason() const override { return startup_reason; }
|
||||
|
||||
#define BATTERY_SAMPLES 8
|
||||
|
|
|
|||
|
|
@ -4,7 +4,23 @@
|
|||
#include <bluefruit.h>
|
||||
#include <Wire.h>
|
||||
|
||||
void T1000eBoard::begin() {
|
||||
// for future use, sub-classes SHOULD call this from their begin()
|
||||
startup_reason = BD_STARTUP_NORMAL;
|
||||
|
||||
#if defined(PIN_BOARD_SDA) && defined(PIN_BOARD_SCL)
|
||||
Wire.begin(PIN_BOARD_SDA, PIN_BOARD_SCL);
|
||||
#else
|
||||
Wire.begin();
|
||||
#endif
|
||||
|
||||
// pinMode(PIN_VBAT_READ, INPUT);
|
||||
|
||||
// Doesn't seem to be a pwr en pin ...
|
||||
// pinMode(LR1110_POWER_EN, OUTPUT);
|
||||
// digitalWrite(LR1110_POWER_EN, HIGH);
|
||||
delay(10); // give sx1262 some time to power up
|
||||
}
|
||||
|
||||
#if 0
|
||||
static BLEDfu bledfu;
|
||||
|
|
|
|||
|
|
@ -25,17 +25,7 @@ protected:
|
|||
uint8_t startup_reason;
|
||||
|
||||
public:
|
||||
void begin() {
|
||||
// for future use, sub-classes SHOULD call this from their begin()
|
||||
startup_reason = BD_STARTUP_NORMAL;
|
||||
|
||||
// pinMode(PIN_VBAT_READ, INPUT);
|
||||
|
||||
// Doesn't seem to be a pwr en pin ...
|
||||
// pinMode(LR1110_POWER_EN, OUTPUT);
|
||||
// digitalWrite(LR1110_POWER_EN, HIGH);
|
||||
delay(10); // give sx1262 some time to power up
|
||||
}
|
||||
void begin();
|
||||
|
||||
uint16_t getBattMilliVolts() override {
|
||||
return 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue