AnalogStick* AnalogStick::createStick(const std::string &stickImageName,
                                      const std::string &outerImageName,
                                      const Vec2 &pos)
{
    auto layer = AnalogStick::create();
    if (layer != nullptr) {
        layer->stickInit(stickImageName, outerImageName, pos);
        return layer;
    }
    CC_SAFE_DELETE(layer);
    return nullptr;
}
Exemple #2
0
int main(void) {
	// Setup pins
	DDRB = 0x00;	// All pins inputs
	DDRC = 0x07;	// PC0,1,2 as outputs for the LEDs
	DDRD = 0x0b;	// PD0 as output for LED, PD1 for TXD, PD3 for buzzer
	
	PORTD = 0xe0;	// Pullups for switches
	PORTB = 0x3f;	// Pullups for switches
	
	// LEDs
	LEDOff();
	
	// ADC
	ADMUX = 0x4f; // start off with mux on internal input
	ADCSRA = 0x80; // ADC EN
	DIDR0 = 0x38; // disable digital buffers on ADC pins
	
	// Timer
	TCCR0A = 0x00;  // Normal mode
	TCCR0B = 0x03;  // prescaler at 64 results in 125kHz ticks
	
	// UART
	cli(); // disable global interrupts

	stickInit(); // initialise stick input
	
	spektrumInit();
	
	// Get startup mode
	trainerPlugged = TRAINERPIN;
	bindSwitch = BINDPIN;
	transmitMode = 0;
	if(trainerPlugged == 0) transmitMode = eTM_trainer_master; // fixme or trainer slave, if PPM signal present

	if(bindSwitch == 0) transmitMode = eTM_bind;
	
	// Timer loop!
	static uint8_t fastScaler = 255;
	static uint8_t slowScaler = 255;
	static uint16_t secondScaler = 0xffff;
	
	// Buzzer
	TCCR2B = 0x03; // prescaler at 64
	stopNote();
	noteBuffer[0] = NOTE6G;
	noteBuffer[1] = NOTE6GS;

	noteBuffer[2] = NOTESTOP;
	noteCounter = 0;
	noteInterruptable = 0;
	

	
	while(1) {
		
		
		while(TCNT0 < FASTLOOPCOUNT)
		{
			if(TCNT0 < FASTLOOPCOUNT && TCNT0 >= FASTLOOPCOUNT-LED0Duty/3) LED0On(); // red LED too bright, reduce duty
			if(TCNT0 < FASTLOOPCOUNT && TCNT0 >= FASTLOOPCOUNT-LED1Duty) LED1On();
			if(TCNT0 < FASTLOOPCOUNT && TCNT0 >= FASTLOOPCOUNT-LED2Duty) LED2On();
			if(TCNT0 < FASTLOOPCOUNT && TCNT0 >= FASTLOOPCOUNT-LED3Duty) LED3On();
		}
		TCNT0 = 0; // reduce jitter by resetting soon (SPEKTRUM does not like jitter!)
		LEDOff();
		
		// should be going at about 625Hz
		getDigital();
		stickGetRawADC(rawstickvalues);
		
	
		if(++fastScaler >= OVERSAMPLE) //should be 22ms for DSMX (Nano Board can not handle it faster!!)
		{ 
			fastScaler = 0;
			
			// this loop runs slower than 50Hz
			fastLoop();
			/*throVoltage = 0;
			ruddVoltage = 0;
			elevVoltage = 0;
			aileVoltage = 0;*/
			rawstickvalues[0]=0;
			rawstickvalues[1]=0;
			rawstickvalues[2]=0;
			rawstickvalues[3]=0;
			
			if(++slowScaler >= 6) 
			{ // should be going at about 10Hz
				slowScaler = 0;
				slowLoop();
			}
		}
		
		// we are here every 2ms
		if(++secondScaler >=500)
		{
			// every second
			secondScaler=0;
			IdleSeconds++;
			if(auxSwitch && mixToggle)
			{	
				FlySeconds++;
					
				if(FlySeconds == FLYSECONDS_MAX)
					oneTone(NOTE7B);
				if(FlySeconds == FLYSECONDS_MAX+10)
					twoTone(NOTE7C);
			
				if(IdleSeconds >= FLYSECONDS_MAX*2)
				{
					twoTone(NOTE7C);
				}
			}
		}
	}
}