Exemple #1
0
//-----------------------------------------------------------------------------
// Main function
//-----------------------------------------------------------------------------
int main(void) {

	WDT_INIT();
	InitMCU();
	initRotary();
	InitUART();
	timer_init();
	rotary__GetValue();
	nRF24L01_Initial();

	// initialize dmx driver
	MDP_SendDimmingReqToMDP(0xff, 0xFF);

	//DMX512Send();
	PORTC = 0x00;

	TCCR1A = 0x00;
	TCCR1B = 0x06;
	TCNT1H = 0xFF;
	TCNT1L = 0xFF;

	TIMSK |= 0x04;

	ZRMSendSetPreconfig(0x15);
	MSLEEP(100);
	ZRMSendReset();
	MSLEEP(1000);

	timer_set(ON_WTD_TIMER_ID, 500);
	timer_set(ON_TEST_TIMER_ID, 3000);

	timer_set(ON_ZIGBEE_PING_TIMER_ID, 3000);
	timer_set(ON_ONTIME_TIMER_ID, 100);
	timer_set(NCP_TIMER_ID, 2000);

	tmp_zrmp.zrm_State = ZRM_INIT;

	xcps_init_zigbee(USART0_Receive, USART0_Transmit);
	xcps_init_rs485(USART1_Receive, USART1_Transmit);
//	FILE mystdout =
	TX_Mode(0);
//			FDEV_SETUP_STREAM((void *)USART0_Transmit, NULL, _FDEV_SETUP_WRITE);
//	stdout = &mystdout;
//
//	DEBUG("\n\r=========START PROGRAM ===========\n\r");
	while (1) {
		ledTask();
		ZigbeeUsartTask();
		NCP_Task();
	}

	return 0;
}
int main(void)
{
	//some setup code
	storePin(1337); //only once needed
	initPincode();
	//initizialize power controle pins
	initPowerControle();
	//initizialize rotary.
	initRotary();
	//initialize shifter.
	initShifter();
	//initialize display code.
	initDisplay();
	//initialize serial comm
	init_uart();
	//initialize the servo code.
	initServo();
	//initialize time code
	initTime();
	//main loop.
	DDRB  |= (1<<PB4)|(1<<PB5);
	PORTB |= (1<<PB5)|(1<<PB4);
	while(1)
	{
		//get the input from user for pincode
		getInputPinCode();
		//if there is new data we check to see the commands.
		if(serial_available)
		{
			serial_available = 0;
			runSerialInputCommands(inputStr);
		}
		//check the servo state, disable it when it's active
		//for longer then a second.7
		if(isServoActive) //check to see if the state of the servo is active.
		{
			if(time-previousServo > timeScale)//see if a second has passed
			{
				if(finalServoPos != getCurrentServoState())
				{
					setServoPos(finalServoPos);
				}
				else
				{
					disableServo();
				}
			}
		}
		
		//send number if logged in and ticks changed and rotary has turned.
		//to prevent spam
		if(rotary_has_turned && ticks != previous_ticks && isLoggedIn)
		{
			previous_ticks = ticks;
			rotary_has_turned = 0;
			sendNumber(pin);
		}
		
		if(timeinSeconds >= 360)
		{
			powerOff();
		}
		else
		{
			powerOn();
		}
		
		//if pin is correctly set set green led, else red on.
		if(pin == actual_pin)
		{
			open();
			PORTB |= (1<<PB5);
			PORTB &= ~(1<<PB4);
		}
		else
		{
			if(!timeinSeconds%2)
				close();
			PORTB |= (1<<PB4);
			PORTB &= ~(1<<PB5);
		}
	}
	
	return 1;
}
Exemple #3
0
int main() {

    char t[2];
    char pos[2];
    DelayInit();                             //initializations and state resets
    OledInit();
    Timer2Init();
    initLEDs();
    initButtons();
    initRotary();
    setLEDstate(0);
    unsigned int time = 0;

    OledClearBuffer();                        //the OLED is cleared
    OledSetCursor(0, 0);                      //OLED cursor reset to first line
    OledPutString("ECE 2534 Lab 2");          //message displayed
    OledSetCursor(0, 1);                      //cursor moves to second line
    OledPutString("Thomas Yu");               //message displayed
    OledSetCursor(0, 2);                      //cursor moves to third
    OledPutString("LOCKED");                  //message displayed
    OledSetCursor(0, 3);                      //cursor moves to third
    OledPutString("0");                       //message displayed
    OledUpdate();

    while (1)
    {
        OledSetCursor(0, 3);                      //cursor moves to third
        sprintf(pos, "%-2d", state);              //state(int) converted to string
        OledPutString(pos);                       //message displayed
        OledUpdate();

        if (go == 1)
        {
            sec1000 = 0;                          //time reset
            while (sec1000 < 15000)               //increments for 15000 ms, or 15 secs
            {
                OledSetCursor(0, 3);                      //cursor moves to third
                sprintf(pos, "%-2d", state);
                OledPutString(pos);                       //current state updated
                OledUpdate();

                OledSetCursor(14,3);                        //the countdown is updated
                sprintf(t, "%-2u", (15 - (sec1000/1000)));  //the current time left in seconds is the
                OledPutString(t);                           //elapsed ms subtracted from 15000
                OledUpdate();

                if (unlocked == 1)
                {
                    setLEDstate(1);                         //if unlocked then the led is turned on
                    OledSetCursor(14,3);
                    OledPutString("  ");                    //the countdown is cleared
                    OledSetCursor(0,2);
                    OledPutString("OPEN  ");                //open is displayed
                    OledUpdate();

                    while (!getButtonState())               //this runs until button1 is pressed
                    {
                        OledSetCursor(0, 3);                // this block of code continues to update
                        sprintf(pos, "%-2d", state);        //the rotary position as it is moved
                        OledPutString(pos);                       
                        OledUpdate();
                    }

                    OledSetCursor(0,2);                     //after button1 is pressed, the lock is reset
                    OledPutString("LOCKED");
                    setLEDstate(0);
                    go = 0;
                    unlocked = 0;
                    r1 = 0;
                    lock = 0;
                }
            }

            if ( go != 0)                             //if go was never set back to zero, then the
            {                                         //correct combination was never entered
                unsigned int a = sec1000;             //and the timer ran out
                while (sec1000 < a + 1000)            //this while loop runs for 1 second
                {
                    OledSetCursor(7,3);               //Time Out! is displayed for the duration
                    OledPutString("Time Out!");
                    OledUpdate();
                }
                OledSetCursor(7,3);                   //Time Out! is cleared and the lock is reset
                OledPutString("         ");
                OledUpdate();
                go = 0;
                r1 = 0;
                lock = 0;
            }
            
        }
    }


   return 0;
}