Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieucarbou committed May 5, 2024
1 parent 0ff2a95 commit f3b9e10
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion lib/MycilaAppInfo/MycilaAppInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <Esp.h>

#ifndef APP_NAME
#define APP_NAME "Beelance"
#define APP_NAME "YaSolR"
#endif

#ifndef APP_MANUFACTURER
Expand Down
19 changes: 12 additions & 7 deletions lib/MycilaRouterOutput/MycilaRouterOutput.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ void Mycila::RouterOutput::applyDimmerLimit() {
return;
if (_dimmer->isOff())
return;
if (_bypassEnabled)
return;
uint8_t limit = RouterOutputConfig.getDimmerLevelLimit(_name);
if (_dimmer->getLevel() > limit) {
Logger.warn(TAG, "Dimmer '%s' reached its limit at %u", _name, limit);
Expand Down Expand Up @@ -65,8 +67,7 @@ bool Mycila::RouterOutput::tryDimmerLevel(uint8_t level) {
}

Logger.debug(TAG, "Setting Dimmer '%s' level to %u...", _name, level);
_relay->off();
_dimmer->setLevel(level);
_setBypassRelay(false, level);
return true;
}

Expand Down Expand Up @@ -222,16 +223,20 @@ void Mycila::RouterOutput::autoBypass() {
_setBypassRelay(true);
}

void Mycila::RouterOutput::_setBypassRelay(bool state) {
void Mycila::RouterOutput::_setBypassRelay(bool state, uint8_t dimmerLevelWhenRelayOff) {
if (_relay->isEnabled()) {
Logger.debug(TAG, "Turning %s Bypass Relay '%s'...", state ? "on" : "off", _name);
if (state)
_dimmer->off();
_relay->setState(state);

if (state ^ _relay->isOn()) {
Logger.debug(TAG, "Turning %s Bypass Relay '%s'...", state ? "on" : "off", _name);
_relay->setState(state);
}
if (!state)
_dimmer->setLevel(dimmerLevelWhenRelayOff);
} else {
Logger.debug(TAG, "Turning %s Dimmer '%s'...", state ? "on" : "off", _name);
_dimmer->setLevel(state ? 100 : 0);
_dimmer->setLevel(state ? 100 : dimmerLevelWhenRelayOff);
_bypassEnabled = state;
}
}

Expand Down
5 changes: 3 additions & 2 deletions lib/MycilaRouterOutput/MycilaRouterOutput.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ namespace Mycila {
// bypass

void autoBypass();
bool isBypassRelayOn() const { return _relay->isEnabled() ? _relay->isOn() : _dimmer->isOnAtFullPower(); }
bool isBypassRelayOn() const { return _relay->isEnabled() ? _relay->isOn() : _bypassEnabled; }
bool isBypassRelayEnabled() const { return _relay->isEnabled() || _dimmer->isEnabled(); }
inline bool tryBypassRelayToggle() { return tryBypassRelayState(!isBypassRelayOn()); }
bool tryBypassRelayState(bool state);
Expand Down Expand Up @@ -110,6 +110,7 @@ namespace Mycila {
Relay* _relay;
PZEM* _pzem;
bool _autoBypassEnabled = false;
bool _bypassEnabled = false;
RouterOutputStateCallback _callback = nullptr;

private:
Expand All @@ -119,7 +120,7 @@ namespace Mycila {
float _inputVoltage = 0;

private:
void _setBypassRelay(bool state);
void _setBypassRelay(bool state, uint8_t dimmerLevelWhenRelayOff = 0);
};

extern RouterOutputConfigClass RouterOutputConfig;
Expand Down
9 changes: 0 additions & 9 deletions lib/MycilaTemperatureSensor/MycilaTemperatureSensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,6 @@ float Mycila::TemperatureSensor::read() {
return _temperature;
}

// TODO: remove
String Mycila::TemperatureSensor::getTemperatureAsString() const {
if (!_enabled || !isValid())
return "??.??";
char buffer[6];
snprintf(buffer, sizeof(buffer), "%5.2f", _temperature);
return buffer;
}

void Mycila::TemperatureSensor::toJson(const JsonObject& root) const {
root["enabled"] = _enabled;
root["temperature"] = _temperature;
Expand Down
3 changes: 1 addition & 2 deletions lib/MycilaTemperatureSensor/MycilaTemperatureSensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ namespace Mycila {

void listen(TemperatureChangeCallback callback) { _callback = callback; }

float getTemperature() const { return _temperature; }
float getTemperature() const { return isValid() ? _temperature : 0; }
bool isEnabled() const { return _enabled; }
bool isValid() const { return _expirationDelay == 0 ? _enabled : (millis() - _lastUpdate < _expirationDelay * 1000); }
uint32_t getLastUpdate() const { return _lastUpdate; }
uint32_t getExpirationDelay() const { return _expirationDelay; }

String getTemperatureAsString() const;
gpio_num_t getPin() const { return _pin; };

void toJson(const JsonObject& root) const;
Expand Down
4 changes: 2 additions & 2 deletions src/YaSolR_Display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ void YaSolR::YaSolRClass::updateDisplay() {
networkState = "Starting...";
break;
}
snprintf(lines[next], MYCILA_DISPLAY_LINE_LENGTH, "%-17.17s %-5.5s C", networkState.c_str(), systemTemperatureSensor.getTemperatureAsString().c_str());
snprintf(lines[next], MYCILA_DISPLAY_LINE_LENGTH, "%-17.17s %5.2f C", networkState.c_str(), systemTemperatureSensor.getTemperature());
next++;

snprintf(lines[next], MYCILA_DISPLAY_LINE_LENGTH, "G: %5d W R: %4d W", static_cast<int>(round(Mycila::Grid.getActivePower())), static_cast<int>(round(Mycila::Router.getTotalRoutedPower())));
next++;

const Mycila::RouterOutput outputs[2] = {output1, output2};
for (size_t i = 0; i < 2; i++) {
snprintf(lines[next], MYCILA_DISPLAY_LINE_LENGTH, "O%u: %-13.13s %-5.5s C", (i + 1), outputs[i].getStateString(), outputs[i].getTemperatureSensor()->getTemperatureAsString().c_str());
snprintf(lines[next], MYCILA_DISPLAY_LINE_LENGTH, "O%u: %-13.13s %5.2f C", (i + 1), outputs[i].getStateString(), outputs[i].getTemperatureSensor()->getTemperature());
next++;
}

Expand Down

0 comments on commit f3b9e10

Please sign in to comment.