Files @ 6060ac6db4a5
Branch filter:

Location: seniordesign-firmware/master/master/lib/slavesensors.c

ethanzonca@CL-SEC241-08.cedarville.edu
Added error code functionality for error LED, added SD card errors.
/*
 * slavesensors.c
 *
 * Created: 11/27/2012 9:02:12 PM
 *  Author: ethanzonca
 */ 

#include <avr/io.h>
#include <stdbool.h>
#include "../config.h"
#include "serial.h"
#include "serparser.h"

// Serial Commands
enum sensorTypes // CMD ID#
{
	NONE = 0,
	BOARDTEMP = (1<<0),
	PRESSURE = (1<<1),
	GEIGER = (1<<2),
	TEMPERATURE = (1<<3),
	HUMIDITY = (1<<4),
	AMBIENTLIGHT = (1<<5),
	CAMERA = (1<<5),
};

uint8_t receptionFinished = 0;
uint8_t currentSlave = 0;
uint8_t currentSlaveSensor = 0;

uint8_t maxSlave = 8;
uint16_t slaves[8];

void slavesensors_setup() 
{
	// Empty array
	for(int i=0; i<8; i++) 
	{
		slaves[i] = 0;
	}	
	
	// Configure sensors
	slaves[0] = SLAVE0_SENSORS;
	slaves[1] = SLAVE1_SENSORS;
	slaves[2] = SLAVE2_SENSORS;
	slaves[3] = SLAVE3_SENSORS;
	slaves[4] = SLAVE4_SENSORS;
	slaves[5] = SLAVE5_SENSORS;
	slaves[6] = SLAVE6_SENSORS;
	slaves[7] = SLAVE7_SENSORS;	
}

bool slavesensors_process() 
{
	// Periodic: Every Iteration
		
	// maybe we should do this in an ISR on byte received. only problem is that this could interrupt things,
	// but we only care about interruption during logging and such. don't log when parsing a message?
	receptionFinished = serparser_parse();
		
	// Finished reception of a message (one sensor data value). If not finished, send out command to get the next one
	if(receptionFinished == 2)
	{
		bool weFinishedTHeLastSlaveSensor = false; // ex.
		// if we finished the final reception for this slave, set gettingValues = false;
		if(currentSlave >= maxSlave && weFinishedTHeLastSlaveSensor)
		{
			currentSlave = 0;
			return false; // We're done for now!
		}
		else
		{
			// Request data from the next slave
			currentSlave++;
			
			// Need to check the next bit over to see if it has that...
			
			serial_sendCommand(currentSlave, 'a', ""); // send req for data
			return true; // Keep going...
		}
	}
	else 
	{
		return true; // Keep going...
	}
}