dolphin/Source/Plugins/Plugin_WiimoteNew/Src/WiimoteEmu/Attachment/Guitar.cpp

102 lines
2.2 KiB
C++
Raw Normal View History

#include "Guitar.h"
namespace WiimoteEmu
{
static const u8 guitar_id[] = { 0x00, 0x00, 0xa4, 0x20, 0x01, 0x03 };
const u16 guitar_fret_bitmasks[] =
{
Guitar::FRET_GREEN,
Guitar::FRET_RED,
Guitar::FRET_YELLOW,
Guitar::FRET_BLUE,
Guitar::FRET_ORANGE,
};
const char* guitar_fret_names[] =
{
"Green","Red","Yellow","Blue","Orange",
};
const u16 guitar_button_bitmasks[] =
{
Guitar::BUTTON_MINUS,
Guitar::BUTTON_PLUS,
};
const u16 guitar_strum_bitmasks[] =
{
Guitar::BAR_UP,
Guitar::BAR_DOWN,
};
Guitar::Guitar() : Attachment( "Guitar" )
{
// frets
groups.push_back( m_frets = new Buttons( "Frets" ) );
for ( unsigned int i = 0; i < sizeof(guitar_fret_names)/sizeof(*guitar_fret_names); ++i )
m_frets->controls.push_back( new ControlGroup::Input( guitar_fret_names[i] ) );
// stick
groups.push_back( m_stick = new AnalogStick( "Stick" ) );
// strum
groups.push_back( m_strum = new Buttons( "Strum" ) );
m_strum->controls.push_back( new ControlGroup::Input("Up") );
m_strum->controls.push_back( new ControlGroup::Input("Down") );
// whammy
groups.push_back( m_whammy = new Triggers( "Whammy" ) );
m_whammy->controls.push_back( new ControlGroup::Input("Bar") );
// buttons
groups.push_back( m_buttons = new Buttons( "Buttons" ) );
m_buttons->controls.push_back( new ControlGroup::Input("Minus") );
m_buttons->controls.push_back( new ControlGroup::Input("Plus") );
// set up register
// id
memcpy( &reg[0xfa], guitar_id, sizeof(guitar_id) );
}
void Guitar::GetState(u8* const data, const bool focus)
{
wm_guitar_extension* const gdata = (wm_guitar_extension*)data;
// calibration data not figured out yet?
// stick
{
u8 x, y;
m_stick->GetState( &x, &y, 0x20, focus ? 0x1F /*0x15*/ : 0 );
gdata->sx = x;
gdata->sy = y;
}
// TODO: touch bar, probably not
gdata->tb = 0x0F; // not touched
// whammy bar
u8 whammy;
m_whammy->GetState( &whammy, 0x1F );
gdata->whammy = whammy;
if (focus)
{
// buttons
m_buttons->GetState( &gdata->bt, guitar_button_bitmasks );
// frets
m_frets->GetState( &gdata->bt, guitar_fret_bitmasks );
// strum
m_strum->GetState( &gdata->bt, guitar_strum_bitmasks );
}
// flip button bits
gdata->bt ^= 0xFFFF;
}
}