Example #1
0
void advancedConfig() {
	
	while(1) {
	
		menuMax = 1;
		selectedMenu = NOT_SELECTED;
		currentMenu = 0;

		while(selectedMenu == NOT_SELECTED) {
			if (currentMenu == 0) { // DWELL
				greenOn();
				delay_ms(50);
				greenOff();
				redOn();
				delay_ms(50);
				redOff();
				
				delay_ms(800);
			} else if (currentMenu == 1) { // DEBOUNCE 2
				for (uint8_t i = 0; i < 2; i++) {
					greenOn();
					delay_ms(50);
					greenOff();
					redOn();
					delay_ms(50);
					redOff();
					delay_ms(100);
				}

				delay_ms(700);
			}
		}
	
		if (selectedMenu == 0) { // DWELL
			// Max is set high to prevent wrapping around to 0 without the user knowing
			getNumberFromUser(USER_DWELL, 255);
	
			// Dwell was entered into selectedMenu.  Verify it and save it.
			if (selectedMenu >= 2 && selectedMenu <= 20) {
				eeprom_write_byte(&EEPROM_USER_DWELL, selectedMenu);
				USER_DWELL = selectedMenu;
				successBlink();
			} else {
				failureBlink();
			}
		} else { // DEBOUNCE
			// Max is set high to prevent wrapping around to 0 without the user knowing
			getNumberFromUser(USER_DEBOUNCE, 255);
		
			// Debounce was entered into selectedMenu.  Verify it and save it.
			if (selectedMenu >= 5 && selectedMenu <= 50) {
				eeprom_write_byte(&EEPROM_USER_DEBOUNCE, selectedMenu);
				USER_DWELL = selectedMenu;
				successBlink();
			} else {
				failureBlink();
			}
		}	
	}			
}
Example #2
0
void presetMenu() {

	// SELECTOR
	currentSelector = 0;
	menuMax = 1;
	selectedMenu = NOT_SELECTED;
	currentMenu = 0;

	while(selectedMenu == NOT_SELECTED) {
		if (currentMenu == 0) { // Preset 1
			redOn();
			delay_ms(100);
			redOff();
			delay_ms(800);
		} else if (currentMenu == 1) { // Preset 2
			for (uint8_t i = 0; i < 2; i++) {
				redOn();
				delay_ms(100);
				redOff();
				delay_ms(100);
			}

			delay_ms(700);
		}
	}

	currentSelector = selectedMenu;

	////////

	menuMax = 2;
	selectedMenu = NOT_SELECTED;
	currentMenu = 0;
	while(selectedMenu == NOT_SELECTED) {
				
		if (currentMenu == 0) { // Preset 1
			orangeLed();
			delay_ms(800);
		} else if (currentMenu == 1) { // Preset 2
			for (uint8_t i = 0; i < 2; i++) {
				orangeLed();
				delay_ms(100);
			}
			
			delay_ms(800);
		} else if (currentMenu == 2) {  // Preset 3
			for (uint8_t i = 0; i < 3; i++) {
				orangeLed();
				delay_ms(100);
			}
			
			delay_ms(800);
		}
	}
	
	CURRENT_PRESET[currentSelector] = selectedMenu;
}
Example #3
0
void mainMenu() {
	menuMax = 4;
	selectedMenu = NOT_SELECTED;
	currentMenu = 0;
	bool state = false;
	while(selectedMenu == NOT_SELECTED) {
		if (currentMenu == 0) { // Firing Mode (toggle green then red)
			state = !state;
			
			redSet(!state);
			greenSet(state);
						
			delay_ms(100);
		} else if (currentMenu == 1) { // Firing Rate (fast green blink)
			state = !state;
			
			redOff();
			greenSet(state);
			
			delay_ms(50);
		} else if (currentMenu == 2) {  // Burst size (three red blinks)
			lightsOff();
			
			// Display as three blinks of red then pause and repeat
			for (uint8_t i = 0; i < 3; i++) {
				redOn();
				delay_ms(100);
				redOff();
				
				if (i == 2) {
					for (uint8_t i = 0; i < 100; i++) {
						delay_ms(10);
						
						if (selectedMenu != NOT_SELECTED) {
							break;
						}
					}					
				} else {
					delay_ms(100);
				}
			}
		} else if (currentMenu == 3) {  // Ammo Limit (Solid Red)
			redOn();
			greenOff();
		} else if (currentMenu == 4) {  // Safety Shot (Solid Green)
			redOff();
			greenOn();
		}			
	}
}
Example #4
0
void redSet(bool state) {
	if (state) {
		redOn();
	} else {
		redOff();
	}
}
Example #5
0
void failureBlink() {
	delay_ms(200);
	for (uint8_t i = 0; i < 10; i++) {
		redOn();
		delay_ms(50);
		redOff();
		delay_ms(50);
	}
}
Example #6
0
void orangeLed() {
	for (uint8_t x = 0; x < 33; x++) {
		greenOn();
		delay_ms(2);
		redOn();
		
		greenOff();
		delay_ms(1);
		redOff();
	}	
}
Example #7
0
void successBlink() {
	for (uint8_t i = 0; i < 3; i++) {
		for (uint8_t x = 0; x < 200; x++) {
			greenOn();
			delay_ms(2);
			redOn();
			greenOff();
			delay_ms(1);
			redOff();
		}
	}
}
Example #8
0
void main_loop(){

	unsigned char message[5];
	int count = 0;
	//pwmCounter = 0;
	//parse and execute loop
	while (1)
    {

    	if (UARTCharsAvail(UART0_BASE)){
    		if(count==0){
    			message[0] =  UARTCharGet(UART0_BASE);	//grab first byte
    			//toggle();
    		}
    		if(count==1){
    			message[1] = UARTCharGet(UART0_BASE);
    			//toggle();
    		}
    		if(count==2){
    			message[2] = UARTCharGet(UART0_BASE);
    			//toggle();
    		}
    		if(count==3){
    			message[3] = UARTCharGet(UART0_BASE); //grab last byte
    			//toggle();
    		}
    		if(count==4){
    			message[4] = UARTCharGet(UART0_BASE); //grab CRC
				if (crc8(0,message,4)==message[4]){
					UARTCharPut(UART0_BASE, 0xFF);	//CRC good (tell python end that)
					parseAndExecute(message);
				}else{
					UARTCharPut(UART0_BASE, 0x00);	//CRC bad
					redOn();
				}
    		}

    		count = count + 1;
    		if(count == 5)
    				count = 0;

    	}
    }
}
void Traffic_Light::allOn() {
  redOn();
  yellowOn();
  greenOn(); 
}
Example #10
0
int main(void) {

	TCCR0B |= (1 << CS01);  // Enable timer with 1/8th prescale
	TIMSK0 |= 1 << OCIE0A; // Configure Timer0 for Compare Match
	OCR0A = 255; // Match at 200
	
	sei();  // Enable global interrupts
	
	initialize();
	
	DDRA |= (1 << PINA1); // Pin 12 - Red LED
	DDRA |= (1 << PINA2); // Pin 11 - Green LED
	DDRA |= (1 << PINA7); // Pin 6  - Solenoid
	
	DDRB &= ~(1 << PINB1); // Pin 3 - Push button
	DDRB &= ~(1 << PINB2); // Pin 5 - Trigger Pin 1
	DDRA &= ~(1 << PINA6); // Pin 7 - Trigger Pin 2

	// Other unknown pins
	//DDRA |= (1 << PINA0); // Pin 13
	//PORTA |= (1 << PINA0); // 13 - HIGH
#ifdef X7CLASSIC
	DDRA |= (1 << PINA3); // Pin 10 - Power pin
	PORTA |= (1 << PINA3); // 10 - HIGH
#endif
	//PORTA &= ~(1 << PINA4);	// 9 - LOW
	//PORTA &= ~(1 << PINA5);	// 8 - LOW
	
	// Set Triggers HIGH
	PORTB |= (1 << PINB2);
	PORTA |= (1 << PINA6);
	
	// Set Pushbutton HIGH
	PORTB |= (1 << PINB1);

#ifdef X7CLASSIC
	// Selector switch on pin 2
	DDRB &= ~(1 << PINB0); // Pin 2
	PORTB |= (1 << PINB0); // Pin 2 set HIGH
#endif

	// If the trigger is held, don't do anything until it's release
	while (macHold()) {
		// Show the Red LED as solid
		redOn();
	}

	// If the button is held during startup, enter config mode.
	uint16_t buttonHeldTime = 0;
	bool configMode = false;
	while ((PINB & (1 << PINB1)) <= 0) {
		delay_ms(1);
		
		// Prevent overflow
		buttonHeldTime++;
		if (buttonHeldTime > 20000) {
			buttonHeldTime = 20000;
		}
	}
	
	if (buttonHeldTime >= 1000) {
		configMode = true;
	}

#ifdef DWELL_DEBOUNCE
    bool advancedMenu = 0;
	if (buttonHeldTime >= 10000) {
		advancedMenu = 1;
	}
#endif
	
	if (configMode) {
		// Initialize interrupts for the menu system
		PCMSK1 |= (1 << PCINT10);  //Enable interrupts on PCINT10 (trigger)
		PCMSK1 |= (1 << PCINT9);  // Enable interrupts for the push button
		GIMSK = (1 << PCIE1);    //Enable interrupts period for PCI0 (PCINT11:8
		
#ifdef DWELL_DEBOUNCE
		if (advancedMenu) {
			advancedConfig();
		} else {
			handleConfig();
		}		
#else
		handleConfig();
#endif				
	} else { // Normal run mode
		for (;;) {
			// This prevents time from changing within an iteration
			trigger_run(&millis);
			pushbutton_run(&millis);
		}
	}		
}
static void TaskSerialCmdProc(void) {

  uartInit();

  uint16_t uint16;

  while( true ) {

    Sys_WaitSemaphore(hSerial, 153);
    if( SysWaitTimedOut(hTaskSerialCmdProc) == false ) {

      // pkt is ready to parse
      rxPktCnt++;

      switch( buffer[0] ) {
        case SERCMD_LEDON:
          redOn();
          buffer[1] = '0';
          buffer[2] = '\n';
          break;
        case SERCMD_LEDOFF:
          redOff();
          buffer[1] = '0';
          buffer[2] = '\n';
          break;
        case SERCMD_CHKBUSY:
          buffer[1] = '0';
          buffer[2] = '0'+injIsBusy();
          buffer[3] = '\n';
          break;
        case SERCMD_GETCYCLES:
          buffer[1] = '0'+injGetCycles(&uint16);
          uitoa_hex(&buffer[2], uint16, 4);
          buffer[6] = '\n';
          break;
        case SERCMD_SETCYCLES:
          uint16 = atoui_hex(&buffer[1]);
          buffer[1] = '0'+injSetCycles(&uint16);
          buffer[2] = '\n';
          break;
        case SERCMD_GETACCCYCLES:
          buffer[1] = '0'+injGetAccumulatedCycles(&uint16);
          uitoa_hex(&buffer[2], uint16, 4);
          buffer[6] = '\n';
          break;
        case SERCMD_SETACCCYCLES:
          uint16 = atoui_hex(&buffer[1]);
          buffer[1] = '0'+injSetAccumulatedCycles(&uint16);
          buffer[2] = '\n';
          break;
        case SERCMD_START:
          buffer[1] = '0'+injStart();
          buffer[2] = '\n';
          break;
        case SERCMD_SETONWIDTH:
          uint16 = atoui_hex(&buffer[1]);
          buffer[1] = '0'+injSetOnWidth(&uint16);
          buffer[2] = '\n';
          break;
        case SERCMD_GETONWIDTH:
          buffer[1] = '0'+injGetOnWidth(&uint16);
          uitoa_hex(&buffer[2], uint16, 4);
          buffer[6] = '\n';
          break;
        case SERCMD_ABORT:
          buffer[1] = '0'+injAbort();
          buffer[2] = '\n';
          break;
        case SERCMD_GETOFFWIDTH:
          buffer[1] = '0'+injGetOffWidth(&uint16);
          uitoa_hex(&buffer[2], uint16, 4);
          buffer[6] = '\n';
          break;
        case SERCMD_SETFPPWM:
          uint16 = atoui_hex(&buffer[1]);
          buffer[1] = '0'+fpSet(&uint16);
          buffer[2] = '\n';
          break;
        case SERCMD_GETFPPWM:
          buffer[1] = '0'+fpGet(&uint16);
          uitoa_hex(&buffer[2], uint16, 4);
          buffer[6] = '\n';
          break;
        default:
          errors++;
          buffer[1] = 'F';
          buffer[2] = '\n';
          break;
      }

      // buffer already contains response, trigger
      // a send and wait for it to complete
      pie1.TXIE = true;       // goes straight to int and loads the first item
      Sys_WaitSemaphore(hSerial, 153);

      if( SysWaitTimedOut(hTaskSerialCmdProc) == false ) {
        txPktCnt++;
      } else {
        // tx never finished - got a timeout
        errors++;
      }

    }
  }
}
Example #12
0
void firingModeMenu() {
	menuMax = 3;
	selectedMenu = NOT_SELECTED;
	currentMenu = FIRING_MODE;
	bool state = LOW;
	while(selectedMenu == NOT_SELECTED) {
		if (currentMenu == 0) {
			state = !state;
			
			redSet(state);
			greenOff();
			
			delay_ms(50);
		} else if (currentMenu == 1) { // Three Round Burst
			lightsOff();
			
			// Display as three blinks of green then pause and repeat
			for (uint8_t i = 0; i < 3; i++) {
				greenOn();
				delay_ms(100);
				greenOff();
				
				if (selectedMenu != NOT_SELECTED) {
					break;
				}
				
				if (i == 2) {
					delay_ms(1000);
				} else {
					delay_ms(100);
				}
			}				
		} else if (currentMenu == 2) { // Auto Response
			lightsOff();
	
			// Display as blink green, blink red, then pause
			greenOn();
			delay_ms(100);
			greenOff();
			delay_ms(100);
			redOn();
			delay_ms(100);
			redOff();

			if (selectedMenu != NOT_SELECTED) {
				break;
			}
		
			delay_ms(1000);
		} else if (currentMenu == 3) { // Auto Response
			redOff();
			greenOn();
		}
	}
	
	if (selectedMenu >= 0 && selectedMenu <= 3) {
		eeprom_write_byte(&EEPROM_FIRING_MODE[currentSelector][CURRENT_PRESET[currentSelector]], selectedMenu);
		successBlink();
	} else {
		failureBlink();
	}
}
Example #13
0
void presetMenu() {

#ifdef X7CLASSIC
/************************************************************************/
/* This is used for the X7 classic to distinguish between F and FA      */
/************************************************************************/
	// SELECTOR
	currentSelector = 0;
	menuMax = 1;
	selectedMenu = NOT_SELECTED;
	currentMenu = 0;

	while(selectedMenu == NOT_SELECTED) {
		if (currentMenu == 0) { // Preset 1
			redOn();
			delay_ms(100);
			redOff();
			delay_ms(800);
		} else if (currentMenu == 1) { // Preset 2
			for (uint8_t i = 0; i < 2; i++) {
				redOn();
				delay_ms(100);
				redOff();
				delay_ms(100);
			}

			delay_ms(700);
		}
	}

	currentSelector = selectedMenu;

	////////
#endif
	menuMax = 2;
	selectedMenu = NOT_SELECTED;
	currentMenu = 0;
	while(selectedMenu == NOT_SELECTED) {
				
		if (currentMenu == 0) { // Preset 1
			orangeLed();
			delay_ms(800);
		} else if (currentMenu == 1) { // Preset 2
			for (uint8_t i = 0; i < 2; i++) {
				orangeLed();
				delay_ms(100);
			}
			
			delay_ms(800);
		} else if (currentMenu == 2) {  // Preset 3
			for (uint8_t i = 0; i < 3; i++) {
				orangeLed();
				delay_ms(100);
			}
			
			delay_ms(800);
		}
	}

#ifdef X7CLASSIC
	CURRENT_PRESET[currentSelector] = selectedMenu;
#else
	CURRENT_PRESET = selectedMenu;
#endif
}