Skip to content
Draft
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
41 changes: 36 additions & 5 deletions variants/lilygo_tbeam_1w/TBeam1WBoard.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,22 @@
#include "TBeam1WBoard.h"

void TBeam1WBoard::fanTimerCallback(void* arg) {
digitalWrite(FAN_CTRL_PIN, LOW);
}

void TBeam1WBoard::stopFanTimer() {
if (fan_timer != nullptr) {
esp_timer_stop(fan_timer);
}
}

void TBeam1WBoard::startFanTimer() {
if (fan_timer != nullptr) {
esp_timer_stop(fan_timer);
esp_timer_start_once(fan_timer, FAN_COOLDOWN_MS * 1000);
}
}

void TBeam1WBoard::begin() {
ESP32Board::begin();

Expand All @@ -15,18 +32,29 @@ void TBeam1WBoard::begin() {
pinMode(LED_PIN, OUTPUT);
digitalWrite(LED_PIN, LOW);

// Initialize fan control (on by default - 1W PA can overheat)
// Initialize fan control
pinMode(FAN_CTRL_PIN, OUTPUT);
digitalWrite(FAN_CTRL_PIN, HIGH);
digitalWrite(FAN_CTRL_PIN, LOW);

esp_timer_create_args_t timer_args = {
.callback = &TBeam1WBoard::fanTimerCallback,
.arg = this,
.dispatch_method = ESP_TIMER_TASK,
.name = "fan_cooldown",
.skip_unhandled_events = true
};
esp_timer_create(&timer_args, &fan_timer);
}

void TBeam1WBoard::onBeforeTransmit() {
// RF switching handled by RadioLib via SX126X_DIO2_AS_RF_SWITCH and setRfSwitchPins()
digitalWrite(LED_PIN, HIGH); // TX LED on
stopFanTimer();
digitalWrite(LED_PIN, HIGH);
digitalWrite(FAN_CTRL_PIN, HIGH);
}

void TBeam1WBoard::onAfterTransmit() {
digitalWrite(LED_PIN, LOW); // TX LED off
digitalWrite(LED_PIN, LOW);
startFanTimer();
}

uint16_t TBeam1WBoard::getBattMilliVolts() {
Expand All @@ -48,6 +76,8 @@ const char* TBeam1WBoard::getManufacturerName() const {
}

void TBeam1WBoard::powerOff() {
stopFanTimer();

// Turn off radio LNA (CTRL pin must be LOW when not receiving)
digitalWrite(SX126X_RXEN, LOW);

Expand All @@ -63,6 +93,7 @@ void TBeam1WBoard::powerOff() {
}

void TBeam1WBoard::setFanEnabled(bool enabled) {
stopFanTimer();
digitalWrite(FAN_CTRL_PIN, enabled ? HIGH : LOW);
}

Expand Down
8 changes: 8 additions & 0 deletions variants/lilygo_tbeam_1w/TBeam1WBoard.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
#include <Arduino.h>
#include <helpers/ESP32Board.h>
#include "variant.h"
#include "esp_timer.h"

#define FAN_COOLDOWN_MS 3000

// LilyGo T-Beam 1W with SX1262 + external PA (XY16P35 module)
//
Expand Down Expand Up @@ -30,6 +33,11 @@
class TBeam1WBoard : public ESP32Board {
private:
bool radio_powered = false;
esp_timer_handle_t fan_timer = nullptr;

static void fanTimerCallback(void* arg);
void stopFanTimer();
void startFanTimer();

public:
void begin();
Expand Down