Skip to content

Commit

Permalink
Remove F macro from onBattery extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
helgeerbe committed Jan 5, 2024
1 parent bfcce16 commit d5155a0
Show file tree
Hide file tree
Showing 12 changed files with 236 additions and 236 deletions.
4 changes: 2 additions & 2 deletions src/JkBmsController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ bool Controller::init(bool verboseLogging)
pin.battery_rx, pin.battery_rxen, pin.battery_tx, pin.battery_txen);

if (pin.battery_rx < 0 || pin.battery_tx < 0) {
MessageOutput.println(F("[JK BMS] Invalid RX/TX pin config"));
MessageOutput.println("[JK BMS] Invalid RX/TX pin config");
return false;
}

Expand All @@ -229,7 +229,7 @@ bool Controller::init(bool verboseLogging)
_txEnablePin = pin.battery_txen;

if (_rxEnablePin < 0 || _txEnablePin < 0) {
MessageOutput.println(F("[JK BMS] Invalid transceiver pin config"));
MessageOutput.println("[JK BMS] Invalid transceiver pin config");
return false;
}

Expand Down
40 changes: 20 additions & 20 deletions src/MqttHandlVedirectHass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,29 +109,29 @@ void MqttHandleVedirectHassClass::publishSensor(const char* caption, const char*
statTopic.concat(subTopic);

DynamicJsonDocument root(1024);
root[F("name")] = caption;
root[F("stat_t")] = statTopic;
root[F("uniq_id")] = serial + "_" + sensorId;
root["name"] = caption;
root["stat_t"] = statTopic;
root["uniq_id"] = serial + "_" + sensorId;

if (icon != NULL) {
root[F("icon")] = icon;
root["icon"] = icon;
}

if (unitOfMeasurement != NULL) {
root[F("unit_of_meas")] = unitOfMeasurement;
root["unit_of_meas"] = unitOfMeasurement;
}

JsonObject deviceObj = root.createNestedObject("dev");
createDeviceInfo(deviceObj);

if (Configuration.get().Mqtt.Hass.Expire) {
root[F("exp_aft")] = Configuration.get().Mqtt.PublishInterval * 3;
root["exp_aft"] = Configuration.get().Mqtt.PublishInterval * 3;
}
if (deviceClass != NULL) {
root[F("dev_cla")] = deviceClass;
root["dev_cla"] = deviceClass;
}
if (stateClass != NULL) {
root[F("stat_cla")] = stateClass;
root["stat_cla"] = stateClass;
}

char buffer[512];
Expand Down Expand Up @@ -160,14 +160,14 @@ void MqttHandleVedirectHassClass::publishBinarySensor(const char* caption, const
statTopic.concat(subTopic);

DynamicJsonDocument root(1024);
root[F("name")] = caption;
root[F("uniq_id")] = serial + "_" + sensorId;
root[F("stat_t")] = statTopic;
root[F("pl_on")] = payload_on;
root[F("pl_off")] = payload_off;
root["name"] = caption;
root["uniq_id"] = serial + "_" + sensorId;
root["stat_t"] = statTopic;
root["pl_on"] = payload_on;
root["pl_off"] = payload_off;

if (icon != NULL) {
root[F("icon")] = icon;
root["icon"] = icon;
}

JsonObject deviceObj = root.createNestedObject("dev");
Expand All @@ -182,12 +182,12 @@ void MqttHandleVedirectHassClass::createDeviceInfo(JsonObject& object)
{
auto spMpptData = VictronMppt.getData();
String serial = spMpptData->SER;
object[F("name")] = "Victron(" + serial + ")";
object[F("ids")] = serial;
object[F("cu")] = String(F("http://")) + NetworkSettings.localIP().toString();
object[F("mf")] = F("OpenDTU");
object[F("mdl")] = spMpptData->getPidAsString();
object[F("sw")] = AUTO_GIT_HASH;
object["name"] = "Victron(" + serial + ")";
object["ids"] = serial;
object["cu"] = String("http://") + NetworkSettings.localIP().toString();
object["mf"] = "OpenDTU";
object["mdl"] = spMpptData->getPidAsString();
object["sw"] = AUTO_GIT_HASH;
}

void MqttHandleVedirectHassClass::publish(const String& subtopic, const String& payload)
Expand Down
2 changes: 1 addition & 1 deletion src/PowerLimiter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ float PowerLimiterClass::getLoadCorrectedVoltage()
{
if (!_inverter) {
// there should be no need to call this method if no target inverter is known
MessageOutput.println(F("DPL getLoadCorrectedVoltage: no inverter (programmer error)"));
MessageOutput.println("DPL getLoadCorrectedVoltage: no inverter (programmer error)");
return 0.0;
}

Expand Down
30 changes: 15 additions & 15 deletions src/PylontechCanReceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ bool PylontechCanReceiver::init(bool verboseLogging)
{
_verboseLogging = verboseLogging;

MessageOutput.println(F("[Pylontech] Initialize interface..."));
MessageOutput.println("[Pylontech] Initialize interface...");

const PinMapping_t& pin = PinMapping.get();
MessageOutput.printf("[Pylontech] Interface rx = %d, tx = %d\r\n",
pin.battery_rx, pin.battery_tx);

if (pin.battery_rx < 0 || pin.battery_tx < 0) {
MessageOutput.println(F("[Pylontech] Invalid pin config"));
MessageOutput.println("[Pylontech] Invalid pin config");
return false;
}

Expand All @@ -35,18 +35,18 @@ bool PylontechCanReceiver::init(bool verboseLogging)
esp_err_t twaiLastResult = twai_driver_install(&g_config, &t_config, &f_config);
switch (twaiLastResult) {
case ESP_OK:
MessageOutput.println(F("[Pylontech] Twai driver installed"));
MessageOutput.println("[Pylontech] Twai driver installed");
break;
case ESP_ERR_INVALID_ARG:
MessageOutput.println(F("[Pylontech] Twai driver install - invalid arg"));
MessageOutput.println("[Pylontech] Twai driver install - invalid arg");
return false;
break;
case ESP_ERR_NO_MEM:
MessageOutput.println(F("[Pylontech] Twai driver install - no memory"));
MessageOutput.println("[Pylontech] Twai driver install - no memory");
return false;
break;
case ESP_ERR_INVALID_STATE:
MessageOutput.println(F("[Pylontech] Twai driver install - invalid state"));
MessageOutput.println("[Pylontech] Twai driver install - invalid state");
return false;
break;
}
Expand All @@ -55,10 +55,10 @@ bool PylontechCanReceiver::init(bool verboseLogging)
twaiLastResult = twai_start();
switch (twaiLastResult) {
case ESP_OK:
MessageOutput.println(F("[Pylontech] Twai driver started"));
MessageOutput.println("[Pylontech] Twai driver started");
break;
case ESP_ERR_INVALID_STATE:
MessageOutput.println(F("[Pylontech] Twai driver start - invalid state"));
MessageOutput.println("[Pylontech] Twai driver start - invalid state");
return false;
break;
}
Expand All @@ -72,21 +72,21 @@ void PylontechCanReceiver::deinit()
esp_err_t twaiLastResult = twai_stop();
switch (twaiLastResult) {
case ESP_OK:
MessageOutput.println(F("[Pylontech] Twai driver stopped"));
MessageOutput.println("[Pylontech] Twai driver stopped");
break;
case ESP_ERR_INVALID_STATE:
MessageOutput.println(F("[Pylontech] Twai driver stop - invalid state"));
MessageOutput.println("[Pylontech] Twai driver stop - invalid state");
break;
}

// Uninstall TWAI driver
twaiLastResult = twai_driver_uninstall();
switch (twaiLastResult) {
case ESP_OK:
MessageOutput.println(F("[Pylontech] Twai driver uninstalled"));
MessageOutput.println("[Pylontech] Twai driver uninstalled");
break;
case ESP_ERR_INVALID_STATE:
MessageOutput.println(F("[Pylontech] Twai driver uninstall - invalid state"));
MessageOutput.println("[Pylontech] Twai driver uninstall - invalid state");
break;
}
}
Expand All @@ -103,10 +103,10 @@ void PylontechCanReceiver::loop()
if (twaiLastResult != ESP_OK) {
switch (twaiLastResult) {
case ESP_ERR_INVALID_ARG:
MessageOutput.println(F("[Pylontech] Twai driver get status - invalid arg"));
MessageOutput.println("[Pylontech] Twai driver get status - invalid arg");
break;
case ESP_ERR_INVALID_STATE:
MessageOutput.println(F("[Pylontech] Twai driver get status - invalid state"));
MessageOutput.println("[Pylontech] Twai driver get status - invalid state");
break;
}
return;
Expand All @@ -118,7 +118,7 @@ void PylontechCanReceiver::loop()
// Wait for message to be received, function is blocking
twai_message_t rx_message;
if (twai_receive(&rx_message, pdMS_TO_TICKS(100)) != ESP_OK) {
MessageOutput.println(F("[Pylontech] Failed to receive message"));
MessageOutput.println("[Pylontech] Failed to receive message");
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/VictronMppt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void VictronMpptClass::updateSettings()
MessageOutput.printf("[VictronMppt] rx = %d, tx = %d\r\n", rx, tx);

if (rx < 0) {
MessageOutput.println(F("[VictronMppt] invalid pin config"));
MessageOutput.println("[VictronMppt] invalid pin config");
return;
}

Expand Down
4 changes: 2 additions & 2 deletions src/VictronSmartShunt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@

bool VictronSmartShunt::init(bool verboseLogging)
{
MessageOutput.println(F("[VictronSmartShunt] Initialize interface..."));
MessageOutput.println("[VictronSmartShunt] Initialize interface...");

const PinMapping_t& pin = PinMapping.get();
MessageOutput.printf("[VictronSmartShunt] Interface rx = %d, tx = %d\r\n",
pin.battery_rx, pin.battery_tx);

if (pin.battery_rx < 0) {
MessageOutput.println(F("[VictronSmartShunt] Invalid pin config"));
MessageOutput.println("[VictronSmartShunt] Invalid pin config");
return false;
}

Expand Down
50 changes: 25 additions & 25 deletions src/WebApi_battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ void WebApiBatteryClass::onStatus(AsyncWebServerRequest* request)
JsonObject root = response->getRoot();
const CONFIG_T& config = Configuration.get();

root[F("enabled")] = config.Battery.Enabled;
root[F("verbose_logging")] = config.Battery.VerboseLogging;
root[F("provider")] = config.Battery.Provider;
root[F("jkbms_interface")] = config.Battery.JkBmsInterface;
root[F("jkbms_polling_interval")] = config.Battery.JkBmsPollingInterval;
root[F("mqtt_topic")] = config.Battery.MqttTopic;
root["enabled"] = config.Battery.Enabled;
root["verbose_logging"] = config.Battery.VerboseLogging;
root["provider"] = config.Battery.Provider;
root["jkbms_interface"] = config.Battery.JkBmsInterface;
root["jkbms_polling_interval"] = config.Battery.JkBmsPollingInterval;
root["mqtt_topic"] = config.Battery.MqttTopic;

response->setLength();
request->send(response);
Expand All @@ -62,11 +62,11 @@ void WebApiBatteryClass::onAdminPost(AsyncWebServerRequest* request)

AsyncJsonResponse* response = new AsyncJsonResponse();
JsonObject retMsg = response->getRoot();
retMsg[F("type")] = F("warning");
retMsg["type"] = "warning";

if (!request->hasParam("data", true)) {
retMsg[F("message")] = F("No values found!");
retMsg[F("code")] = WebApiError::GenericNoValueFound;
retMsg["message"] = "No values found!";
retMsg["code"] = WebApiError::GenericNoValueFound;
response->setLength();
request->send(response);
return;
Expand All @@ -75,8 +75,8 @@ void WebApiBatteryClass::onAdminPost(AsyncWebServerRequest* request)
String json = request->getParam("data", true)->value();

if (json.length() > 1024) {
retMsg[F("message")] = F("Data too large!");
retMsg[F("code")] = WebApiError::GenericDataTooLarge;
retMsg["message"] = "Data too large!";
retMsg["code"] = WebApiError::GenericDataTooLarge;
response->setLength();
request->send(response);
return;
Expand All @@ -86,33 +86,33 @@ void WebApiBatteryClass::onAdminPost(AsyncWebServerRequest* request)
DeserializationError error = deserializeJson(root, json);

if (error) {
retMsg[F("message")] = F("Failed to parse data!");
retMsg[F("code")] = WebApiError::GenericParseError;
retMsg["message"] = "Failed to parse data!";
retMsg["code"] = WebApiError::GenericParseError;
response->setLength();
request->send(response);
return;
}

if (!root.containsKey(F("enabled")) || !root.containsKey(F("provider"))) {
retMsg[F("message")] = F("Values are missing!");
retMsg[F("code")] = WebApiError::GenericValueMissing;
if (!root.containsKey("enabled") || !root.containsKey("provider")) {
retMsg["message"] = "Values are missing!";
retMsg["code"] = WebApiError::GenericValueMissing;
response->setLength();
request->send(response);
return;
}

CONFIG_T& config = Configuration.get();
config.Battery.Enabled = root[F("enabled")].as<bool>();
config.Battery.VerboseLogging = root[F("verbose_logging")].as<bool>();
config.Battery.Provider = root[F("provider")].as<uint8_t>();
config.Battery.JkBmsInterface = root[F("jkbms_interface")].as<uint8_t>();
config.Battery.JkBmsPollingInterval = root[F("jkbms_polling_interval")].as<uint8_t>();
strlcpy(config.Battery.MqttTopic, root[F("mqtt_topic")].as<String>().c_str(), sizeof(config.Battery.MqttTopic));
config.Battery.Enabled = root["enabled"].as<bool>();
config.Battery.VerboseLogging = root["verbose_logging"].as<bool>();
config.Battery.Provider = root["provider"].as<uint8_t>();
config.Battery.JkBmsInterface = root["jkbms_interface"].as<uint8_t>();
config.Battery.JkBmsPollingInterval = root["jkbms_polling_interval"].as<uint8_t>();
strlcpy(config.Battery.MqttTopic, root["mqtt_topic"].as<String>().c_str(), sizeof(config.Battery.MqttTopic));
Configuration.write();

retMsg[F("type")] = F("success");
retMsg[F("message")] = F("Settings saved!");
retMsg[F("code")] = WebApiError::GenericSuccess;
retMsg["type"] = "success";
retMsg["message"] = "Settings saved!";
retMsg["code"] = WebApiError::GenericSuccess;

response->setLength();
request->send(response);
Expand Down
Loading

0 comments on commit d5155a0

Please sign in to comment.