Skip to content

Commit

Permalink
add T-Beam v1.2 AXP2101
Browse files Browse the repository at this point in the history
  • Loading branch information
peterus committed Sep 9, 2023
1 parent 9131929 commit b638d95
Show file tree
Hide file tree
Showing 6 changed files with 301 additions and 76 deletions.
8 changes: 4 additions & 4 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: false
AllowShortEnumsOnASingleLine: false
AllowShortBlocksOnASingleLine: Never
AllowShortCaseLabelsOnASingleLine: false
Expand All @@ -24,8 +24,8 @@ AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
Expand Down Expand Up @@ -54,7 +54,7 @@ BreakConstructorInitializersBeforeComma: false
BreakConstructorInitializers: BeforeColon
BreakAfterJavaFieldAnnotations: false
BreakStringLiterals: true
ColumnLimit: 500
ColumnLimit: 200
CommentPragmas: '^ IWYU pragma:'
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
Expand Down
6 changes: 5 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ lib_deps =
adafruit/Adafruit GFX Library @ 1.11.5
adafruit/Adafruit SSD1306 @ 2.5.7
bblanchon/ArduinoJson @ 6.21.2
lewisxhe/AXP202X_Library @ 1.1.3
lewisxhe/XPowersLib @ 0.1.8
sandeepmistry/LoRa @ 0.8.0
peterus/APRS-Decoder-Lib @ 0.0.6
mikalhart/TinyGPSPlus @ 1.0.3
Expand All @@ -23,6 +23,10 @@ check_flags =
cppcheck: --suppress=*:*.pio\* --inline-suppr -DCPPCHECK
check_skip_packages = yes

[env:ttgo-t-beam-AXP2101-v1_2]
board = ttgo-t-beam
build_flags = -Werror -Wall -DTTGO_T_Beam_V1_2

[env:ttgo-t-beam-v1]
board = ttgo-t-beam
build_flags = -Werror -Wall -DTTGO_T_Beam_V1_0
Expand Down
83 changes: 58 additions & 25 deletions src/LoRa_APRS_Tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,22 @@
#include "pins.h"
#include "power_management.h"

#define VERSION "22.19.0"
#define VERSION "23.36.0"

logging::Logger logger;

Configuration Config;
BeaconManager BeaconMan;

PowerManagement powerManagement;
OneButton userButton = OneButton(BUTTON_PIN, true, true);
#ifdef TTGO_T_Beam_V1_0
AXP192 axp;
PowerManagement *powerManagement = &axp;
#endif
#ifdef TTGO_T_Beam_V1_2
AXP2101 axp;
PowerManagement *powerManagement = &axp;
#endif
OneButton userButton = OneButton(BUTTON_PIN, true, true);

HardwareSerial ss(1);
TinyGPSPlus gps;
Expand Down Expand Up @@ -66,15 +73,27 @@ void setup() {

#ifdef TTGO_T_Beam_V1_0
Wire.begin(SDA, SCL);
if (!powerManagement.begin(Wire)) {
if (powerManagement->begin(Wire)) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "AXP192", "init done!");
} else {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "AXP192", "init failed!");
}
powerManagement.activateLoRa();
powerManagement.activateOLED();
powerManagement.activateGPS();
powerManagement.activateMeasurement();
powerManagement->activateLoRa();
powerManagement->activateOLED();
powerManagement->activateGPS();
powerManagement->activateMeasurement();
#endif
#ifdef TTGO_T_Beam_V1_2
Wire.begin(SDA, SCL);
if (powerManagement->begin(Wire)) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_INFO, "AXP2101", "init done!");
} else {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "AXP2101", "init failed!");
}
powerManagement->activateLoRa();
powerManagement->activateOLED();
powerManagement->activateGPS();
powerManagement->activateMeasurement();
#endif

delay(500);
Expand Down Expand Up @@ -180,20 +199,15 @@ void loop() {
static String batteryChargeCurrent = "";
#ifdef TTGO_T_Beam_V1_0
static unsigned int rate_limit_check_battery = 0;
if (!(rate_limit_check_battery++ % 60))
BatteryIsConnected = powerManagement.isBatteryConnect();
if (!(rate_limit_check_battery++ % 60)) {
BatteryIsConnected = powerManagement->isBatteryConnect();
}
if (BatteryIsConnected) {
batteryVoltage = String(powerManagement.getBatteryVoltage(), 2);
batteryChargeCurrent = String(powerManagement.getBatteryChargeDischargeCurrent(), 0);
batteryVoltage = String(powerManagement->getBatteryVoltage(), 2);
batteryChargeCurrent = String(powerManagement->getBatteryChargeDischargeCurrent(), 0);
}
#endif

if (powerManagement.isChargeing()) {
powerManagement.enableChgLed();
} else {
powerManagement.disableChgLed();
}

if (!send_update && gps_loc_update && BeaconMan.getCurrentBeaconConfig()->smart_beacon.active) {
uint32_t lastTx = millis() - lastTxTime;
currentHeading = gps.course.deg();
Expand Down Expand Up @@ -222,7 +236,8 @@ void loop() {
if (send_update && gps_loc_update) {
send_update = false;

nextBeaconTimeStamp = now() + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_rate : (BeaconMan.getCurrentBeaconConfig()->timeout * SECS_PER_MIN));
nextBeaconTimeStamp =
now() + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_rate : (BeaconMan.getCurrentBeaconConfig()->timeout * SECS_PER_MIN));

APRSMessage msg;
String lat;
Expand Down Expand Up @@ -328,7 +343,20 @@ void loop() {

if (gps_time_update) {

show_display(BeaconMan.getCurrentBeaconConfig()->callsign, createDateString(now()) + " " + createTimeString(now()), String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop(), String("Next Bcn: ") + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? "~" : "") + createTimeString(nextBeaconTimeStamp), BatteryIsConnected ? (String("Bat: ") + batteryVoltage + "V, " + batteryChargeCurrent + "mA") : "Powered via USB", String("Smart Beacon: " + getSmartBeaconState()));
show_display(BeaconMan.getCurrentBeaconConfig()->callsign,
createDateString(now()) + " " + createTimeString(now()),
String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop(),
String("Next Bcn: ") + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? "~" : "") + createTimeString(nextBeaconTimeStamp),
BatteryIsConnected ? (String("Bat: ") + batteryVoltage + "V, " + batteryChargeCurrent + "mA") : "Powered via USB",
String("Smart Beacon: " + getSmartBeaconState()));

Serial.println(BeaconMan.getCurrentBeaconConfig()->callsign);
Serial.println(createDateString(now()) + " " + createTimeString(now()));
Serial.println(String("Sats: ") + gps.satellites.value() + " HDOP: " + gps.hdop.hdop());
Serial.println(String("Next Bcn: ") + (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active ? "~" : "") + createTimeString(nextBeaconTimeStamp));
Serial.println(BatteryIsConnected ? (String("Bat: ") + batteryVoltage + "V, " + batteryChargeCurrent + "mA") : "Powered via USB");
Serial.println(String("Smart Beacon: " + getSmartBeaconState()));
Serial.println();

if (BeaconMan.getCurrentBeaconConfig()->smart_beacon.active) {
// Change the Tx internal based on the current speed
Expand All @@ -348,13 +376,16 @@ void loop() {
would lead to decrease of beacon rate in between 5 to 20 km/h. what
is even below the slow speed rate.
*/
txInterval = min(BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_rate, BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_speed * BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_rate / curr_speed) * 1000;
txInterval = min(BeaconMan.getCurrentBeaconConfig()->smart_beacon.slow_rate,
BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_speed * BeaconMan.getCurrentBeaconConfig()->smart_beacon.fast_rate / curr_speed) *
1000;
}
}
}

if ((Config.debug == false) && (millis() > 5000 && gps.charsProcessed() < 10)) {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "GPS",
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR,
"GPS",
"No GPS frames detected! Try to reset the GPS Chip with this "
"firmware: https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset");
show_display("No GPS frames detected!", "Try to reset the GPS Chip", "https://github.com/lora-aprs/TTGO-T-Beam_GPS-reset", 2000);
Expand All @@ -366,11 +397,13 @@ void load_config() {
Config = confmg.readConfiguration();
BeaconMan.loadConfig(Config.beacons);
if (BeaconMan.getCurrentBeaconConfig()->callsign == "NOCALL-7") {
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR, "Config",
logger.log(logging::LoggerLevel::LOGGER_LEVEL_ERROR,
"Config",
"You have to change your settings in 'data/tracker.json' and "
"upload it via \"Upload File System image\"!");
show_display("ERROR", "You have to change your settings in 'data/tracker.json' and "
"upload it via \"Upload File System image\"!");
show_display("ERROR",
"You have to change your settings in 'data/tracker.json' and "
"upload it via \"Upload File System image\"!");
while (true) {
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/pins.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#define GPS_TX 12
#endif

#ifdef TTGO_T_Beam_V1_0
#if defined(TTGO_T_Beam_V1_0) || defined(TTGO_T_Beam_V1_2)
#define GPS_RX 12
#define GPS_TX 34
#endif
Expand Down
Loading

0 comments on commit b638d95

Please sign in to comment.