Skip to content

Commit 882bbf8

Browse files
committed
[Mois Labs] Format code with CLion
1 parent acba93e commit 882bbf8

File tree

1 file changed

+154
-153
lines changed

1 file changed

+154
-153
lines changed

moislabs/beescale-yun/beescale-yun.ino

Lines changed: 154 additions & 153 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
**********************************************************************************************************/
5858

5959
// define individual values for used load cell type
60-
// loadCellZeroOffset: write down the sensor value of the scale with no load and adjust it
61-
// loadCellKgDivider: add a load with known weight in kg to the cell, note the sensor value, calculate
62-
// the value for the load and adjust it
60+
// loadCellZeroOffset: write down the sensor value of the scale with no load and adjust it
61+
// loadCellKgDivider: add a load with known weight in kg to the cell, note the sensor value, calculate
62+
// the value for the load and adjust it
6363
// Vertauschte Anschlüsse der Wägezellen:
6464
long loadCellZeroOffset = 6100000; //die mit den NICHT-versenkten schrauben (erhöhen um den offset zu senken und vice versa)
6565
long loadCellKgDivider = 5810000;
@@ -96,9 +96,12 @@ int switchPin = 11; // switch is connected to pin 11
9696
uint16_t lux = 0;
9797

9898
#include <ADS1231.h>
99+
99100
ADS1231 loadCell; // create ADS1231 object
100101
ADS1231 loadCell01;
102+
101103
#include <RunningMedian.h>
104+
102105
// RunningMedian sample size is 11
103106
RunningMedian weightSamples = RunningMedian(11); // create RunningMedian object
104107
RunningMedian weightSamples01 = RunningMedian(11);
@@ -108,12 +111,14 @@ RunningMedian weightSamples01 = RunningMedian(11);
108111

109112
#include <OneWire.h>
110113
#include <DallasTemperature.h>
114+
111115
#define ONE_WIRE_BUS 4
112116
OneWire OneWire(ONE_WIRE_BUS);
113117
// Pass our OneWire reference to Dallas Temperature.
114118
DallasTemperature sensors(&OneWire);
115119

116120
#include "DHT.h"
121+
117122
#define DHT1PIN 2
118123
#define DHT2PIN 3
119124
#define DHT1TYPE DHT22
@@ -124,69 +129,68 @@ DHT dht2(DHT2PIN, DHT2TYPE);
124129
#include <Wire.h>
125130
#include <Adafruit_Sensor.h>
126131
#include "Adafruit_TSL2591.h"
132+
127133
Adafruit_TSL2591 tsl = Adafruit_TSL2591(2591); // pass in a number for the sensor identifier
128134

129135
// Forward declarations
130136
String getTimeStamp();
131137

132138
// Function to read out weight cell.
133139
void getWeight(void) {
134-
// ADS1231 ready?
135-
if (loadCell.check())
136-
{
137-
for (int i = 0; i < 10; i++) {
138-
delay(200);
139-
// read input of ADS1231:
140-
weightSensorValue = loadCell.readData();
141-
weightSensorValue01 = loadCell01.readData();
142-
// calculate weight in kg
143-
weightKg = ((float)weightSensorValue - loadCellZeroOffset) / loadCellKgDivider;
144-
weightKg01 = ((float)weightSensorValue01 - loadCellZeroOffset01) / loadCellKgDivider01;
145-
// add data to runnig median sample
146-
weightSamples.add(weightKg);
147-
weightSamples01.add(weightKg01);
148-
}
140+
// ADS1231 ready?
141+
if (loadCell.check()) {
142+
for (int i = 0; i < 10; i++) {
143+
delay(200);
144+
// read input of ADS1231:
145+
weightSensorValue = loadCell.readData();
146+
weightSensorValue01 = loadCell01.readData();
147+
// calculate weight in kg
148+
weightKg = ((float) weightSensorValue - loadCellZeroOffset) / loadCellKgDivider;
149+
weightKg01 = ((float) weightSensorValue01 - loadCellZeroOffset01) / loadCellKgDivider01;
150+
// add data to runnig median sample
151+
weightSamples.add(weightKg);
152+
weightSamples01.add(weightKg01);
153+
}
149154
// weightKg = weightSamples.getAverage();
150-
weightKg = weightSamples.getMedian(); // Besser, weil durch Ausreißer nicht beeinflusst. Der Median ist der Wert in der Mitte einer nach ihrer Größe geordneten Rangreihe.
151-
weightKg01 = weightSamples01.getMedian();
152-
//convert the sensor data from float to string
153-
dtostrf(weightKg, 6, 3, cKg00); // Achtung: String ist exakt 6 Zeichen lang, inkl. Punkt. Funktioniert nur für Gewichte von 10.000 bis 99.999kg!
154-
dtostrf(weightKg01, 6, 3, cKg01);
155-
}
155+
weightKg = weightSamples.getMedian(); // Besser, weil durch Ausreißer nicht beeinflusst. Der Median ist der Wert in der Mitte einer nach ihrer Größe geordneten Rangreihe.
156+
weightKg01 = weightSamples01.getMedian();
157+
//convert the sensor data from float to string
158+
dtostrf(weightKg, 6, 3,
159+
cKg00); // Achtung: String ist exakt 6 Zeichen lang, inkl. Punkt. Funktioniert nur für Gewichte von 10.000 bis 99.999kg!
160+
dtostrf(weightKg01, 6, 3, cKg01);
161+
}
156162
}
157163

