2015-04-18 21:46:51 +00:00
|
|
|
#include <stdio.h>
|
2015-08-18 22:43:30 +00:00
|
|
|
#include <boo/boo.hpp>
|
2015-04-18 21:46:51 +00:00
|
|
|
|
2015-04-29 10:24:39 +00:00
|
|
|
namespace boo
|
|
|
|
{
|
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
class DolphinSmashAdapterCallback : public IDolphinSmashAdapterCallback
|
2015-04-24 00:24:15 +00:00
|
|
|
{
|
2015-05-05 07:16:06 +00:00
|
|
|
void controllerConnected(unsigned idx, EDolphinControllerType)
|
2015-04-24 00:24:15 +00:00
|
|
|
{
|
|
|
|
printf("CONTROLLER %u CONNECTED\n", idx);
|
|
|
|
}
|
2015-05-05 07:16:06 +00:00
|
|
|
void controllerDisconnected(unsigned idx, EDolphinControllerType)
|
2015-04-24 00:24:15 +00:00
|
|
|
{
|
|
|
|
printf("CONTROLLER %u DISCONNECTED\n", idx);
|
|
|
|
}
|
2015-05-05 07:16:06 +00:00
|
|
|
void controllerUpdate(unsigned idx, EDolphinControllerType,
|
2015-08-18 19:40:26 +00:00
|
|
|
const DolphinControllerState& state)
|
2015-04-24 00:24:15 +00:00
|
|
|
{
|
|
|
|
printf("CONTROLLER %u UPDATE %d %d\n", idx, state.m_leftStick[0], state.m_leftStick[1]);
|
2015-05-15 01:16:36 +00:00
|
|
|
printf(" %d %d\n", state.m_rightStick[0], state.m_rightStick[1]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-18 23:32:19 +00:00
|
|
|
class DualshockPadCallback : public IDualshockControllerCallback
|
2015-05-15 01:16:36 +00:00
|
|
|
{
|
|
|
|
void controllerDisconnected()
|
|
|
|
{
|
|
|
|
printf("CONTROLLER DISCONNECTED\n");
|
|
|
|
}
|
2015-08-18 23:32:19 +00:00
|
|
|
void controllerUpdate(const DualshockControllerState& state)
|
2015-05-15 01:16:36 +00:00
|
|
|
{
|
|
|
|
static time_t timeTotal;
|
|
|
|
static time_t lastTime = 0;
|
|
|
|
timeTotal = time(NULL);
|
|
|
|
time_t timeDif = timeTotal - lastTime;
|
|
|
|
/*
|
|
|
|
if (timeDif >= .15)
|
|
|
|
{
|
|
|
|
uint8_t led = ctrl->getLED();
|
|
|
|
led *= 2;
|
|
|
|
if (led > 0x10)
|
|
|
|
led = 2;
|
|
|
|
ctrl->setRawLED(led);
|
|
|
|
lastTime = timeTotal;
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
if (state.m_psButtonState)
|
|
|
|
{
|
|
|
|
if (timeDif >= 1) // wait 30 seconds before issuing another rumble event
|
|
|
|
{
|
|
|
|
ctrl->startRumble(DS3_MOTOR_LEFT);
|
|
|
|
ctrl->startRumble(DS3_MOTOR_RIGHT, 100);
|
|
|
|
lastTime = timeTotal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
else
|
|
|
|
ctrl->stopRumble(DS3_MOTOR_RIGHT | DS3_MOTOR_LEFT);*/
|
2015-05-22 00:35:46 +00:00
|
|
|
|
2015-05-15 01:16:36 +00:00
|
|
|
printf("CONTROLLER UPDATE %d %d\n", state.m_leftStick[0], state.m_leftStick[1]);
|
|
|
|
printf(" %d %d\n", state.m_rightStick[0], state.m_rightStick[1]);
|
|
|
|
printf(" %f %f %f\n", state.accPitch, state.accYaw, state.gyroZ);
|
2015-04-24 00:24:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
class TestDeviceFinder : public DeviceFinder
|
2015-04-22 21:48:23 +00:00
|
|
|
{
|
2015-08-18 23:32:19 +00:00
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
DolphinSmashAdapter* smashAdapter = NULL;
|
2015-08-18 23:32:19 +00:00
|
|
|
DualshockPad* ds3 = nullptr;
|
2015-08-18 19:40:26 +00:00
|
|
|
DolphinSmashAdapterCallback m_cb;
|
2015-08-18 23:32:19 +00:00
|
|
|
DualshockPadCallback m_ds3CB;
|
2015-04-22 21:48:23 +00:00
|
|
|
public:
|
2015-08-18 19:40:26 +00:00
|
|
|
TestDeviceFinder()
|
|
|
|
: DeviceFinder({typeid(DolphinSmashAdapter)})
|
2015-04-22 21:48:23 +00:00
|
|
|
{}
|
2015-08-18 19:40:26 +00:00
|
|
|
void deviceConnected(DeviceToken& tok)
|
2015-04-22 21:48:23 +00:00
|
|
|
{
|
2015-08-18 19:40:26 +00:00
|
|
|
smashAdapter = dynamic_cast<DolphinSmashAdapter*>(tok.openAndGetDevice());
|
2015-05-15 01:16:36 +00:00
|
|
|
if (smashAdapter)
|
|
|
|
{
|
|
|
|
smashAdapter->setCallback(&m_cb);
|
|
|
|
smashAdapter->startRumble(0);
|
|
|
|
return;
|
|
|
|
}
|
2015-08-18 23:32:19 +00:00
|
|
|
ds3 = dynamic_cast<DualshockPad*>(tok.openAndGetDevice());
|
2015-05-15 01:16:36 +00:00
|
|
|
if (ds3)
|
|
|
|
{
|
|
|
|
ds3->setCallback(&m_ds3CB);
|
|
|
|
ds3->setLED(DS3_LED_1);
|
|
|
|
}
|
2015-04-22 21:48:23 +00:00
|
|
|
}
|
2015-08-18 19:40:26 +00:00
|
|
|
void deviceDisconnected(DeviceToken&, DeviceBase* device)
|
2015-04-22 21:48:23 +00:00
|
|
|
{
|
2015-04-23 00:46:32 +00:00
|
|
|
if (smashAdapter == device)
|
|
|
|
{
|
|
|
|
delete smashAdapter;
|
|
|
|
smashAdapter = NULL;
|
|
|
|
}
|
2015-05-15 01:16:36 +00:00
|
|
|
if (ds3 == device)
|
|
|
|
{
|
|
|
|
delete ds3;
|
|
|
|
ds3 = nullptr;
|
|
|
|
}
|
2015-04-22 21:48:23 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-05-04 04:28:07 +00:00
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
struct CTestWindowCallback : IWindowCallback
|
2015-05-04 04:28:07 +00:00
|
|
|
{
|
2015-05-12 09:38:37 +00:00
|
|
|
void mouseDown(const SWindowCoord& coord, EMouseButton button, EModifierKey mods)
|
2015-05-04 04:28:07 +00:00
|
|
|
{
|
2015-05-12 09:38:37 +00:00
|
|
|
fprintf(stderr, "Mouse Down %d (%f,%f)\n", button, coord.norm[0], coord.norm[1]);
|
|
|
|
}
|
|
|
|
void mouseUp(const SWindowCoord& coord, EMouseButton button, EModifierKey mods)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Mouse Up %d (%f,%f)\n", button, coord.norm[0], coord.norm[1]);
|
|
|
|
}
|
|
|
|
void mouseMove(const SWindowCoord& coord)
|
|
|
|
{
|
|
|
|
//fprintf(stderr, "Mouse Move (%f,%f)\n", coord.norm[0], coord.norm[1]);
|
|
|
|
}
|
|
|
|
void scroll(const SWindowCoord& coord, const SScrollDelta& scroll)
|
|
|
|
{
|
2015-05-13 08:51:18 +00:00
|
|
|
fprintf(stderr, "Mouse Scroll (%f,%f) (%f,%f)\n", coord.norm[0], coord.norm[1], scroll.delta[0], scroll.delta[1]);
|
2015-05-04 04:28:07 +00:00
|
|
|
}
|
|
|
|
|
2015-05-13 08:51:18 +00:00
|
|
|
void touchDown(const STouchCoord& coord, uintptr_t tid)
|
2015-05-04 04:28:07 +00:00
|
|
|
{
|
2015-05-13 08:51:18 +00:00
|
|
|
//fprintf(stderr, "Touch Down %16lX (%f,%f)\n", tid, coord.coord[0], coord.coord[1]);
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
2015-05-13 08:51:18 +00:00
|
|
|
void touchUp(const STouchCoord& coord, uintptr_t tid)
|
2015-05-12 09:38:37 +00:00
|
|
|
{
|
2015-05-13 08:51:18 +00:00
|
|
|
//fprintf(stderr, "Touch Up %16lX (%f,%f)\n", tid, coord.coord[0], coord.coord[1]);
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
2015-05-13 08:51:18 +00:00
|
|
|
void touchMove(const STouchCoord& coord, uintptr_t tid)
|
2015-05-12 09:38:37 +00:00
|
|
|
{
|
2015-05-13 08:51:18 +00:00
|
|
|
//fprintf(stderr, "Touch Move %16lX (%f,%f)\n", tid, coord.coord[0], coord.coord[1]);
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
2015-05-04 04:28:07 +00:00
|
|
|
|
2015-05-12 09:38:37 +00:00
|
|
|
void charKeyDown(unsigned long charCode, EModifierKey mods, bool isRepeat)
|
|
|
|
{
|
2015-05-04 04:28:07 +00:00
|
|
|
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
|
|
|
void charKeyUp(unsigned long charCode, EModifierKey mods)
|
|
|
|
{
|
2015-05-04 04:28:07 +00:00
|
|
|
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
|
|
|
void specialKeyDown(ESpecialKey key, EModifierKey mods, bool isRepeat)
|
|
|
|
{
|
2015-05-04 04:28:07 +00:00
|
|
|
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
|
|
|
void specialKeyUp(ESpecialKey key, EModifierKey mods)
|
2015-05-04 04:28:07 +00:00
|
|
|
{
|
2015-05-12 09:38:37 +00:00
|
|
|
|
2015-05-04 04:28:07 +00:00
|
|
|
}
|
2015-05-12 09:38:37 +00:00
|
|
|
void modKeyDown(EModifierKey mod, bool isRepeat)
|
|
|
|
{
|
2015-05-04 04:28:07 +00:00
|
|
|
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
|
|
|
void modKeyUp(EModifierKey mod)
|
|
|
|
{
|
2015-05-04 04:28:07 +00:00
|
|
|
|
2015-05-12 09:38:37 +00:00
|
|
|
}
|
2015-05-04 04:28:07 +00:00
|
|
|
|
2015-05-12 09:38:37 +00:00
|
|
|
};
|
2015-05-02 00:20:30 +00:00
|
|
|
|
2015-04-21 04:02:43 +00:00
|
|
|
|
2015-08-18 19:40:26 +00:00
|
|
|
struct TestApplicationCallback : IApplicationCallback
|
2015-05-04 04:28:07 +00:00
|
|
|
{
|
2015-05-06 00:50:57 +00:00
|
|
|
IWindow* mainWindow = NULL;
|
2015-08-18 19:40:26 +00:00
|
|
|
boo::TestDeviceFinder devFinder;
|
2015-05-12 09:38:37 +00:00
|
|
|
CTestWindowCallback windowCallback;
|
2015-05-06 00:50:57 +00:00
|
|
|
void appLaunched(IApplication* app)
|
2015-04-18 23:12:22 +00:00
|
|
|
{
|
2015-05-06 00:50:57 +00:00
|
|
|
mainWindow = app->newWindow("YAY!");
|
2015-05-12 09:38:37 +00:00
|
|
|
mainWindow->setCallback(&windowCallback);
|
2015-05-06 00:50:57 +00:00
|
|
|
mainWindow->showWindow();
|
|
|
|
devFinder.startScanning();
|
2015-04-18 23:12:22 +00:00
|
|
|
}
|
2015-05-06 00:50:57 +00:00
|
|
|
void appQuitting(IApplication*)
|
2015-05-04 04:28:07 +00:00
|
|
|
{
|
2015-05-06 00:50:57 +00:00
|
|
|
delete mainWindow;
|
|
|
|
}
|
2015-08-18 19:40:26 +00:00
|
|
|
void appFilesOpen(IApplication*, const std::vector<std::string>& paths)
|
2015-05-15 01:16:36 +00:00
|
|
|
{
|
2015-05-13 22:21:13 +00:00
|
|
|
fprintf(stderr, "OPENING: ");
|
|
|
|
for (const std::string& path : paths)
|
|
|
|
fprintf(stderr, "%s ", path.c_str());
|
|
|
|
fprintf(stderr, "\n");
|
2015-05-15 01:16:36 +00:00
|
|
|
}
|
2015-05-06 00:50:57 +00:00
|
|
|
};
|
2015-05-04 04:28:07 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-08-18 22:43:30 +00:00
|
|
|
int main(int argc, const char** argv)
|
2015-04-18 21:46:51 +00:00
|
|
|
{
|
2015-08-18 19:40:26 +00:00
|
|
|
boo::TestApplicationCallback appCb;
|
2015-08-18 22:50:52 +00:00
|
|
|
std::unique_ptr<boo::IApplication> app =
|
2015-08-18 22:43:30 +00:00
|
|
|
ApplicationBootstrap(boo::IApplication::PLAT_AUTO,
|
|
|
|
appCb, "rwk", "RWK", argc, argv);
|
2015-05-06 00:50:57 +00:00
|
|
|
app->run();
|
2015-05-12 09:38:37 +00:00
|
|
|
printf("IM DYING!!\n");
|
2015-04-18 21:46:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-05-04 04:28:07 +00:00
|
|
|
|