Changeset - f04abd553284
[Not reviewed]
Merge default
0 6 0
ethanzonca@CL-ENS241-08.cedarville.edu - 12 years ago 2013-02-18 16:50:38
ethanzonca@CL-ENS241-08.cedarville.edu
Merge
6 files changed with 53 insertions and 29 deletions:
0 comments (0 inline, 0 general)
slave/slave/config.h
Show inline comments
 
/*
 
 * config.h
 
 *
 
 * Created: 10/25/2012 10:00:09 PM
 
 *  Author: mkanning
 
 */
 
 
 
 #ifndef CONFIG_H_
 
 #define CONFIG_H_
 
 
 #define F_CPU 11059200				// Clock frequency (used in calculations)
 
 
//Serial
 
#define USART0_BAUDRATE 115200
 
#define USART1_BAUDRATE 115200 
 
 
// Circular serial buffer size. Must be at least MAX_CMD_LEN + 5
 
#define BUFFER_SIZE 32
 
 
// Maximum payload size of command
 
#define MAX_PAYLOAD_LEN 16
 
 
// Number of datatypes to transmit per module type
 
#define DATATYPES_GENERIC 3
 
#define DATATYPES_SENSOR 8
 
#define DATATYPES_GEIGER 4
 
#define DATATYPES_CAMERA 3
 
 
//Sensors and IO
 
#define SENSOR_LOOP 100				// Frequency of sensor reads (in ms) (should be 200)
 
#define HEATER_THRESHOLD 40			// Temperature threshold in Fahrenheit where heater is activated
 
 
 //I2C Addresses
 
 #define EEPROM_ADDR 0xA0		// Read 0xA1 - Write 0xA0
 
 #define BOARDTEMP_ADDR 0x90	// Read 0x91 - Write 0x90
 
 #define PRESSURE_ADDR 0xEF		// Read 0xEF - Write 0xEE
 
 #define HUMID_ADDR 0x27		// Read 0x27 - Write 0x26
 
 #define LIGHT_ADDR 0x95		// Read 0x95 - Write 0x94
 
 #define PRESSURE_ADDR 0xEE		// Read 0xEF - Write 0xEE
 
 #define HUMID_ADDR 0x26		// Read 0x27 - Write 0x26
 
 #define LIGHT_ADDR 0x94		// Read 0x95 - Write 0x94
 
 #define RTC_ADDR 0xB2			//DEBUG [Used for testing]      // Read 0xA3 - Write 0xA2
 
 
 
 
 #endif /* CONFIG_H_ */
 
\ No newline at end of file
slave/slave/lib/masterComm.c
Show inline comments
 
@@ -45,127 +45,127 @@ void masterComm_types()
 
		case 1:
 
			// Sensors
 
			dataTypes = DATATYPES_SENSOR;
 
			break;
 
			
 
		case 2:
 
			// Geiger
 
			dataTypes = DATATYPES_GEIGER;
 
			break;
 
			
 
		case 3:
 
			// Camera
 
			dataTypes = DATATYPES_CAMERA;
 
			break;
 
			
 
		default:
 
			dataTypes = DATATYPES_GENERIC;
 
			break;
 
	}
 
}
 
 
 
void masterComm_packetSend_unsigned(uint8_t id, uint32_t data)
 
{
 
	serial0_sendChar('[');
 
	snprintf(buff2,64,"%u%lu",id,data);
 
	serial0_sendString(buff2);
 
	serial0_sendChar(']');
 
	serial0_sendChar(masterComm_checksum(buff2));
 
}
 
 
void masterComm_packetSend_signed(uint8_t id, int32_t data)
 
{
 
	serial0_sendChar('[');
 
	snprintf(buff2,64,"%u%ld",id,data);
 
	serial0_sendString(buff2);
 
	serial0_sendChar(']');
 
	serial0_sendChar(masterComm_checksum(buff2));
 
}
 
 
 
 
void masterComm_modules()
 