158164
void configureSensor(void) // Configures the gain and integration time for the TSL2591
159165
{
160-
tsl.setGain(TSL2591_GAIN_LOW); // 1x gain (bright light)
161-
// tsl.setGain(TSL2591_GAIN_MED); // 25x gain
162-
// tsl.setGain(TSL2591_GAIN_HIGH); // 428x gain
163-
// tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS); // shortest integration time (bright light)
164-
// tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);
165-
tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
166-
// tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);
167-
// tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);
168-
// tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS); // longest integration time (dim light)
169-
//
170-
// 25 gain/200ms ok for winter indoor. spring sun too bright.
171-
// 1 gain/300ms ok for sunny spring morning
166+
tsl.setGain(TSL2591_GAIN_LOW); // 1x gain (bright light)
167+
// tsl.setGain(TSL2591_GAIN_MED); // 25x gain
168+
// tsl.setGain(TSL2591_GAIN_HIGH); // 428x gain
169+
// tsl.setTiming(TSL2591_INTEGRATIONTIME_100MS); // shortest integration time (bright light)
170+
// tsl.setTiming(TSL2591_INTEGRATIONTIME_200MS);
171+
tsl.setTiming(TSL2591_INTEGRATIONTIME_300MS);
172+
// tsl.setTiming(TSL2591_INTEGRATIONTIME_400MS);
173+
// tsl.setTiming(TSL2591_INTEGRATIONTIME_500MS);
174+
// tsl.setTiming(TSL2591_INTEGRATIONTIME_600MS); // longest integration time (dim light)
175+
//
176+
// 25 gain/200ms ok for winter indoor. spring sun too bright.
177+
// 1 gain/300ms ok for sunny spring morning
172178
}
173179

