Example #1
0
//#START_FUNCTION_HEADER//////////////////////////////////////////////////////
//#	
//# Description: 	Initialization function.  Configures IO pins, enables interrupts.
//#					Heartbeat checks the accelerometers and determines if there are 1
//#					or 2 active (in case we unstuff the second one in future) and sets.
//#					the device into factory mode.  In debug, it can print out initialization stats.
//#
//# Parameters:		None
//#
//# Returns: 		Nothing
//#
//#//END_FUNCTION_HEADER////////////////////////////////////////////////////////
	void setup()
	{
		pinMode(LED, OUTPUT);
		pinMode(SAME_BLE, INPUT);
		pinMode(INT1_ACC, INPUT);
		pinMode(INT2_ACC, INPUT);
		pinMode(INT_BLE, INPUT);
		
#ifdef RDV_DEBUG
		Serial.begin(115200);
		while(!Serial);
#endif
		
		sei();								//ENABLE EXTERNAL INTERRUPT FOR WAKEUP
		got_slp_wake = false;
		got_data_acc = false;
		got_int_ble = false;
		both_acc = false;
		_sleep_inactive = false;
		_sleep_active = false;
		
		intCount = 0;
		
		// WHO_AM_I should always be 0x2A
		accel_on = acc1.readRegister(WHO_AM_I) == 0x2A;
		both_acc = acc2.readRegister(WHO_AM_I) == 0x2A;
		
#ifdef RDV_DEBUG
		if(accel_on)
		{
			Serial.println("MMA8452Q is on-line...");
		}
		else
		{
			Serial.print("Could not connect to MMA8452Q");
		}
#endif
		
#ifdef RDV_DEBUG	
		Serial.println("WELCOME TO CYCLEAT...");
		Serial.println("+++++++++++++++++++++++++++++");
		long tempVcc = read_vcc();
		Serial.print("Power Level At: ");
		Serial.print(tempVcc / 1000);
		Serial.print(".");
		Serial.print(tempVcc % 1000);
		Serial.println("V");
		Serial.print("ACC ODR: ");
		Serial.println(f_odr);
		Serial.print("ACC 1: ");
		Serial.print(accel_on);
		Serial.print("\t");
		Serial.print("ACC 2: ");
		Serial.println(both_acc);
		Serial.println("+++++++++++++++++++++++++++++");
		Serial.println("Setting into factory mode...");
		delay(2500);
#endif
		set_factory_mode();
	}
Example #2
0
int main ()
{
	// Disable the ADC
	disable_adc();

	// Watchdog timer reset safety check
	wdt_reset_safety();
	
	// Initialise watchdog timer
	init_wdt();

	// Identify input and output pins
	init_pins();

	// Buffer for text
	char s[20];

	// Setup direction and port for debug logging
	STX_PORT |= 1<<STX_BIT;
	STX_DDR |= 1<<STX_BIT;

	// Initialise DSP
	int i = 0;
	for (; i < MAX_READINGS; i++) readings[i] = 0;

	for (;;)
	{
		// Go to sleep
		sleep_avr();
		
		// Read VCC and convert to base 10 number
		long vcc = read_vcc();

		dsp(vcc);
		utoa(average, s, 10);

		// Output VCC to soft serial PIN STX_BIT
		sputs(s);
		sputs("\n\r");

		if (average > FULL_CHARGE_MV)
		{
			init_wdt_05s();
			blink();
		}
		else init_wdt();	
	}
}
Example #3
0
int main (void) {
	uint8_t j;

	aes128_ctx_t ctx; /* the context where the round keys are stored */
	aes128_init(key, &ctx); /* generating the round keys from the 128 bit key */

	wakeup_init();

	sei(); //Activate interrupts

	rfm70_init();

	j = 0;

	while(1) {
		set_sleep_mode(SLEEP_MODE_IDLE);
		sleep_mode();

		if (interrupt_flag == 1) {
			interrupt_flag = 0;
			rfm70_mode_transmit();
			rfm70_power(3);
			_delay_ms(50);
			read_vcc(); //setup the ADC
			data.info.type = 1;
			data.info.vcc = vcc;
			data.info.vcc_factor = VCC_SCALE_FACTOR;
			data.info.tempreture = 0;
			for (uint8_t i=0;i<11;i++) {
				data.info.data[i] = 0;
			}
			aes128_enc(data.raw, &ctx); /* encrypting the data block */
			rfm70_transmit_message( data.raw, 16 );
			_delay_ms(100);
			rfm70_mode_powerdown();
		}
	}
   
	return 0;
}