2020-04-02 22:22:45 +00:00
|
|
|
#include "application.hpp"
|
2020-04-17 09:52:22 +00:00
|
|
|
#include "bluetooth/core.hpp"
|
|
|
|
//#include "hidgamepad.hpp"
|
2020-04-02 22:22:45 +00:00
|
|
|
|
|
|
|
#include "gfx/graphics.hpp"
|
|
|
|
#include "scenes/pairingscene.hpp"
|
|
|
|
|
|
|
|
PairingScene::PairingScene()
|
|
|
|
: m_selectionIdx(-1) {
|
|
|
|
m_imgIcons = mc::gfx::LoadTexture("romfs:/images/controller-icons.png");
|
|
|
|
}
|
|
|
|
|
|
|
|
PairingScene::~PairingScene() {
|
|
|
|
mc::gfx::DestroyTexture(m_imgIcons);
|
|
|
|
}
|
|
|
|
|
2020-04-17 09:52:22 +00:00
|
|
|
void PairingScene::setFocus(bool focus) {
|
|
|
|
if (mc::bluetooth::core::discoveredDevices.empty()) {
|
|
|
|
m_selectionIdx = -1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_selectionIdx = 0;
|
|
|
|
}
|
|
|
|
mc::ui::Scene::setFocus(focus);
|
|
|
|
}
|
|
|
|
|
2020-04-02 22:22:45 +00:00
|
|
|
void PairingScene::draw(void) {
|
|
|
|
|
2020-04-17 09:52:22 +00:00
|
|
|
if (mc::bluetooth::core::IsDiscovering()) {
|
2020-04-02 22:22:45 +00:00
|
|
|
mc::gfx::DrawGlyph(670, 96,
|
|
|
|
mc::font::ExtSmall,
|
|
|
|
mc::app::theme->foregroundColor,
|
|
|
|
GlyphType_SpinnerTopLeft + mc::app::counter
|
|
|
|
);
|
|
|
|
mc::gfx::DrawText(700, 96,
|
|
|
|
mc::font::Small,
|
|
|
|
mc::app::theme->foregroundColor,
|
|
|
|
"Searching for controllers..."
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
uint16_t y_offset = 130;
|
2020-04-17 09:52:22 +00:00
|
|
|
int i;
|
2020-04-02 22:22:45 +00:00
|
|
|
|
|
|
|
int x1 = 470;
|
|
|
|
int x2 = 1189;
|
|
|
|
int y1;
|
|
|
|
int y2;
|
|
|
|
|
|
|
|
// lay down separator lines
|
2020-04-17 09:52:22 +00:00
|
|
|
for (i = 0; i < mc::bluetooth::core::discoveredDevices.size(); ++i) {
|
2020-04-02 22:22:45 +00:00
|
|
|
y1 = y_offset + i*(70+1);
|
|
|
|
mc::gfx::DrawHLine(x1, x2, y1, mc::app::theme->foregroundColor2);
|
|
|
|
}
|
|
|
|
mc::gfx::DrawHLine(470, 1189, y_offset + i*(70+1), mc::app::theme->foregroundColor2);
|
|
|
|
|
|
|
|
i = 0;
|
2020-04-17 09:52:22 +00:00
|
|
|
for (auto it = mc::bluetooth::core::discoveredDevices.begin(); it != mc::bluetooth::core::discoveredDevices.end(); ++it) {
|
2020-04-02 22:22:45 +00:00
|
|
|
y1 = y_offset + i*(70+1);
|
|
|
|
y2 = y1 + 70;
|
|
|
|
|
2020-04-17 09:52:22 +00:00
|
|
|
if ( (i == m_selectionIdx) & this->hasFocus() ) {
|
2020-04-02 22:22:45 +00:00
|
|
|
mc::gfx::DrawRoundedRect(x1-5, y1-5, x2+5, y2+5, 2, mc::app::theme->glowColor);
|
|
|
|
mc::gfx::DrawRect(x1, y1, x2, y2, mc::app::theme->selectionColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw controller image
|
2020-04-17 09:52:22 +00:00
|
|
|
SDL_Rect clip = {5*48, mc::app::theme->colorSetId*48, 48, 48};
|
2020-04-02 22:22:45 +00:00
|
|
|
mc::gfx::DrawTexture(x1+30, y1 + 14, m_imgIcons, &clip);
|
|
|
|
// draw controller details
|
|
|
|
mc::gfx::DrawText(x1+100, y1 + 10, mc::font::Small, mc::app::theme->foregroundColor, (*it)->name);
|
|
|
|
mc::gfx::DrawText(x1+100, y1 + 40, mc::font::Small, mc::app::theme->foregroundColor2, "%02X:%02X:%02X:%02X:%02X:%02X",
|
|
|
|
((uint8_t *)&(*it)->address)[0],
|
|
|
|
((uint8_t *)&(*it)->address)[1],
|
|
|
|
((uint8_t *)&(*it)->address)[2],
|
|
|
|
((uint8_t *)&(*it)->address)[3],
|
|
|
|
((uint8_t *)&(*it)->address)[4],
|
|
|
|
((uint8_t *)&(*it)->address)[5]
|
|
|
|
);
|
|
|
|
|
2020-04-17 09:52:22 +00:00
|
|
|
if ( (i == m_selectionIdx) && mc::bluetooth::core::IsPairing()) {
|
2020-04-02 22:22:45 +00:00
|
|
|
mc::gfx::DrawGlyph(x1+600, y1 + 26, mc::font::ExtSmall, mc::app::theme->highlightColor, GlyphType_SpinnerTopLeft + mc::app::counter);
|
|
|
|
mc::gfx::DrawText(x1+630, y1 + 26, mc::font::Small, mc::app::theme->highlightColor, "Pairing");
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw console bd address
|
|
|
|
/*
|
|
|
|
mc::gfx::DrawText(430, 620, mc::font::Small, mc::app::theme->foregroundColor2, "Host address: %02X:%02X:%02X:%02X:%02X:%02X",
|
2020-04-17 09:52:22 +00:00
|
|
|
((uint8_t *)&mc::bluetooth::core::hostAddress)[0],
|
|
|
|
((uint8_t *)&mc::bluetooth::core::hostAddress)[1],
|
|
|
|
((uint8_t *)&mc::bluetooth::core::hostAddress)[2],
|
|
|
|
((uint8_t *)&mc::bluetooth::core::hostAddress)[3],
|
|
|
|
((uint8_t *)&mc::bluetooth::core::hostAddress)[4],
|
|
|
|
((uint8_t *)&mc::bluetooth::core::hostAddress)[5]
|
2020-04-02 22:22:45 +00:00
|
|
|
);
|
|
|
|
*/
|
|
|
|
}
|
|
|
|
|
|
|
|
void PairingScene::handleInput(const mc::app::UserInput *input) {
|
|
|
|
|
2020-04-17 09:52:22 +00:00
|
|
|
if (!mc::bluetooth::core::IsPairing()) {
|
2020-04-02 22:22:45 +00:00
|
|
|
/* Move selection up */
|
|
|
|
if (input->kDown & KEY_UP) {
|
|
|
|
m_selectionIdx = std::max(m_selectionIdx-1, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Move selection down */
|
|
|
|
if (input->kDown & KEY_DOWN) {
|
|
|
|
|
2020-04-17 09:52:22 +00:00
|
|
|
if (++m_selectionIdx >= mc::bluetooth::core::discoveredDevices.size()) {
|
2020-04-02 22:22:45 +00:00
|
|
|
m_selectionIdx = m_selectionIdx - 1;
|
|
|
|
}
|
2020-04-17 09:52:22 +00:00
|
|
|
//m_selectionIdx = std::min(m_selectionIdx+1, mc::bluetooth::core::discoveredDevices.size()-1);
|
2020-04-02 22:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Pair with current selection */
|
|
|
|
if (input->kDown & KEY_A) {
|
|
|
|
if (m_selectionIdx >= 0) {
|
2020-04-17 09:52:22 +00:00
|
|
|
mc::bluetooth::core::PairDevice(&mc::bluetooth::core::discoveredDevices[m_selectionIdx]->address);
|
2020-04-02 22:22:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|