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

Pull Request #529 rebase #543

Merged
merged 2 commits into from
Oct 6, 2021
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: 2 additions & 2 deletions pio/lib/Globals/Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ extern bool saveConfig(int16_t Offset[6]);
extern bool formatLittleFS();
extern void flash();

float scaleTemperature(float t);
String tempScaleLabel(void);
float scaleTemperatureFromC(float t, uint8_t);
String tempScaleLabel(uint8_t);

struct iData
{
Expand Down
4 changes: 2 additions & 2 deletions pio/lib/WiFiManagerKT/WiFiManagerKT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -986,9 +986,9 @@ void WiFiManager::handleiSpindel()
page += Tilt;
page += F("&deg;</td></tr>");
page += F("<tr><td>Temperature:</td><td>");
page += scaleTemperature(Temperatur);
page += scaleTemperatureFromC(Temperatur, myData.my_tempscale);
page += F("&deg;");
page += tempScaleLabel();
page += tempScaleLabel(myData.my_tempscale);
page += F("</td></tr>");
page += F("<tr><td>Battery:</td><td>");
page += Volt;
Expand Down
51 changes: 26 additions & 25 deletions pio/src/iSpindel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,25 +75,25 @@ uint32_t DSreqTime = 0;
int16_t ax, ay, az;
float Volt, Temperatur, Tilt, Gravity;

float scaleTemperature(float t)
float scaleTemperatureFromC(float t, uint8_t tempscale)
{
if (myData.my_tempscale == TEMP_CELSIUS)
if (tempscale == TEMP_CELSIUS)
return t;
else if (myData.my_tempscale == TEMP_FAHRENHEIT)
else if (tempscale == TEMP_FAHRENHEIT)
return (1.8f * t + 32);
else if (myData.my_tempscale == TEMP_KELVIN)
else if (tempscale == TEMP_KELVIN)
return t + 273.15f;
else
return t; // Invalid value for myData.my_tempscale => default to celsius
}

String tempScaleLabel(void)
String tempScaleLabel(uint8_t tempscale)
{
if (myData.my_tempscale == TEMP_CELSIUS)
if (tempscale == TEMP_CELSIUS)
return "C";
else if (myData.my_tempscale == TEMP_FAHRENHEIT)
else if (tempscale == TEMP_FAHRENHEIT)
return "F";
else if (myData.my_tempscale == TEMP_KELVIN)
else if (tempscale == TEMP_KELVIN)
return "K";
else
return "C"; // Invalid value for myData.my_tempscale => default to celsius
Expand Down Expand Up @@ -317,7 +317,7 @@ void postConfig()
if (myData.my_hassio)
{
sender.enableHassioDiscovery(myData.my_server, myData.my_port, myData.my_username, myData.my_password,
myData.my_name, tempScaleLabel());
myData.my_name, tempScaleLabel(myData.my_tempscale));
}
if (my_hassio_changed && !myData.my_hassio)
{
Expand Down Expand Up @@ -577,7 +577,7 @@ bool uploadData(uint8_t service)
if (service == DTUbiDots)
{
sender.add("tilt", Tilt);
sender.add("temperature", scaleTemperature(Temperatur));
sender.add("temperature", scaleTemperatureFromC(Temperatur, myData.my_tempscale));
sender.add("battery", Volt);
sender.add("gravity", Gravity);
sender.add("interval", myData.my_sleeptime);
Expand All @@ -592,7 +592,7 @@ bool uploadData(uint8_t service)
{
sender.add("name", myData.my_name);
sender.add("tilt", Tilt);
sender.add("temperature", scaleTemperature(Temperatur));
sender.add("temperature", scaleTemperatureFromC(Temperatur, myData.my_tempscale));
sender.add("battery", Volt);
sender.add("gravity", Gravity);
sender.add("interval", myData.my_sleeptime);
Expand All @@ -608,8 +608,8 @@ bool uploadData(uint8_t service)
if (service == DTMQTT)
{
sender.add("tilt", Tilt);
sender.add("temperature", scaleTemperature(Temperatur));
sender.add("temp_units", tempScaleLabel());
sender.add("temperature", scaleTemperatureFromC(Temperatur, myData.my_tempscale));
sender.add("temp_units", tempScaleLabel(myData.my_tempscale));
sender.add("battery", Volt);
sender.add("gravity", Gravity);
sender.add("interval", myData.my_sleeptime);
Expand All @@ -623,8 +623,8 @@ bool uploadData(uint8_t service)
if (service == DTTHINGSPEAK)
{
sender.add("tilt", Tilt);
sender.add("temperature", scaleTemperature(Temperatur));
sender.add("temp_units", tempScaleLabel());
sender.add("temperature", scaleTemperatureFromC(Temperatur, myData.my_tempscale));
sender.add("temp_units", tempScaleLabel(myData.my_tempscale));
sender.add("battery", Volt);
sender.add("gravity", Gravity);
sender.add("interval", myData.my_sleeptime);
Expand All @@ -638,8 +638,8 @@ bool uploadData(uint8_t service)
if (service == DTInfluxDB)
{
sender.add("tilt", Tilt);
sender.add("temperature", scaleTemperature(Temperatur));
sender.add("temp_units", tempScaleLabel());
sender.add("temperature", scaleTemperatureFromC(Temperatur, myData.my_tempscale));
sender.add("temp_units", tempScaleLabel(myData.my_tempscale));
sender.add("battery", Volt);
sender.add("gravity", Gravity);
sender.add("interval", myData.my_sleeptime);
Expand Down Expand Up @@ -677,8 +677,8 @@ bool uploadData(uint8_t service)
if (myData.my_token[0] != 0)
sender.add("token", myData.my_token);
sender.add("angle", Tilt);
sender.add("temperature", scaleTemperature(Temperatur));
sender.add("temp_units", tempScaleLabel());
sender.add("temperature", scaleTemperatureFromC(Temperatur, myData.my_tempscale));
sender.add("temp_units", tempScaleLabel(myData.my_tempscale));
sender.add("battery", Volt);
sender.add("gravity", Gravity);
sender.add("interval", myData.my_sleeptime);
Expand Down Expand Up @@ -717,8 +717,8 @@ bool uploadData(uint8_t service)
if (service == DTFHEM)
{
sender.add("angle", Tilt);
sender.add("temperature", scaleTemperature(Temperatur));
sender.add("temp_units", tempScaleLabel());
sender.add("temperature", scaleTemperatureFromC(Temperatur, myData.my_tempscale));
sender.add("temp_units", tempScaleLabel(myData.my_tempscale));
sender.add("battery", Volt);
sender.add("gravity", Gravity);
sender.add("ID", ESP.getChipId());
Expand All @@ -729,7 +729,7 @@ bool uploadData(uint8_t service)
#if API_TCONTROL
if (service == DTTcontrol)
{
sender.add("T", scaleTemperature(Temperatur));
sender.add("T", scaleTemperatureFromC(Temperatur, myData.my_tempscale));
sender.add("D", Tilt);
sender.add("U", Volt);
sender.add("G", Gravity);
Expand All @@ -741,13 +741,13 @@ bool uploadData(uint8_t service)
#if API_BLYNK
if (service == DTBLYNK)
{
String tempToSend = String(scaleTemperature(Temperatur), 1);
String tempToSend = String(scaleTemperatureFromC(Temperatur, myData.my_tempscale), 1);
sender.add("20", tempToSend); //send temperature without the unit to the graph first
String voltToSend = String(Volt, 2);
sender.add("30", voltToSend); //send temperature without the unit to the graph first

tempToSend += "°";
tempToSend += tempScaleLabel(); // Add temperature unit to the String
tempToSend += tempScaleLabel(myData.my_tempscale); // Add temperature unit to the String

sender.add("1", String(Tilt, 1) + "°");
sender.add("2", tempToSend);
Expand All @@ -761,7 +761,8 @@ bool uploadData(uint8_t service)
if (service == DTBREWBLOX)
{
sender.add("Tilt[deg]", Tilt);
sender.add("Temperature[deg" + tempScaleLabel() + "]", scaleTemperature(Temperatur));
sender.add("Temperature[deg" + tempScaleLabel(myData.my_tempscale) + "]",
scaleTemperatureFromC(Temperatur, myData.my_tempscale));
sender.add("Battery[V]", Volt);
sender.add("Gravity", Gravity);
sender.add("Rssi[dBm]", WiFi.RSSI());
Expand Down