void wiimote_extension_controller() {
	/* LED DEBUG */
	//PORTD &= ~(1<<4); // S3 low
	//DDRD  |= (1<<4); // S3 output

	resetDrumData();
	wm_init((uchar*)drumDeviceID, (uchar*)&data, (uchar*)drumCalibrationData, sizeof(drumCalibrationData));
	wm_newaction((void*)&data);

	while(1) {
		readJoystickSwitch();
		readInputWiiDrum();
		wm_newaction((uchar*)&data);
	}
}
예제 #2
0
void wm_init(unsigned char * id, unsigned char * button_data, unsigned char * cal_data, unsigned int cal_data_length/*, void (*function)(void)*/)
{
	/*
	// link user function
	wm_sample_event = function;
	*/

	// start state
	wm_newaction(button_data);
	twi_reg[0xF0] = 0; // disable encryption

	// set id
	for(unsigned int i = 0, j = 0xFA; i < 6; i++, j++)
	{
		twi_reg[j] = id[i];
	}

	// set calibration data
	for(unsigned int i = 0, j = 0x20; i < cal_data_length; i++, j++)
	{
		twi_reg[j] = cal_data[i];
	}

	/*
	// initialize device detect pin
	dev_detect_port &= 0xFF ^ _BV(dev_detect_pin);
	dev_detect_ddr |= _BV(dev_detect_pin);
	_delay_ms(500); // delay to simulate disconnect
	*/

	// ready twi bus, no pull-ups
	twi_port &= 0xFF ^ _BV(twi_scl_pin);
	twi_port &= 0xFF ^ _BV(twi_sda_pin);

	// start twi slave, link events
	twi_slave_init(0x52);

	/*
	// make the wiimote think something is connected
	dev_detect_port |= _BV(dev_detect_pin);
	*/
}
예제 #3
0
int main()
{
	#ifdef USE_SERPORT
	// start serial port
	sbi(uart_port, uart_rx_pin); // pull up
	serInit(38400);
	#endif

	// initialize ports

	// make power detect pin input
	cbi(power_detect_port, power_detect_pin);
	cbi(power_detect_ddr, power_detect_pin);

	sbi(LED_port, LED_pin);
	sbi(LED_ddr, LED_pin);

	#ifdef pull_up_res
	#ifdef trig_on_fall
	// setting port = pull ups on
	sbi(drum_port, green_pin);
	sbi(drum_port, red_pin);
	sbi(drum_port, yellow_pin);
	sbi(drum_port, blue_pin);
	sbi(drum_port, orange_pin);
	#endif
	#else
	cbi(drum_port, green_pin);
	cbi(drum_port, red_pin);
	cbi(drum_port, yellow_pin);
	cbi(drum_port, blue_pin);
	cbi(drum_port, orange_pin);
	#endif

	#ifdef trig_on_rise
	// clearing port = pull ups off
	cbi(drum_port, green_pin);
	cbi(drum_port, red_pin);
	cbi(drum_port, yellow_pin);
	cbi(drum_port, blue_pin);
	cbi(drum_port, orange_pin);
	#endif

	sbi(bass_port, bass1_pin);
	sbi(bass_port, bass2_pin);

	#ifdef GHWT
	sbi(plusminus_port, plus_pin);
	sbi(plusminus_port, minus_pin);
	sbi(stick_port, up_stick_pin);
	sbi(stick_port, down_stick_pin);
	sbi(stick_port, left_stick_pin);
	sbi(stick_port, right_stick_pin);
	#endif

	// all input
	cbi(drum_ddr, green_pin);
	cbi(drum_ddr, red_pin);
	cbi(drum_ddr, yellow_pin);
	cbi(drum_ddr, blue_pin);
	cbi(drum_ddr, orange_pin);
	cbi(bass_ddr, bass1_pin);
	cbi(bass_ddr, bass2_pin);

	#ifdef GHWT
	cbi(plusminus_ddr, plus_pin);
	cbi(plusminus_ddr, minus_pin);
	cbi(stick_ddr, up_stick_pin);
	cbi(stick_ddr, down_stick_pin);
	cbi(stick_ddr, left_stick_pin);
	cbi(stick_ddr, right_stick_pin);
	#endif

	// preinitialize comparison
	drum_in_preg = drum_in_reg;
	bass_in_preg = bass_in_reg;

	// initialize variables	
	wm_timer = 0;

	// initialize flags
	hit_f_l = 0xFF;
	hit_f_h = 0xFF;
	for(unsigned char i = 0; i < 8; i++)
	{
		hit_t[i] = 0;
		hit_s[i] = default_hit_softness;
	}

	unsigned char but_dat[6]; // struct containing button data
	but_dat[0] = 0b00011111;
	but_dat[1] = 0b00011111;
	but_dat[2] = 0b11111111;
	but_dat[3] = 0b11111111;
	but_dat[4] = 0b11111111;
	but_dat[5] = 0b11111111;

	// make wiimote think this is a drum
	wm_init(drum_id, but_dat, cal_data, wm_timer_inc);

	while(1)
	{
		// check if connected to wiimote
		if(bit_is_clear(power_detect_input, power_detect_pin))
		{
			// disconnected

			#ifdef USE_SERPORT
			// clear serial port buffer
			serFlush();
			#endif

			// handles reconnections
			wm_init(drum_id, but_dat, cal_data, wm_timer_inc);

			continue;
		}
		
		// check hardware
		check_for_hits();
		check_hit_f_llags();

		// apply hits
		but_dat[5] = hit_f_l;

		#ifdef USE_SERPORT
		unsigned char d; // serial port latest data
		unsigned char c; // number of char in serial port buffer
		d = serRx(&c); // check for serial command

		if(c > 0) // new command over serial port
		{
			but_dat[4] = 0xFF;
			but_dat[5] = 0xFF;

			if(bit_is_set(d, 0)) cbi(but_dat[5], green_bit);
			if(bit_is_set(d, 1)) cbi(but_dat[5], red_bit);
			if(bit_is_set(d, 2)) cbi(but_dat[5], yellow_bit);
			if(bit_is_set(d, 3)) cbi(but_dat[5], blue_bit);
			if(bit_is_set(d, 4)) cbi(but_dat[5], orange_bit);
			if(bit_is_set(d, 5)) cbi(but_dat[5], bass_bit);

			if(bit_is_set(d, 6)) cbi(but_dat[4], minus_bit);
			if(bit_is_set(d, 7)) cbi(but_dat[4], plus_bit);
		}
		#endif

		#ifdef GHWT

		but_dat[2] = 0xFF;
		but_dat[3] = 0xFF;

		if(but_dat[5] != 0xFF)
		{
			unsigned long t = wm_timer;
			
			// if any pads active, then send "softness"
			for(unsigned long i = hit_last + t; i < 16; i++)
			{
				unsigned char j = (unsigned char)(i % 8);
				if(bit_is_clear(but_dat[5], j))
				{
					// set pad
					but_dat[2] = pad_tbl[j];
					
					// set softness
					but_dat[3] = 0b00001100 | (hit_s[i] << 5);
					but_dat[4] &= 0b01111110;
					break;
				}
			}
		}

		// plus and minus buttons
		if(bit_is_clear(plusminus_in_reg, plus_pin)) cbi(but_dat[4], plus_bit);
		if(bit_is_clear(plusminus_in_reg, minus_pin)) cbi(but_dat[4], minus_bit);

		// simulate thumbstick with switches
		but_dat[0] = 0b00011111;
		but_dat[1] = 0b00011111;
		if(bit_is_clear(stick_in_reg, up_stick_pin)) but_dat[1] += thumbstick_speed;
		if(bit_is_clear(stick_in_reg, down_stick_pin)) but_dat[1] -= thumbstick_speed;
		if(bit_is_clear(stick_in_reg, left_stick_pin)) but_dat[0] -= thumbstick_speed;
		if(bit_is_clear(stick_in_reg, right_stick_pin)) but_dat[0] += thumbstick_speed;

		#endif

		wm_newaction(but_dat);
	}

	return 0;
}