174-
void simpleRead(void)
175-
{
176-
// Simple data read example. Just read the infrared, fullspecrtrum diode
177-
// or 'visible' (difference between the two) channels.
178-
// This can take 100-600 milliseconds! Uncomment whichever of the following you want to read
179-
lux = tsl.getLuminosity(TSL2591_VISIBLE);
180-
//uint16_t x = tsl.getLuminosity(TSL2591_FULLSPECTRUM);
181-
//uint16_t x = tsl.getLuminosity(TSL2591_INFRARED);
180+
void simpleRead(void) {
181+
// Simple data read example. Just read the infrared, fullspecrtrum diode
182+
// or 'visible' (difference between the two) channels.
183+
// This can take 100-600 milliseconds! Uncomment whichever of the following you want to read
184+
lux = tsl.getLuminosity(TSL2591_VISIBLE);
185+
//uint16_t x = tsl.getLuminosity(TSL2591_FULLSPECTRUM);
186+
//uint16_t x = tsl.getLuminosity(TSL2591_INFRARED);
182187
}
183188

184189
// Function to send values via GET request.
185-
void add_line()
186-
{
187-
HttpClient client;
188-
// convert the readings to a String to send it:
189-
dataURL="http://www.euse.de/honig/beescale/add_line2.php?weight1=";
190+
void add_line() {
191+
HttpClient client;
192+
// convert the readings to a String to send it:
193+
dataURL = "http://www.euse.de/honig/beescale/add_line2.php?weight1=";
190194
dataURL += cKg00;
191195
dataURL += "&weight2=";
192196
dataURL += cKg01;
@@ -204,8 +208,10 @@ void add_line()
204208
dataURL += t2;
205209
dataURL += "&lux=";
206210
dataURL += lux;
207-
//log to console, view with ssh root@[yun-ip] 'telnet localhost 6571'
208-
Console.print("Messwerte "); Console.print(getTimeStamp()); Console.println(":");
211+
//log to console, view with ssh root@[yun-ip] 'telnet localhost 6571'
212+
Console.print("Messwerte ");
213+
Console.print(getTimeStamp());
214+
Console.println(":");
209215
Console.print("Kiste1 kg: ");
210216
Console.print(weightKg, 3);
211217
Console.print(", Hum: ");
@@ -222,77 +228,75 @@ void add_line()
222228
Console.print(temp1);
223229
Console.print(", inside: ");
224230
Console.print(temp2);
225-
Console.print(", Lux: "); Console.println(lux, DEC);
231+
Console.print(", Lux: ");
232+
Console.println(lux, DEC);
226233
Console.print("GET request: ");
227234
Console.println(dataURL);
228-
//send data
235+
//send data
229236
client.get(dataURL);
230237
Console.println("sending data...");
231-
//if there's incoming data from the net connection send it out the console.
232-
while (client.available())
233-
{
234-
char c = client.read();
235-
Console.print(c);
236-
}
238+
//if there's incoming data from the net connection send it out the console.
239+
while (client.available()) {
240+
char c = client.read();
241+
Console.print(c);
242+
}
237243
Console.flush();
238244
}
239245

240-
void add_line_sd()
241-
{
242-
// make a string that starts with a timestamp for assembling the data to log:
243-
String dataString;
244-
dataString += getTimeStamp();
245-
dataString += ",";
246-
dataString += cKg00;
247-
dataString += ",";
248-
dataString += temp1;
249-
dataString += ",0,";
250-
dataString += lux;
251-
dataString += ",";
252-
dataString += cKg01;
253-
dataString += ",";
254-
dataString += temp2;
255-
dataString += ",";
256-
dataString += h1;
257-
dataString += ",";
258-
dataString += t1;
259-
dataString += ",";
260-
dataString += h2;
261-
dataString += ",";
262-
dataString += t2;
263-
File dataFile = FileSystem.open("/mnt/sda1/arduino/www/datalog.txt", FILE_APPEND);
264-
// if the file is available, write to it:
265-
if (dataFile) {
266-
Console.print("Writing to Yun SD... ");
267-
dataFile.println(dataString);
268-
dataFile.close();
269-
// print to the serial port too:
270-
Console.println("OK.");
246+
void add_line_sd() {
247+
// make a string that starts with a timestamp for assembling the data to log:
248+
String dataString;
249+
dataString += getTimeStamp();
250+
dataString += ",";
251+
dataString += cKg00;
252+
dataString += ",";
253+
dataString += temp1;
254+
dataString += ",0,";
255+
dataString += lux;
256+
dataString += ",";
257+
dataString += cKg01;
258+
dataString += ",";
259+
dataString += temp2;
260+
dataString += ",";
261+
dataString += h1;
262+
dataString += ",";
263+
dataString += t1;
264+
dataString += ",";
265+
dataString += h2;
266+
dataString += ",";
267+
dataString += t2;
268+
File dataFile = FileSystem.open("/mnt/sda1/arduino/www/datalog.txt", FILE_APPEND);
269+
// if the file is available, write to it:
270+
if (dataFile) {
271+
Console.print("Writing to Yun SD... ");
272+
dataFile.println(dataString);
273+
dataFile.close();
274+
// print to the serial port too:
275+
Console.println("OK.");
271276
// Console.print("OK. File Size: "); Console.println(getLogSize());
272-
}
273-
// if the file isn't open, pop up an error:
274-
else {
275-
Console.println("error opening /mnt/sda1/arduino/www/datalog.txt");
276-
}
277+
}
278+
// if the file isn't open, pop up an error:
279+
else {
280+
Console.println("error opening /mnt/sda1/arduino/www/datalog.txt");
281+
}
277282
}
278283

279-
String getTimeStamp()
280-
{
281-
String result;
282-
Process time;
283-
// date is a command line utility to get the date and the time
284-
// in different formats depending on the additional parameter
285-
time.begin("date");
286-
time.addParameter("+%Y/%m/%d %T");
287-
time.run(); // run the command
288-
// read the output of the command
289-
while (time.available() > 0) {
290-
char c = time.read();
291-
if (c != '\n') {
292-
result += c;
284+
String getTimeStamp() {
285+
String result;
286+
Process time;
287+
// date is a command line utility to get the date and the time
288+
// in different formats depending on the additional parameter
289+
time.begin("date");
290+
time.addParameter("+%Y/%m/%d %T");
291+
time.run(); // run the command
292+
// read the output of the command
293+
while (time.available() > 0) {
294+
char c = time.read();
295+
if (c != '\n') {
296+
result += c;
297+
}
293298
}
294-
}
295-
return result;
299+
return result;
296300
}
297301

298302
/*
@@ -312,52 +316,49 @@ String getLogSize()
312316
}
313317
*/
314318

315-
void setup()
316-
{
319+
void setup() {
317320
// delay(1000);
318-
Serial.begin(9600); //init serial port and set baudrate
319-
Bridge.begin();
320-
Console.begin();
321-
FileSystem.begin();
322-
// a second to initialize:
323-
delay(1000);
324-
// load cell / ADS1231 pin definition: SCL 7, Data 6, PowerDown 10
325-
loadCell.attach(7,6,10);
326-
// second load cell / ADS1231 pin definition: SCL 8, Data 5, PowerDown 9
327-
loadCell01.attach(8,5,9);
328-
sensors.begin(); // start DallasTemperature Lib
329-
// Switch LED: initialize digital pin LED_BUILTIN as an output.
330-
pinMode(LED_BUILTIN, OUTPUT);
331-
pinMode(switchPin, INPUT); // Switch: Set the switch pin as input
332-
dht1.begin();
333-
dht2.begin();
334-
tsl.begin();
335-
configureSensor(); // digital light sensor
321+
Serial.begin(9600); //init serial port and set baudrate
322+
Bridge.begin();
323+
Console.begin();
324+
FileSystem.begin();
325+
// a second to initialize:
326+
delay(1000);
327+
// load cell / ADS1231 pin definition: SCL 7, Data 6, PowerDown 10
328+
loadCell.attach(7, 6, 10);
329+
// second load cell / ADS1231 pin definition: SCL 8, Data 5, PowerDown 9
330+
loadCell01.attach(8, 5, 9);
331+
sensors.begin(); // start DallasTemperature Lib
332+
// Switch LED: initialize digital pin LED_BUILTIN as an output.
333+
pinMode(LED_BUILTIN, OUTPUT);
334+
pinMode(switchPin, INPUT); // Switch: Set the switch pin as input
335+
dht1.begin();
336+
dht2.begin();
337+
tsl.begin();
338+
configureSensor(); // digital light sensor
336339
}
337340

338-
void loop()
339-
{
340-
while (digitalRead(switchPin) == HIGH)
341-
{
342-
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
343-
Console.println("paused by switch...");
344-
delay(5000);
341+
void loop() {
342+
while (digitalRead(switchPin) == HIGH) {
343+
digitalWrite(LED_BUILTIN, HIGH); // turn the LED on (HIGH is the voltage level)
344+
Console.println("paused by switch...");
345+
delay(5000);
345346
}
346-
digitalWrite(LED_BUILTIN, LOW); // turn the LED off (LOW is the voltage level)
347+
digitalWrite(LED_BUILTIN, LOW); // turn the LED off (LOW is the voltage level)
347348
// delay(1000);
348-
//read and prepare sensor data
349-
sensors.requestTemperatures(); // get temperatures
350-
temp2 = sensors.getTempCByIndex(0); // Temp in box
351-
temp1 = sensors.getTempCByIndex(1); // Temp outside box
352-
simpleRead(); // Luminosity by TSL2591
353-
h1 = dht1.readHumidity();
354-
t1 = dht1.readTemperature();
355-
h2 = dht2.readHumidity();
356-
t2 = dht2.readTemperature();
357-
getWeight();
358-
add_line(); //transmit data
359-
add_line_sd(); // backup to Yun's MicroSD
360-
Console.println();
349+
//read and prepare sensor data
350+
sensors.requestTemperatures(); // get temperatures
351+
temp2 = sensors.getTempCByIndex(0); // Temp in box
352+
temp1 = sensors.getTempCByIndex(1); // Temp outside box
353+
simpleRead(); // Luminosity by TSL2591
354+
h1 = dht1.readHumidity();
355+
t1 = dht1.readTemperature();
356+
h2 = dht2.readHumidity();
357+
t2 = dht2.readTemperature();
358+
getWeight();
359+
add_line(); //transmit data
360+
add_line_sd(); // backup to Yun's MicroSD
361+
Console.println();
361362
// delay(21000); //run every 30 seconds (runtime without delay: 9 seconds)
362-
delay(111000); //run every two minutes (runtime without delay: 9 seconds)
363+
delay(111000); //run every two minutes (runtime without delay: 9 seconds)
363364
}

0 commit comments

Comments
 (0)