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

Adds Rx fan support #2492

Merged
merged 6 commits into from
Jun 24, 2024
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
4 changes: 3 additions & 1 deletion src/include/target/Unified_ESP_RX.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,6 @@
#define VPD_VALUES_100MW hardware_u16_array(HARDWARE_vtx_amp_vpd_100mW)
#define PWM_VALUES_25MW hardware_u16_array(HARDWARE_vtx_amp_pwm_25mW)
#define PWM_VALUES_100MW hardware_u16_array(HARDWARE_vtx_amp_pwm_100mW)
#endif
#endif

#define GPIO_PIN_FAN_EN hardware_pin(HARDWARE_misc_fan_en)
10 changes: 5 additions & 5 deletions src/lib/OPTIONS/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,11 @@ __attribute__ ((used)) static firmware_options_t flashedOptions = {
#else
.flash_discriminator = 0,
#endif
#if defined(FAN_MIN_RUNTIME)
.fan_min_runtime = FAN_MIN_RUNTIME,
#else
.fan_min_runtime = 30,
#endif
#if defined(PLATFORM_ESP32) || defined(PLATFORM_ESP8266)
#if defined(AUTO_WIFI_ON_INTERVAL)
.wifi_auto_on_interval = AUTO_WIFI_ON_INTERVAL * 1000,
Expand Down Expand Up @@ -123,11 +128,6 @@ __attribute__ ((used)) static firmware_options_t flashedOptions = {
.tlm_report_interval = TLM_REPORT_INTERVAL_MS,
#else
.tlm_report_interval = 240U,
#endif
#if defined(FAN_MIN_RUNTIME)
.fan_min_runtime = FAN_MIN_RUNTIME,
#else
.fan_min_runtime = 30,
#endif
._unused1 = false,
#if defined(UNLOCK_HIGHER_POWER)
Expand Down
2 changes: 1 addition & 1 deletion src/lib/OPTIONS/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ typedef struct _options {
uint8_t uid[6]; // MY_UID derived from MY_BINDING_PHRASE
uint32_t flash_discriminator; // Discriminator value used to determine if the device has been reflashed and therefore
// the SPIFSS settings are obsolete and the flashed settings should be used in preference
uint32_t fan_min_runtime;
#if defined(PLATFORM_ESP32) || defined(PLATFORM_ESP8266)
int32_t wifi_auto_on_interval;
char home_wifi_ssid[33];
Expand All @@ -40,7 +41,6 @@ typedef struct _options {
#endif
#if defined(TARGET_TX) || defined(UNIT_TEST)
uint32_t tlm_report_interval;
uint32_t fan_min_runtime;
bool _unused1:1;
bool unlock_higher_power:1;
bool is_airport:1;
Expand Down
21 changes: 13 additions & 8 deletions src/lib/THERMAL/devThermal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@

#if defined(HAS_THERMAL) || defined(HAS_FAN)

#if defined(TARGET_RX)
#error "devThermal not supported on RX"
#endif

#include "targets.h"
#include "config.h"
#include "logging.h"

#include "config.h"
#if defined(TARGET_RX)
extern RxConfig config;
#else
extern TxConfig config;

#endif
#define THERMAL_DURATION 1000

#if defined(HAS_THERMAL)
Expand Down Expand Up @@ -100,6 +98,7 @@ static void timeoutThermal()
}

#if defined(PLATFORM_ESP32)
#ifndef TARGET_RX
static void setFanSpeed()
{
const uint8_t defaultFanSpeeds[] = {
Expand All @@ -118,6 +117,7 @@ static void setFanSpeed()
DBGLN("Fan speed: %d (power) -> %u (pwm)", POWERMGNT::currPower(), speed);
}
#endif
#endif

/*
* For enable-only fans:
Expand All @@ -133,13 +133,17 @@ static void timeoutFan()
#if defined(HAS_FAN)
static uint8_t fanStateDuration;
static bool fanIsOn;
#if defined(TARGET_RX)
bool fanShouldBeOn = true;
#else
bool fanShouldBeOn = POWERMGNT::currPower() >= (PowerLevels_e)config.GetPowerFanThreshold();

#endif
if (fanIsOn)
{
if (fanShouldBeOn)
{
#if defined(PLATFORM_ESP32)
#ifndef TARGET_RX
if (GPIO_PIN_FAN_PWM != UNDEF_PIN)
{
static PowerLevels_e lastPower = MinPower;
Expand All @@ -155,6 +159,7 @@ static void timeoutFan()
}
}
else
#endif
#endif
{
fanStateDuration = 0; // reset the timeout
Expand Down
2 changes: 1 addition & 1 deletion src/lib/THERMAL/rpm.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "targets.h"

#if defined(PLATFORM_ESP32)
#if defined(PLATFORM_ESP32) && !defined(PLATFORM_ESP32_C3)
#include "logging.h"
#include <driver/pcnt.h>
#include <soc/pcnt_struct.h>
Expand Down
4 changes: 4 additions & 0 deletions src/src/rx_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "devSerialUpdate.h"
#include "devBaro.h"
#include "devMSPVTX.h"
#include "devThermal.h"

#if defined(PLATFORM_ESP8266)
#include <user_interface.h>
Expand Down Expand Up @@ -95,6 +96,9 @@ device_affinity_t ui_devices[] = {
#ifdef HAS_MSP_VTX
{&MSPVTx_device, 0}, // dependency on VTxSPI_device
#endif
#if defined(HAS_THERMAL) || defined(HAS_FAN)
{&Thermal_device, 0},
#endif
};

uint8_t antenna = 0; // which antenna is currently in use
Expand Down