11// Headers for each sensor type
22#include " YourSensorClass.h"
33// ...
4+ #include " YourActuatorClass.h"
45
6+ #include " Base.h"
57#include " Sensor.h"
8+ #include " Actuator.h"
69#define NUMSENSORS 1 // Or however many
10+ #define NUMACTUATORS 1 // Or however many
711#define BAUDRATE 115200
12+ #define THISARDUINO ARDUINO_ONE
813
914// Objects for each sensor
10- SensorClass sensor (/* Arguments, arduino enum*/ );
15+ SensorClass sensor (/* Arguments, ...*/ , THISARDUINO);
16+ // ...
17+ ActuatorClass actuator (/* Arguments, arduino enum*/ , THISARDUINO);
1118// ...
1219
1320Sensor* sensors[NUMSENSORS] = {
@@ -16,6 +23,12 @@ Sensor* sensors[NUMSENSORS] = {
1623 // ...
1724};
1825
26+ Actuator* actuators[NUMACTUATORS] = {
27+ // Entry for each sensor object
28+ &actuator,
29+ // ...
30+ };
31+
1932// !#!#!#!--- EVERYTHING AFTER HERE DOES NOT NEED TO BE CHANGED FOR SENSOR IMPLEMENTATION ---!#!#!#!
2033
2134void setup (){
@@ -37,8 +50,34 @@ void setup(){
3750 }
3851 success &= _success;
3952 }
53+ for (int i = 0 ; i < NUMACTUATORS; i++){
54+ ActuatorState* state = actuators[i]->begin ();
55+ // Print/send sensor post-setup state data here. For example:
56+ bool _success = (state->error == ERR_NONE);
57+ if (_success){
58+ Serial.print (" Actuator " );
59+ Serial.print (actuators[i]->actuator );
60+ Serial.print (" initialized. " );
61+
62+ state = actuators[i]->update (); // Initial set to default target
63+ _success = (state->error == ERR_NONE);
64+ if (_success){
65+ Serial.print (" Set to " );
66+ Serial.println (state->target );
67+ } else {
68+ Serial.print (" \n Actuator " );
69+ Serial.print (sensors[i]->sensor );
70+ Serial.println (" failed to set!" );
71+ }
72+ } else {
73+ Serial.print (" Actuator " );
74+ Serial.print (sensors[i]->sensor );
75+ Serial.println (" failed to initialize!" );
76+ }
77+ success &= _success;
78+ }
4079 if (!success){
41- Serial.println (" POST failed on one or more sensors , freezing..." );
80+ Serial.println (" POST failed on one or more devices , freezing..." );
4281 while (1 ){delay (1000 );}
4382 }
4483}
@@ -48,7 +87,7 @@ void loop(){
4887 SensorState* state = sensors[i]->update ();
4988 // Print/send sensor post-setup state data here. For example:
5089 bool _success = (state->error == ERR_NONE);
51- bool _new = (state->debug == DS_NEWREAD );
90+ bool _new = (state->debug == DS_SUCCESS );
5291 if (_success && _new){
5392 Serial.print (" Sensor " );
5493 Serial.print (sensors[i]->sensor );
@@ -66,4 +105,20 @@ void loop(){
66105 // TODO: Recover failed sensor?
67106 }
68107 }
108+ for (int i = 0 ; i < NUMACTUATORS; i++){
109+ ActuatorState* state = actuators[i]->update ();
110+
111+ bool _success = (state->error == ERR_NONE) && (state->debug == DS_SUCCESS);
112+ if (_success){
113+ Serial.print (" Actuator " );
114+ Serial.print (actuators[i]->actuator );
115+ Serial.print (" set success: " );
116+ Serial.println (state->target );
117+ } else {
118+ Serial.print (" Actuator " );
119+ Serial.print (actuators[i]->actuator );
120+ Serial.println (" failed to set!" );
121+ // TODO: Recover failed sensor?
122+ }
123+ }
69124}
0 commit comments