If you have tested a sensor driver working on AVR 8 bits MCU before , that driver can be adapted to be used in EMMA , read this.
First the sensor driver should implement these functions if already done then follow these.
Define a macro for the sensor's bit to be identified on file sensors_flags like:
#define DHT11 1
That means the bit 1
will be addresed to refer the sensor DHT11, the sensor DHT11 measures temperature so the byte TEMPERATURE_CTRL_BYTE1
will be used in EEPROM memory to check the state of sensors
realted to temperature.
You should have defined a string containing the sensor's name on file ProgMemStrings.h, for instance:
const char STR_dht11[] PROGMEM = "DHT11";
In the same file there should be an array which contains the string you just defined. Remeber the bit defined in sensors_flags for the sensor you are to add, that same number should be the number of the element in the array.
For instance, the array that contains sensor names that measure temperature is STR_SensorsNamesTemperature1[]
and the string corresponding the sensor STR_dht11
is at position 1
(1 was the defined bit in sensor_flags.h
file for this sensor). The array should be like this:
PGM_P const STR_SensorsNamesTemperature1[] PROGMEM ={
// Temperature
STR_lm35, //0
STR_dht11, //1 <-- String corresponding to the sensor
STR_ds18s20, //2
};
If in doubt about this see ProgMemStrings.h
A sensor main header should be included in sensors.h see that file and include the new sensor.
But sensors.c contains a function void InitializeSensors(void)
. This function calls the sensor's init
function. Include the init
function of the sensor you want to add there, to make sure the sensor was marked to be included in logs you should add an if statement that checks if so, like this one:
if(temperature_ctrl & (1<<DHT11))
dht11_init();
The main program calls this function to initialize all sensors, and with the last statement in InitializeSensors
function, the sensor will initialize properly.
The function LogIntoFile()
on DataLogger.c file is the function that actually reads the sensor's name you defined on ProgMemStrings.h and logs it in a file.
For instance, if the sensor measures temperature, there should be an if statement if(temperature_ctrl)
which checks if a sensors that measures temperature was marked. You should nest there another if statement that checks if the sensor was marked to be included in the log. The statement should result in:
if(temperature_ctrl & (1<<DHT11))
{
Copy_STR_SensorsNamesTemperature1(str_buff, DHT11);
sprintf(str_buff, "%s\t", str_buff);
addToNewContentBuffer(str_buff, 1);
}
It will check for DHT11 sensor's control_flag
then it will copy the sensor's name to str_buff
string , then it will append that string into a temporal buffer, that buffer will later be logged on a file.
The function LogIntoFile()
on DataLogger.c file is the function that actually calls the sensor's get_response
function.
There is a second if statement that checks for physical phenomenom byte in the same file, you should nest there another if statement that checks wether the sensor was marked to be included in the logs. To do so for DHT11 sensor the statement will look like:
if(temperature_ctrl & (1<<DHT11))
{
last_sensor_response = dht11_get_Temperature();
AppendAndCheckValidDataFromSensor(last_sensor_response, logfile->FileName);
}
It checks if the sensor DHT11 (which measures temperature) was marked, then it calls the sensor's get_response
storing its response in last_sensor_response
var. Then it checks if that response is valid and appends that response into a temporal buffer that will be stored on a file later.
That is all needed to do for a sensor to be added using Datalogger system