Skip to content

Commit 22c04a1

Browse files
committed
Add Process Task , create readValue vs getValue in SenseData
1 parent 2a87c55 commit 22c04a1

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

WifiModule/SenseData.cpp

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ Scheduler sched;
1111

1212
Sensor SensorArray[MAX_SENSOR_NB];
1313

14+
void ProcessCallback() {
15+
//can do some logic here
16+
if(SensorArray[0].getValue() > 128)
17+
SensorArray[7].setValue(1);
18+
else
19+
SensorArray[7].setValue(0);
20+
}
21+
1422
void SamplingCallback() {
1523
for(int i = 0;i<MAX_SENSOR_NB;i++)
1624
{
@@ -46,23 +54,19 @@ void SenseData::init(void)
4654

4755
//Scheduler init
4856
sched.init();
49-
sched.addTask(SamplingTask);
50-
sched.addTask(HistoryTask);
51-
SamplingTask.enable();
52-
HistoryTask.enable();
57+
58+
sched.addTask(SamplingTask);
59+
sched.addTask(HistoryTask);
60+
SamplingTask.enable();
61+
HistoryTask.enable();
62+
63+
Task *ProcessTask = new Task(PROCESS_T, TASK_FOREVER, &ProcessCallback, &sched, true);
5364
Serial.println("Sense init");
5465
}
5566

5667
void SenseData::run(void)
5768
{
5869
sched.execute();
59-
/* //can do some logic here
60-
if(SensorArray[0].getValue() > 128)
61-
SensorArray[7].setValue(1);
62-
else
63-
SensorArray[7].setValue(0);
64-
65-
*/
6670
}
6771

6872
//void addSensor(Sensor sensor);
@@ -75,7 +79,7 @@ String SenseData::getData(char* name)
7579
{
7680
if(strcmp(name,SensorArray[i].m_name) == 0 || strcmp("",name) == 0)
7781
{
78-
ret += "\""+String(SensorArray[i].m_name)+"\":"+SensorArray[i].getValue()+",";
82+
ret += "\""+String(SensorArray[i].m_name)+"\":"+SensorArray[i].readValue()+",";
7983
}
8084
}
8185
}
@@ -94,7 +98,7 @@ int16_t SenseData::getValue(char* name)
9498
{
9599
if(strcmp(name,SensorArray[i].m_name) == 0 || strcmp("",name) == 0)
96100
{
97-
ret = SensorArray[i].getValue();
101+
ret = SensorArray[i].readValue();
98102
}
99103
}
100104
}

WifiModule/SenseData.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "Sensor.h"
77

88
#define MAX_SENSOR_NB 10
9+
#define PROCESS_T 1000 //in millisec
910

1011
class SenseData
1112
{

WifiModule/Sensor.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ void Sensor::init(char* name, SensorInput_t input, SensorType_t type)
4949

5050
void Sensor::update(void)
5151
{
52-
buffer.push(getValue());
52+
buffer.push(readValue());
5353
}
5454

55-
int16_t Sensor::getValue(void)
55+
int16_t Sensor::readValue(void)
5656
{
5757
float value = 0;
5858
switch(m_input){
@@ -111,6 +111,12 @@ int16_t Sensor::getValue(void)
111111
return m_value;
112112
}
113113

114+
115+
int16_t Sensor::getValue(void)
116+
{
117+
return m_value;
118+
}
119+
114120
void Sensor::setValue(int16_t val)
115121
{
116122
m_value = val;

WifiModule/Sensor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ class Sensor
6666
Sensor(void);
6767
void init(char* name, SensorInput_t input, SensorType_t type);
6868
void update(void);
69-
int16_t getValue(void);
69+
int16_t readValue(void); //read the data physically
70+
int16_t getValue(void); //read the buffered data
7071
void setValue(int16_t val);
7172
private:
7273
};

0 commit comments

Comments
 (0)