{
 
	// Send Board Temperature (Common for all modules)
 
	masterComm_packetSend_signed(0,sensors_getBoardTemp());
 
 
	// Send Heater Status (Common for all modules)
 
	masterComm_packetSend_unsigned(1,/*Heater Status Get Function Here */0);
 
	masterComm_packetSend_unsigned(1,io_heaterStatus());
 
	
 
	// Send Battery Level (Common for all modules)
 
	masterComm_packetSend_unsigned(2,/*Battery Level Get Function Here */0);
 
	masterComm_packetSend_unsigned(2,/*Battery Level Get Function Here */999);
 
	
 
	
 
	// Send module specific sensor readings
 
	switch(io_getModuleId())
 
	{
 
		case 0:
 
			// Generic
 
			
 
			break;
 
		
 
		case 1:
 
			// Sensors
 
			
 
			// Send SPI Temperature (Air)
 
			masterComm_packetSend_unsigned(3,sensors_getSpiTemp());
 
			
 
			// Send Ambient Light (Needs to be formatted)
 
			masterComm_packetSend_unsigned(4,/*Ambient Light Get Function Here */123);
 
			masterComm_packetSend_unsigned(4,sensors_getLux());
 
			
 
			// Send Humidity
 
			masterComm_packetSend_unsigned(5,/*Humidity Get Function Here */456);		
 
			masterComm_packetSend_unsigned(5,/*Humidity Get Function Here */999);		
 
			
 
			// Send Pressure 
 
			masterComm_packetSend_unsigned(6,/*Pressure Get Function Here */7890);			
 
			masterComm_packetSend_unsigned(6,sensors_getPressure());			
 
			
 
			// Send Altitude
 
			masterComm_packetSend_unsigned(7,/*Altitude Get Function Here */456789);
 
			masterComm_packetSend_unsigned(7,sensors_getAltitude());
 
			break;
 
			
 
		case 2:
 
			// Geiger
 
			
 
			// Send CPM (radiation)
 
			masterComm_packetSend_unsigned(8,geiger_getCpm());
 
			break;
 
		
 
		case 3:
 
			// Camera
 
			
 
			
 
			break;
 
		
 
		default:
 
			
 
			break;
 
	}
 
}
 
 
 
void masterComm_send()
 
{
 
	masterComm_types();		// Calculates how many data types to send
 
	
 
	// Return request with number of data types to be sent
 
	serial0_sendChar('[');						// Send opening bracket
 
	snprintf(buff2,64,"@%u",dataTypes);				// Send package (@ reply and number of data types)
 
	serial0_sendString(buff2);
 
	serial0_sendChar(']');						// Send closing bracket
 
	serial0_sendChar(masterComm_checksum(buff2));	// Calculate and send checksum
 
	
 
	masterComm_modules();	// Send sensor data
 
}
 
 
 
void masterComm_checkParser()
 
