+#include "options.h"
+#include "bbb_pin.h"
+#include <math.h>
+
+/** Array of sensors, initialised by Sensor_Init **/
+static Sensor g_sensors[SENSORS_MAX];
+/** The number of sensors **/
+int g_num_sensors = 0;
+
+
+
+/**
+ * Add and initialise a Sensor
+ * @param name - Human readable name of the sensor
+ * @param user_id - User identifier
+ * @param read - Function to call whenever the sensor should be read
+ * @param init - Function to call to initialise the sensor (may be NULL)
+ * @param max_error - Maximum error threshold; program will exit if this is exceeded for the sensor reading
+ * @param min_error - Minimum error threshold; program will exit if the sensor reading falls below this value
+ * @param max_warn - Maximum warning threshold; program will log warnings if the value exceeds this threshold
+ * @param min_warn - Minimum warning threshold; program will log warnings if the value falls below this threshold
+ * @returns Number of actuators added so far
+ */
+int Sensor_Add(const char * name, int user_id, ReadFn read, InitFn init, CleanFn cleanup, SanityFn sanity)
+{
+ if (++g_num_sensors > SENSORS_MAX)
+ {
+ Fatal("Too many sensors; Increase SENSORS_MAX from %d in sensor.h and recompile", SENSORS_MAX);
+ // We could design the program to use realloc(3)
+ // But since someone who adds a new sensor has to recompile the program anyway...
+ }
+ Sensor * s = &(g_sensors[g_num_sensors-1]);
+
+ s->id = g_num_sensors-1;
+ s->user_id = user_id;
+ Data_Init(&(s->data_file));
+ s->name = name;
+ s->read = read; // Set read function
+ s->init = init; // Set init function
+
+ // Start by averaging values taken over a second
+ s->sample_us = 1e6;
+ s->averages = 1;
+
+ // Set sanity function
+ s->sanity = sanity;
+
+ if (init != NULL)
+ {
+ if (!init(name, user_id))
+ Fatal("Couldn't init sensor %s", name);
+ }
+
+
+ return g_num_sensors;
+}
+
+/**
+ * Initialise all sensors used by the program
+ * TODO: Edit this to add any extra sensors you need
+ * TODO: Edit the includes as well
+ */
+#include "sensors/resource.h"
+#include "sensors/strain.h"
+#include "sensors/pressure.h"
+void Sensor_Init()
+{
+ Sensor_Add("cpu_stime", RESOURCE_CPU_SYS, Resource_Read, NULL, NULL, NULL);
+ Sensor_Add("cpu_utime", RESOURCE_CPU_USER, Resource_Read, NULL, NULL, NULL);
+ Sensor_Add("pressure_high0", PRES_HIGH0, Pressure_Read, Pressure_Init, Pressure_Cleanup, NULL);
+ Sensor_Add("pressure_high1", PRES_HIGH1, Pressure_Read, Pressure_Init, Pressure_Cleanup, NULL);
+ Sensor_Add("pressure_low0", PRES_LOW0, Pressure_Read, Pressure_Init, Pressure_Cleanup, NULL);
+ //Sensor_Add("../testing/count.py", 0, Piped_Read, Piped_Init, Piped_Cleanup, 1e50,-1e50,1e50,-1e50);
+ //Sensor_Add("strain0", STRAIN0, Strain_Read, Strain_Init, 5000,0,5000,0);
+ //Sensor_Add("strain1", STRAIN1, Strain_Read, Strain_Init, 5000,0,5000,0);
+ //Sensor_Add("strain2", STRAIN2, Strain_Read, Strain_Init, 5000,0,5000,0);
+ //Sensor_Add("strain3", STRAIN3, Strain_Read, Strain_Init, 5000,0,5000,0);
+ //Sensor_Add("pressure0", PRESSURE0, Pressure_Read, Pressure_Init, 5000,0,5000,0);
+ //Sensor_Add("pressure1", PRESSURE1, Pressure_Read, Pressure_Init, 5000,0,5000,0);
+ //Sensor_Add("pressure_feedback", PRESSURE_FEEDBACK, Pressure_Read, Pressure_Init, 5000,0,5000,0);
+ //Sensor_Add("enclosure", ENCLOSURE, Enclosure_Read, Enclosure_Init, 1,1,1,1);
+ //Sensor_Add("dilatometer", DILATOMETER, Dilatometer_Read, Dilatometer_Init, -1,-1,-1,-1);
+}