void airdrums_stick(void){

    //initial setup
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT

    P1SEL &= 0;
    P1SEL2 &= 0;
    P1SEL |= BIT6 + BIT7; // Assign I2C pins to USCI_B0
    P1SEL2|= BIT6 + BIT7; // Assign I2C pins to USCI_B0

    // LED pin
    P1DIR |= 0x01;
    P1OUT = 0x00;

    // start up i2c bus
    init_i2c();

    //intialise some globals
    highCount = 0;
    isDown = FALSE;
    driftCount=0;

    // Give the nrf plenty of time to start up;
    // it gets pissy if you talk to it too early.

    __delay_cycles(10000);
    nrfInit();
    __delay_cycles(10000);
    // Start TX with address '!'.
    // Hard coded because why not
    nrfStartTX('!');
    __delay_cycles(10000);

    //transmit stuff to set up mpu6050
    //set sensitivity levels
    MPU6050_write_byte(MPU6050_GYRO_CONFIG, MPU6050_FS_SEL_2000);
    MPU6050_write_byte(MPU6050_ACCEL_CONFIG, MPU6050_AFS_SEL_16G);

    //wake sensor up by clearing sleep bit
    MPU6050_write_byte (MPU6050_PWR_MGMT_1, 0);

    // initialise circular buffer
    circ_init();

    // Do some quick and dirty drift correction
    findDrift();

    // Set up timer interrupts for main loop
    CCTL0 = CCIE;                    // CCR0 interrupt enabled
    TACTL = TASSEL_2 + MC_1 + ID_3;  // SMCLK/8, upmode
    CCR0 =  (1000000 / 8 / PROCESS_RATE_HZ); // Set process rate
    // CCR0 = 417; // 300 Hz

    _BIS_SR(CPUOFF + GIE); // Enter LPM0 w/ interrupt
    while(1);
}
Example #2
0
void enblt_loadValues(EnemyBullet *blt) {
	blt->x = enbltInitVals.px;
	blt->y = enbltInitVals.py;
	blt->radius = enbltInitVals.radius;
	blt->damage = enbltInitVals.damage;
	blt->frames = enbltInitVals.frames;
	blt->curframe = blt->animframespast = 0;
	blt->animdelay = enbltInitVals.animdelay;
	blt->dead = false;
	circ_init(&blt->hitbox, (blt->x + blt->radius), (blt->y + blt->radius), blt->radius);
	blt->images = (ALLEGRO_BITMAP **)malloc(enbltInitVals.frames + sizeof(ALLEGRO_BITMAP *));
	for (int i = 0; i < blt->frames; i++) {
		std::stringstream out;
		out << i;
		std::string filename = "enemybullets/" + enbltInitVals.type + "/" + out.str() + ".png";
		blt->images[i] = dx_getGame()->resources.get_image(filename);
	}
}