{
 
	if (serparser_parse() == PARSERESULT_PARSEOK)
 
	{
 
		if (getPayloadType() == ('@'-0x30))		// Request for data recieved
 
		{
 
			led_on(2);
 
			// Send all data
 
			masterComm_send();
 
			//led_off(2);
 
		}	
slave/slave/lib/sensors.c
Show inline comments
 
/*
 
 * sensors.c
 
 *
 
 * Created: 11/19/2012 9:25:01 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#include <inttypes.h>
 
#include <math.h>
 
#include <avr/io.h>
 
#include <avr/interrupt.h>
 
#include "../config.h"
 
#include <util/delay.h>
 
#include "sensors.h"
 
#include "spi.h"
 
#include "i2c.h"
 
 
int16_t	spiTemp;	// Thermocouple Temperature (from spi)
 
int8_t	boardTemp;	// Board Temperature (from i2c)
 
//Should these two be int16_t?  CHANGED TO INT32 BASED ON DATASHEET
 
int32_t ut;			// Temperature from BMP085 (from i2c)
 
int32_t up;			// Pressure from BMP085 (from i2c)
 
uint16_t humid;		// Humidity (from i2c)
 
uint8_t light;		// Lux reading (from i2c)
 
uint8_t lightH;		// Higher byte from light sensor (from i2c)
 
uint8_t lightL;		// Lower byte from light sensor
 
uint8_t exponent;	// Exponent for Lux
 
uint8_t mantissa;	// Mantissa for Lux
 
uint32_t lux;		// Calculated Lux value
 
int8_t batt;		// Read battery voltage from ADC
 
 
int16_t ac1;		// The following 11 variables are the calibration values for the BMP085
 
int16_t ac2;
 
int16_t ac3;
 
uint16_t ac4;
 
uint16_t ac5;
 
uint16_t ac6;
 
int16_t b1;
 
int16_t b2;
 
int16_t mb;
 
int16_t mc;
 
int16_t md;
 
 
int32_t x1;			// The following variables are needed to calculate the true pressure
 
int32_t x2;
 
int32_t x3;
 
int32_t b3;
 
uint32_t b4;
 
int32_t b5;
 
int32_t b6;
 
uint32_t b7;
 
int32_t trueTemp;
 
int32_t pressure;
 
uint32_t altitude;
 
 
 
 
void sensors_setupPressure()
 
{
 
	//This function reads in the calibration values from the BMP085.  This is done only once.
 
	ac1 = i2c_read(PRESSURE_ADDR, 0xAA);
 
	ac1 = ac1 << 8;
 
	ac1 = ac1 | i2c_read(PRESSURE_ADDR, 0xAB);
 
	
 
	ac2 = i2c_read(PRESSURE_ADDR, 0xAC);
 
	ac2 = ac2 << 8;
 
	ac2 = ac2 | i2c_read(PRESSURE_ADDR, 0xAD);
 
	
 
	ac3 = i2c_read(PRESSURE_ADDR, 0xAE);
 
	ac3 = ac3 << 8;
 
	ac3 = ac3 | i2c_read(PRESSURE_ADDR, 0xAF);
 
	
 
	ac4 = i2c_read(PRESSURE_ADDR, 0xB0);
 
	ac4 = ac4 << 8;
 
	ac4 = ac4 | i2c_read(PRESSURE_ADDR, 0xB1);
 
	
 
	ac5 = i2c_read(PRESSURE_ADDR, 0xB2);
 
	ac5 = ac5 << 8;
 
	ac5 = ac5 | i2c_read(PRESSURE_ADDR, 0xB3);
 
	
 
	ac6 = i2c_read(PRESSURE_ADDR, 0xB4);
 
	ac6 = ac6 << 8;
 
	ac6 = ac6 | i2c_read(PRESSURE_ADDR, 0xB5);
 
	
 
	b1 = i2c_read(PRESSURE_ADDR, 0xB6);
 
	b1 = b1 << 8;
 
	b1 = b1 | i2c_read(PRESSURE_ADDR, 0xB7);
 
	
 
	b2 = i2c_read(PRESSURE_ADDR, 0xB8);
 
	b2 = b2 << 8;
 
	b2 = b2 | i2c_read(PRESSURE_ADDR, 0xB9);
 
	
 
	mb = i2c_read(PRESSURE_ADDR, 0xBA);
 
	mb = mb << 8;
 
	mb = mb | i2c_read(PRESSURE_ADDR, 0xBB);
 
	
 
	mc = i2c_read(PRESSURE_ADDR, 0xBC);
 
	mc = mc << 8;
 
	mc = mc | i2c_read(PRESSURE_ADDR, 0xBD);
 
	
 
	md = i2c_read(PRESSURE_ADDR, 0xBE);
 
	md = md << 8;
 
	md = md | i2c_read(PRESSURE_ADDR, 0xBF);
 
}
 
 
void sensors_readSpiTemp()
 
{
 
	// Select TEMP wait 100 microseconds then read four bytes
 
	SELECT_TEMP;
 
	_delay_us(100);
 
	uint8_t one = send_spi(0xFF);
 
	_delay_us(100);
 
	uint8_t two = send_spi(0xFF);
 
	_delay_us(100);
 
	uint8_t three = send_spi(0xFF);
 
	_delay_us(100);
 
	uint8_t four = send_spi(0xFF);
 
	DESELECT_TEMP;
 
	
 
	int16_t temperature = ((one<<4)|(two>>4));	// Shift and place into larger int. (Cuts off Decimal)
 
	temperature = (temperature & (0x0800)) ? (temperature & 0xF000) : temperature;	// Sign extend
 
	
 
	//int16_t temperature = ((one<<6)|(two>>2));	// Shift and place into larger int. (Includes Decimal)
 
	//temperature = (temperature & (0x2000)) ? (temperature & 0xC000) : temperature;	// Sign extend
 
	
 
	temperature = (two & 0x01) ? 0x00DE : temperature;	// Error Condition. If error is detected output is set to 222 degrees (0x00DE)
 
	
 
	// Note: Temperature still needs to be scaled in order to be accurate (eg. boil water). Do this before implementing.
 
	spiTemp = temperature;
 
}
 
 
void sensors_readBoardTemp()
 
{
 
	boardTemp = i2c_read(BOARDTEMP_ADDR, 0x00);		// Read only the first byte of data (we don't need the resolution here)
 
	boardTemp = ((boardTemp*18)/10) + (32);			// Converting Celsius to Fahrenheit
 
	boardTemp = boardTemp - 3;						// Linear offset
 
}
 
 
void sensors_readPressure()
 
{
 
	i2c_write(0xEE, 0xF4, 0x2E);				//write 0x2E (temp) into 0xF4 (control register), (write is 0xEE)
 
	i2c_write(PRESSURE_ADDR, 0xF4, 0x2E);				//write 0x2E (temp) into 0xF4 (control register), (write is 0xEE)
 
	_delay_us(4500);							//wait 4.5 ms
 
	ut = i2c_read(PRESSURE_ADDR, 0xF6);
 
	ut = ut << 8;
 
	ut = ut | i2c_read(PRESSURE_ADDR, 0xF7);	//ut = MSB<<8 + LSB
 
	
 
	i2c_write(0xEE, 0xF4, 0x34);				//write 0x34 (pressure) into 0xF4 (control register), (write is 0xEE)
 
	i2c_write(PRESSURE_ADDR, 0xF4, 0x34);				//write 0x34 (pressure) into 0xF4 (control register), (write is 0xEE)
 
	_delay_us(4500);							//wait 4.5 ms
 
	up = i2c_read(PRESSURE_ADDR, 0xF6);
 
	up = up << 8;
 
	up = up | i2c_read(PRESSURE_ADDR, 0xF7);	//up = (MSB<<16 + LSB<<8 + XLSB(NOT USED)) >> (8-oss)
 
	
 
	//calculate true temperature
 
	x1 = ((ut - ac6) * ac5) >> 15;
 
	x2 = (mc << 11) / (x1 + md);
 
	b5 = x1 + x2;
 
	trueTemp = (b5 + 8) >> 4;
 
	
 
	//calculate b3
 
	b6 = b5 - 4000;
 
	x1 = (b2 * (b6 * b6) >> 12) >> 11;
 
	x2 = (ac2 * b6) >> 11;
 
	x3 = x1 + x2;
 
	b3 = ((ac1 * 4 + x3) + 2) / 4;
 
	
 
	//calculate b4
 
	x1 = (ac3 * b6) >> 16;
 
	x2 = (b1 * ((b6 * b6) >> 12)) >> 16;
 
	x3 = ((x1 + x2) + 2) >> 2;
 
	b4 = (ac4 * (x3 + 32768)) >> 15;
 
	
 
	b7 = (up - b3) * 50000;
 
	
 
	if (b7 < 0x80000000)
 
	{
 
		pressure = (b7 << 1) / b4;
 
	}
 
	
 
	else
 
	{
 
		pressure = (b7 / b4) << 1;
 
	}
 
	
 
	x1 = (pressure >> 8) * (pressure >> 8);
 
	x1 = (x1 * 3038) >> 16;
 
	x2 = (-7357 * pressure) >> 16;
 
	pressure += (x1 + x2 + 3791) >> 4;				//This is the final value for our pressure
 
	
 
	//altitude = 44330 * (1 - pow((pressure / 101325), (1 / 5.255)));
 
	altitude = (float)44330 * (1 - pow(((float) pressure/101325), 0.190295));
 
}
 
 
void sensors_readHumid()
 
{
 
	humid = i2c_read16(HUMID_ADDR);
 
	
 
	//calculations to relative humidity: humid = (humid/((2^14) - 1))*100%       >> is divide by power, << is multiply by power, 2^14-1 = 16383
 
	humid = (humid / 16383) * 100;
 
}
 
 
void sensors_readLight()
 
void sensors_readLux()
 
{
 
	// FOR FIRST BYTE:
 
	light = i2c_read(LIGHT_ADDR, 0x03);
 
	// exponent = 8xE3 + 4xE2 + 2xE1 + E0
 
	// mantissa = 8xM7 + 4xM6 + 2xM5 + M4
 
	// light = 2^(exponent)*mantissa*0.72
 
 
	lightH = i2c_read(LIGHT_ADDR, 0x03);
 
	lightL = i2c_read(LIGHT_ADDR, 0x04);
 
	
 
	exponent = lightH;
 
	exponent = exponent >> 4;
 
	
 
	lightH = lightH << 4;
 
	mantissa = lightH | lightL;
 
	//mantissa = mantissa << 4;
 
	//mantissa = mantissa >> 4;
 
	
 
	//lux = (pow(2, exponent) * (float)(mantissa * 0.045));
 
	lux = (float)(pow(2,exponent) * mantissa) * 0.045;
 
	
 
	// FOR BOTH BYTES:
 
	// light = light << 4;
 
	// light = light | (0x0F & i2c_read(LIGHT_ADDR, 0x04));  //  This can be used to read in the 4 LSBs from the second register
 
	// exponent = 8xE3 + 4xE2 + 2xE1 + E0
 
	// mantissa = 128xM7 + 64xM6 + 32xM5 + 16xM4 + 8xM3 + 4xM2 + 2xM1 + M0
 
	// light = 2^(exponent)*mantissa*0.045
 
}
 
 
void sensors_readBatt()
 
{
 
	batt = ADCH;					// Read battery level from ADC
 
}
 
 
int16_t sensors_getSpiTemp(void)	// Gets spi temperature from variable
 
{
 
	return spiTemp;
 
}
 
 
int8_t sensors_getBoardTemp(void)	// Gets board temperature from variable
 
{
 
	return boardTemp;
 
}
 
 
int32_t sensors_getPressure(void)	// Gets pressure from variable
 
{
 
	return pressure;
 
}
 
 
uint16_t sensors_getHumid(void)			// Gets relative humidity from variable
 
{
 
	return humid;
 
}
 
 
uint8_t sensors_getLight(void)		// Gets light from variable
 
uint32_t sensors_getLux(void)		// Gets light from variable
 
{
 
	return light;
 
	return lux;
 
}
 
 
//possibly uint8_t
 
int8_t sensors_getBatt(void)		// Gets battery voltage from variable
 
{
 
	return batt;
 
}
 
 
uint32_t sensors_getAltitude(void)
 
{
 
	return altitude;
 
}
 
\ No newline at end of file
slave/slave/lib/sensors.h
Show inline comments
 
/*
 
 * sensors.h
 
 *
 
 * Created: 11/19/2012 9:24:50 PM
 
 *  Author: kripperger
 
 */ 
 
 
 
#ifndef SENSORS_H_
 
#define SENSORS_H_
 
 
 
void sensors_setupPressure(void);	// Reads pressure calibration values
 
void sensors_readSpiTemp(void);		// Reads spi temperature
 
void sensors_readBoardTemp(void);	// Reads board temperature
 
void sensors_readPressure(void);	// Reads pressure
 
void sensors_readHumid(void);		// Reads humidity
 
void sensors_readLight(void);		// Reads lux
 
void sensors_readLux(void);		// Reads lux
 
void sensors_readBatt(void);
 
 
int16_t sensors_getSpiTemp(void);	// Gets spi temperature from variable
 
int8_t sensors_getBoardTemp(void);	// Gets board temperature from variable
 
int32_t sensors_getPressure(void);	// Gets pressure from variable
 
uint16_t sensors_getHumid(void);	// Gets humidity from variable
 
uint8_t sensors_getLight(void);		// Gets lux from variable
 
uint32_t sensors_getLux(void);		// Gets lux from variable
 
int8_t sensors_getBatt(void);		// Gets battery voltage from variable
 
uint32_t sensors_getAltitude(void);		// Gets altitude from variable
 
 
#endif /* SENSORS_H_ */
 
\ No newline at end of file
slave/slave/modules.c
Show inline comments
 
@@ -78,68 +78,68 @@
 
 void modules_sensors_setup()
 
 {
 
	DESELECT_TEMP;
 
	setup_spi();
 
	sensors_setupPressure();
 
 }
 
  
 
 void modules_geiger_setup()
 
 {
 
	// Pin setup
 
	DDRA &= ~(1 << DDA0);	// PA0 is an input
 
	
 
	
 
	 
 
	// Setup for interrupt input on PA0 (PCINT0)
 
	PCMSK0 |= (1 << PCINT0);	// Enable interrupt for PA0
 
	PCICR |= (1 << PCIE0);		// Enable ioc section PCIF0
 
	
 
	// Setup for interrupt from Timer2
 
	ASSR &= ~(1 << EXCLK);	// Disable external clock input (enabling crystal use)
 
	ASSR |= (1 << AS2);		// Enable timer2 async mode with an external crystal	
 
	_delay_ms(250);			// Let external 32KHz crystal stabilize
 
	TCCR2B = 0x05;			// Set the prescaler to 128: 32.768kHz / 128 = 1Hz overflow
 
	TIFR2 = 0x01;			// Reset timer2 overflow interrupt flag
 
	TIMSK2 = 0x01;			// Enable interrupt on overflow
 
	
 
	sei();					// Enable all interrupts
 
 }
 
  
 
  
 
  
 
 void modules_cameras_setup()
 
 {
 
	  	  
 
 }
 
  
 
 
 void modules_generic()
 
 {
 
	// Gathers data and performs functions for generic daughter board
 
	
 
 }
 
  
 
 void modules_sensors()
 
 {
 
	// Gathers data and performs functions for sensor daughter board
 
	sensors_readBoardTemp();		//Data Read
 
	sensors_readSpiTemp();			//Data Read
 
	//sensors_readPressure();			//Data Read
 
	//sensors_readHumid();				//Data Read
 
	//sensors_readLight();				//Data Read
 
	sensors_readBatt();
 
	sensors_readPressure();			//Data Read
 
	//sensors_readHumid();			//Data Read
 
	sensors_readLux();				//Data Read
 
	sensors_readBatt();				//Data Read
 
	 
 
 }
 
  
 
 void modules_geiger()
 
 {
 
	// No data gatering function needed for geiger daughter board
 
		// This is taken care of in interrupt (See geiger.c)
 
	  
 
 }
 
  
 
 void modules_cameras()
 
 {
 
	// Gathers data and performs functions for cameras daughter board
 
  
 
 } 
 
  
 
\ No newline at end of file
slave/slave/slave.c
Show inline comments
 
@@ -17,108 +17,108 @@
 
#include <inttypes.h>
 
#include <avr/io.h>
 
#include <compat/twi.h>
 
#include <util/delay.h>
 
#include <avr/cpufunc.h>
 
#include <avr/interrupt.h>
 
#include "modules.h"
 
#include "lib/serial.h"
 
#include "lib/serparser.h"
 
#include "lib/led.h"
 
#include "lib/inputOutput.h"
 
#include "lib/i2c.h"
 
#include "lib/spi.h"
 
#include "lib/geiger.h"
 
#include "lib/sensors.h"
 
#include "lib/cameras.h"
 
#include "lib/loopTimer.h"
 
#include "lib/masterComm.h"
 

	
 

	
 

	
 
void micro_setup()
 
{
 
	// Generic microcontroller config options
 
	sei();	// Enable interrupts
 
	
 
}
 

	
 

	
 
int main(void)
 
{
 
	// Initialize		
 
	micro_setup();			// Generic microcontroller config options
 
	time_setup();			// Setup loop timer and interrupts (TIMER0)
 
	led_configure();		// Configure ports and registers for LED operation
 
	io_configure();			// Configure IO ports and registers
 
	i2c_init();				// Setup I2C
 
	serial0_setup();		// Config serial port
 
	
 
	io_readModuleId();
 
	modules_setup(io_getModuleId());				// Run setup functions for specific module
 

	
 
	
 
	//uint8_t test;		//Debug
 
	//uint8_t test2;	//Debug	
 
	
 
	
 
	// Serial output //DEBUG
 
	char buff[64];							//Buffer for serial output //DEBUG
 
	char buff[128];							//Buffer for serial output //DEBUG
 
	serial0_sendString("Starting Slave\r\n");
 
			
 
    while(1)
 
    {	
 
		
 
		// Master communication
 
		masterComm_checkParser();
 
			
 
		
 
		
 
		// Main slave operations
 
		if ((time_millis() % SENSOR_LOOP) == 0)	// Uses program timer to run every so often. Time interval defined in config.h
 
		{
 
			led_on(0);
 
			sensors_readBoardTemp();	// Read board temperature sensor (Common on all slaves) (Data Read)
 
			modules_run(io_getModuleId());		// Runs specific module functions (like data reading)
 
			
 
			io_regulateTemp();			// Gets board temperature and enables heater if below threshold
 

	
 
			//snprintf(buff,64,"|ModuleID: %u |BoardTemp: %i |Millis: %lu |SpiTemp: %i\r\n",io_getModuleId(),sensors_getBoardTemp(),time_millis(),sensors_getSpiTemp()); //DEBUG
 
			//serial0_sendString(buff); //DEBUG
 
			snprintf(buff,128,"|ModuleID: %u |BoardTemp: %i |Heater: %u |Millis: %lu |Lux: %lu |Pressure: %lu |Altitude: %lu \r\n",io_getModuleId(),sensors_getBoardTemp(),io_heaterStatus(),time_millis(),sensors_getLux(),sensors_getPressure(),sensors_getAltitude()); //DEBUG
 
			serial0_sendString(buff); //DEBUG
 

	
 
			_delay_ms(2);		// Delay to prevent the sensor loop from running again before time_millis changes
 
			led_off(0);
 
			led_off(2);
 
		}
 

	
 
    }
 
	
 
	return 0;
 
}
 

	
 

	
 

	
 

	
 

	
 
		/********Examples of data reading and getting******************
 
		x = geiger_getCpm();				//Data get
 
		x = sensors_getSpiTemp();			//Data get
 
		x = sensors_getBoardTemp();			//Data get
 
		
 
		sensors_readSpiTemp();				//Data Read
 
		sensors_readBoardTemp();			//Data Read
 
		
 
		led_output(0xFF);					//Output value to LED array
 
		i2c_write(RTC_ADDR, 0x05, 0x3A);	//i2c Write Example
 
		
 
		PORTA &= ~(1 << PA1);	//OFF
 
		PORTA |= (1 << PA1);	//ON
 
		PORTB ^= (1 << PB0);	//Toggle
 
		
 
		sprintf(buff, "log: %u,%u,%u,%u\r\n", temp,temp2,temp3,temp4);
 
		serial0_sendString(buff);
 
		
 
		**************************************************************/
 
		
 
		
 
		
 
		
 
\ No newline at end of file
0 comments (0 inline, 0 general)