Cleanup and improvements (#194)

- Lots of changes for migrating C code to C++
- Improved `Lockable` in several ways like adding `withLock()` (+ tests)
- Improved `Semaphore` a bit for improved readability, and also added some tests
- Upgrade Linux machine in GitHub Actions so that we can compile with a newer GCC
- Simplification of WiFi connection
- Updated funding options
- (and more)
This commit is contained in:
Ken Van Hoeylandt
2025-01-28 17:39:58 +01:00
committed by GitHub
parent 1bb1260ea0
commit 6c67845645
54 changed files with 518 additions and 531 deletions
+10 -10
View File
@@ -26,9 +26,9 @@ static adc_oneshot_chan_cfg_t adcChannelConfig = {
};
static uint8_t estimateChargeLevelFromVoltage(uint32_t milliVolt) {
float volts = TT_MIN((float)milliVolt / 1000.f, BATTERY_VOLTAGE_MAX);
float volts = std::min((float)milliVolt / 1000.f, BATTERY_VOLTAGE_MAX);
float voltage_percentage = (volts - BATTERY_VOLTAGE_MIN) / (BATTERY_VOLTAGE_MAX - BATTERY_VOLTAGE_MIN);
float voltage_factor = TT_MIN(1.0f, voltage_percentage);
float voltage_factor = std::min(1.0f, voltage_percentage);
auto charge_level = (uint8_t) (voltage_factor * 100.f);
TT_LOG_V(TAG, "mV = %lu, scaled = %.2f, factor = %.2f, result = %d", milliVolt, volts, voltage_factor, charge_level);
return charge_level;
@@ -56,11 +56,11 @@ TdeckPower::~TdeckPower() {
bool TdeckPower::supportsMetric(MetricType type) const {
switch (type) {
case MetricType::BatteryVoltage:
case MetricType::ChargeLevel:
using enum MetricType;
case BatteryVoltage:
case ChargeLevel:
return true;
case MetricType::IsCharging:
case MetricType::Current:
default:
return false;
}
@@ -69,17 +69,17 @@ bool TdeckPower::supportsMetric(MetricType type) const {
bool TdeckPower::getMetric(Power::MetricType type, Power::MetricData& data) {
switch (type) {
case MetricType::BatteryVoltage:
using enum MetricType;
case BatteryVoltage:
return readBatteryVoltageSampled(data.valueAsUint32);
case MetricType::ChargeLevel:
case ChargeLevel:
if (readBatteryVoltageSampled(data.valueAsUint32)) {
data.valueAsUint32 = estimateChargeLevelFromVoltage(data.valueAsUint32);
return true;
} else {
return false;
}
case MetricType::IsCharging:
case MetricType::Current:
default:
return false;
}