Sensor Communication Library  0.2.0
SensorCommunicationLib.cpp
Go to the documentation of this file.
1 
12 /*
13  Copyright 2019, Toni Cafiero, IoThingsWare
14  MIT License terms detailed in LICENSE.txt
15 */
16 #include <Arduino.h>
17 #include <SensorCommunicationLib.h>
18 
19 
20 //Serial data variables
21 const char kDelimiter = ',';
22 const int kSerialInterval = 1000;
23 unsigned long serialPreviousTime;
24 Smoothed <float> avgSensors[MAXNUMOFSENSORS];
25 
26 
27 
35 {
36  kNumberOfSensors=NumberOfSensors;
37  for(int i=0; i < NumberOfSensors; i++) {
38  avgSensors[i].begin(SMOOTHED_AVERAGE, 10);
39  avgSensors[i].clear();
40  }
41 }
42 
43 void SensorCommunicationLib::Send()
44 {
45  int i;
46  for(i = 0; i < kNumberOfSensors-1; i++){
47  Serial.printf("%.2f", avgSensors[i].get());
48  Serial.print(kDelimiter);
49  }
50  Serial.printf("%.2f", avgSensors[i].get());
51  Serial.println();
52 }
53 
54 void SensorCommunicationLib::Tentative()
55 {
56  if((millis() - serialPreviousTime) > kSerialInterval)
57  {
58  serialPreviousTime = millis();
59  Send();
60  }
61 }
62 
69 void SensorCommunicationLib::processSensors(void (*getSensorData)()) //call in loop()
70 {
71  (*getSensorData)();
72  for(int i = 0; i < kNumberOfSensors; i++){
73  avgSensors[i].add(Sensors[i]);
74  }
75  delay(10);
76  Tentative();
77 }
SensorCommunicationLib(int NumberOfSensors=10)
void processSensors(void(*getSensorData)())
contains the SensorCommunicationLib class definition and the include file that the class implementati...