mirror of
https://github.com/schinken/esp8266-geigercounter.git
synced 2024-11-23 09:00:21 +01:00
Code format
This commit is contained in:
parent
4823f0a36b
commit
e06c587b19
1 changed files with 57 additions and 55 deletions
|
@ -18,6 +18,8 @@ float lastuSv = 0, currentuSv = 0;
|
|||
|
||||
void setup() {
|
||||
|
||||
WiFi.mode(WIFI_STA);
|
||||
|
||||
Serial.begin(115200);
|
||||
geigerCounterSerial.begin(BAUD_GEIGERCOUNTER);
|
||||
|
||||
|
@ -44,24 +46,24 @@ void setup() {
|
|||
void updateRadiationValues() {
|
||||
|
||||
|
||||
char tmp[8];
|
||||
char tmp[8];
|
||||
|
||||
if(currentCPM != lastCPM) {
|
||||
String(currentCPM).toCharArray(tmp, 8);
|
||||
Serial.print("Sending CPM");
|
||||
Serial.println(tmp);
|
||||
mqttClient.publish(MQTT_TOPIC_CPM, tmp, true);
|
||||
}
|
||||
if (currentCPM != lastCPM) {
|
||||
String(currentCPM).toCharArray(tmp, 8);
|
||||
Serial.print("Sending CPM");
|
||||
Serial.println(tmp);
|
||||
mqttClient.publish(MQTT_TOPIC_CPM, tmp, true);
|
||||
}
|
||||
|
||||
if(currentuSv != lastuSv) {
|
||||
String(currentuSv).toCharArray(tmp, 8);
|
||||
Serial.print("Sending uSv");
|
||||
Serial.println(tmp);
|
||||
mqttClient.publish(MQTT_TOPIC_USV, tmp, true);
|
||||
}
|
||||
if (currentuSv != lastuSv) {
|
||||
String(currentuSv).toCharArray(tmp, 8);
|
||||
Serial.print("Sending uSv");
|
||||
Serial.println(tmp);
|
||||
mqttClient.publish(MQTT_TOPIC_USV, tmp, true);
|
||||
}
|
||||
|
||||
lastCPM = currentCPM;
|
||||
lastuSv = currentuSv;
|
||||
lastCPM = currentCPM;
|
||||
lastuSv = currentuSv;
|
||||
}
|
||||
|
||||
void connectMqtt() {
|
||||
|
@ -77,7 +79,7 @@ void connectMqtt() {
|
|||
newConnection = true;
|
||||
}
|
||||
|
||||
if(newConnection) {
|
||||
if (newConnection) {
|
||||
mqttClient.publish(MQTT_TOPIC_LAST_WILL, "connected", true);
|
||||
}
|
||||
|
||||
|
@ -85,45 +87,45 @@ void connectMqtt() {
|
|||
|
||||
void parseReceivedLine(char* input) {
|
||||
|
||||
char segment = 0;
|
||||
char *token;
|
||||
char segment = 0;
|
||||
char *token;
|
||||
|
||||
float uSv = 0;
|
||||
float cpm = 0;
|
||||
float uSv = 0;
|
||||
float cpm = 0;
|
||||
|
||||
token = strtok(input, delimiter);
|
||||
token = strtok(input, delimiter);
|
||||
|
||||
while (token != NULL) {
|
||||
while (token != NULL) {
|
||||
|
||||
switch(segment) {
|
||||
switch (segment) {
|
||||
|
||||
// This is just for validation
|
||||
case IDX_CPS_KEY: if (strcmp(token, "CPS") != 0) return; break;
|
||||
case IDX_CPM_KEY: if (strcmp(token, "CPM") != 0) return; break;
|
||||
case IDX_uSv_KEY: if (strcmp(token, "uSv/hr") != 0) return; break;
|
||||
// This is just for validation
|
||||
case IDX_CPS_KEY: if (strcmp(token, "CPS") != 0) return; break;
|
||||
case IDX_CPM_KEY: if (strcmp(token, "CPM") != 0) return; break;
|
||||
case IDX_uSv_KEY: if (strcmp(token, "uSv/hr") != 0) return; break;
|
||||
|
||||
case IDX_CPM:
|
||||
Serial.printf("Current CPM: %s\n", token);
|
||||
cpm = String(token).toInt();
|
||||
break;
|
||||
case IDX_CPM:
|
||||
Serial.printf("Current CPM: %s\n", token);
|
||||
cpm = String(token).toInt();
|
||||
break;
|
||||
|
||||
case IDX_uSv:
|
||||
Serial.printf("Current uSv/hr: %s\n", token);
|
||||
uSv = String(token).toFloat();
|
||||
break;
|
||||
}
|
||||
|
||||
if(segment > 7) {
|
||||
// Invalid! There should be no more than 7 segments
|
||||
return;
|
||||
}
|
||||
|
||||
token = strtok(NULL, delimiter);
|
||||
segment++;
|
||||
case IDX_uSv:
|
||||
Serial.printf("Current uSv/hr: %s\n", token);
|
||||
uSv = String(token).toFloat();
|
||||
break;
|
||||
}
|
||||
|
||||
currentuSv = uSv;
|
||||
currentCPM = cpm;
|
||||
if (segment > 7) {
|
||||
// Invalid! There should be no more than 7 segments
|
||||
return;
|
||||
}
|
||||
|
||||
token = strtok(NULL, delimiter);
|
||||
segment++;
|
||||
}
|
||||
|
||||
currentuSv = uSv;
|
||||
currentCPM = cpm;
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
@ -145,7 +147,7 @@ void loop() {
|
|||
}
|
||||
|
||||
// Just in case the buffer gets to big, start from scratch
|
||||
if(serialInput.length() > RECV_LINE_SIZE + 10) {
|
||||
if (serialInput.length() > RECV_LINE_SIZE + 10) {
|
||||
serialInput = "";
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue