Update project for new HID API

This commit is contained in:
cathery 2021-09-24 00:53:59 +03:00
parent 3dfa800db3
commit 8c00a8b3a7
18 changed files with 151 additions and 170 deletions

View File

@ -54,9 +54,9 @@ CUSTOM_LIBS := SimpleIniParser
ARCH := -march=armv8-a -mtune=cortex-a57 -mtp=soft -fPIE
CFLAGS := -g -Wall -O2 -ffunction-sections \
$(ARCH) $(DEFINES) -I$(PORTLIBS)/include/freetype2
$(ARCH) $(DEFINES)
CFLAGS += $(INCLUDE) -D__SWITCH__
CFLAGS += $(INCLUDE) -D__SWITCH__ `freetype-config --cflags`
CXXFLAGS := $(CFLAGS) -fno-rtti -fexceptions -std=gnu++17

View File

@ -20,7 +20,7 @@ public:
void draw();
bool onInput(u32 kdown);
void onTouch(touchPosition &touch);
void onTouch(HidTouchState &touch);
inline bool isActivated() {
return m_isActivated;

View File

@ -79,10 +79,10 @@ public:
virtual void onInput(u32 kdown) {
inputButtons(kdown);
}
virtual void onTouch(touchPosition &touch) {
virtual void onTouch(HidTouchState &touch) {
touchButtons(touch);
}
virtual void onGesture(touchPosition &startPosition, touchPosition &endPosition){};
virtual void onGesture(HidTouchState &startPosition, HidTouchState &endPosition){};
s16 getSelectedButtonIndex();
void selectButton(s16 buttonIndex);
void selectButtonByRef(const Button *button);
@ -127,7 +127,7 @@ protected:
return false;
};
void touchButtons(touchPosition &touch) {
void touchButtons(HidTouchState &touch) {
for (auto &btn : m_buttons) {
btn->onTouch(touch);
}

View File

@ -18,7 +18,7 @@ public:
void update();
void draw(Gui *gui);
void onInput(u32 kdown);
void onTouch(touchPosition &touch);
void onTouch(HidTouchState &touch);
void show();
void hide();

View File

@ -28,8 +28,8 @@ public:
void draw(Gui *gui);
void onInput(u32 kdown);
void onTouch(touchPosition &touch);
void onGesture(touchPosition startPosition, touchPosition endPosition, bool finish);
void onTouch(HidTouchState &touch);
void onGesture(HidTouchState &startPosition, HidTouchState &endPosition, bool finish);
void setProgress(s8 progress);

View File

@ -20,7 +20,7 @@ enum class OverrideKeyType {
};
struct OverrideKey {
HidControllerKeys key;
HidNpadButton key;
bool overrideByDefault;
u64 programID;
@ -29,7 +29,7 @@ struct OverrideKey {
static OverrideKey StringToKeyCombo(const std::string &keyString);
static OverrideKey StringToKeyCombo(const char *keyString);
static std::string KeyComboToString(const OverrideKey &keyCombo);
static const char *KeyToUnicode(HidControllerKeys key);
static const char *KeyToUnicode(HidNpadButton key);
//the override_key option names as they are defined in the Atmosphere config
static const char *getOverrideKeyString(OverrideKeyType type);

View File

@ -37,15 +37,15 @@ bool Button::onInput(u32 kdown) {
return false;
if (!m_isActivated) {
if ((kdown & KEY_A) && activatable) {
if ((kdown & HidNpadButton_A) && activatable) {
m_isActivated = true;
kdown = 0;
} else {
if (kdown & KEY_UP) m_gui->selectButton(adjacentButton[0]);
if (kdown & KEY_DOWN) m_gui->selectButton(adjacentButton[1]);
if (kdown & KEY_LEFT) m_gui->selectButton(adjacentButton[2]);
if (kdown & KEY_RIGHT) m_gui->selectButton(adjacentButton[3]);
if (kdown & (KEY_UP | KEY_DOWN | KEY_LEFT | KEY_RIGHT)) return true;
if (kdown & HidNpadButton_AnyUp) m_gui->selectButton(adjacentButton[0]);
if (kdown & HidNpadButton_AnyDown) m_gui->selectButton(adjacentButton[1]);
if (kdown & HidNpadButton_AnyLeft) m_gui->selectButton(adjacentButton[2]);
if (kdown & HidNpadButton_AnyRight) m_gui->selectButton(adjacentButton[3]);
if (kdown & (HidNpadButton_AnyUp | HidNpadButton_AnyDown | HidNpadButton_AnyLeft | HidNpadButton_AnyRight)) return true;
}
}
@ -56,18 +56,18 @@ bool Button::onInput(u32 kdown) {
return false;
}
void Button::onTouch(touchPosition &touch) {
void Button::onTouch(HidTouchState &touch) {
if (!usableCondition()) return;
u16 resultX = position.first > m_gui->m_targetOffsetX ? position.first - m_gui->m_targetOffsetX : 0;
u16 resultY = position.second > m_gui->m_targetOffsetY ? position.second - m_gui->m_targetOffsetY : 0;
if (touch.px >= resultX && touch.px <= (resultX + volume.first) && touch.py >= resultY && touch.py <= (resultY + volume.second)) {
if (touch.x >= resultX && touch.x <= (resultX + volume.first) && touch.y >= resultY && touch.y <= (resultY + volume.second)) {
if (m_isSelected) {
if (activatable)
m_isActivated = true;
else
inputAction(KEY_A, &m_isActivated);
inputAction(HidNpadButton_A, &m_isActivated);
return;
}

View File

@ -92,7 +92,7 @@ GuiHekate::GuiHekate() : Gui() {
gui->drawTextAligned(font20, x + 830, y + 50, currTheme.selectedColor, autoBootName.c_str(), ALIGNED_RIGHT);
};
profileButton->inputAction = [&](u32 kdown, bool *isActivated) {
if (kdown & KEY_A) {
if (kdown & HidNpadButton_A) {
rebootNames.clear();
for (auto const &autoBootEntry : m_rebootConfigs)
@ -100,7 +100,7 @@ GuiHekate::GuiHekate() : Gui() {
(new ListSelector("Hekate profile to reboot to", "\uE0E1 Back \uE0E0 OK", rebootNames, currRebootEntryIndex))
->setInputAction([&](u32 k, u16 selectedItem) {
if (k & KEY_A) {
if (k & HidNpadButton_A) {
currRebootEntryIndex = selectedItem;
m_currRebootConfig = m_rebootConfigs[selectedItem];
@ -121,7 +121,7 @@ GuiHekate::GuiHekate() : Gui() {
gui->drawTextAligned(font20, Gui::g_framebuffer_width / 2, y + 50, currTheme.textColor, "Reboot now!", ALIGNED_CENTER);
};
rebootButton->inputAction = [&](u32 kdown, bool *isActivated) {
if (kdown & KEY_A) {
if (kdown & HidNpadButton_A) {
FILE *f = fopen("sdmc:/bootloader/update.bin", "rb");
if (f) {
fread(g_reboot_payload, 1, sizeof(g_reboot_payload), f);
@ -171,6 +171,6 @@ void GuiHekate::draw() {
void GuiHekate::onInput(u32 kdown) {
inputButtons(kdown);
if (kdown & KEY_B)
if (kdown & HidNpadButton_B)
Gui::g_nextGui = GUI_MAIN;
}

View File

@ -36,7 +36,7 @@ GuiHIDMitm::GuiHIDMitm() : Gui() {
gui->drawTextAligned(font20, Gui::g_framebuffer_width / 2, y + 50, currTheme.textColor, "Touch to save config", ALIGNED_CENTER);
};
configButton->inputAction = [&](u32 kdown, bool *isActivated) {
if (kdown & KEY_A) {
if (kdown & HidNpadButton_A) {
Gui::g_nextGui = GUI_SM_SELECT;
for (u16 i = 0; i < m_hidConfig.size(); i++)
@ -112,10 +112,10 @@ void GuiHIDMitm::draw() {
void GuiHIDMitm::onInput(u32 kdown) {
if (m_selectedButton == -1) {
if (kdown <= KEY_DDOWN)
if (kdown <= HidNpadButton_Down)
m_selectedButton = log2(kdown);
} else {
if (kdown <= KEY_DDOWN) {
if (kdown <= HidNpadButton_Down) {
m_hidConfig[keyNames[m_selectedButton]] = keyNames[static_cast<u32>(log2(kdown))];
m_selectedButton = -1;
}

View File

@ -42,7 +42,7 @@ GuiMain::GuiMain() : Gui() {
gui->drawTextAligned(font14, x + 100, y + 185, currTheme.textColor, "Change override keys", ALIGNED_CENTER);
};
overrideKeysMenuButton->inputAction = [&](u64 kdown, bool *isActivated) {
if (kdown & KEY_A)
if (kdown & HidNpadButton_A)
Gui::g_nextGui = GUI_OVERRIDES_MENU;
};
add(overrideKeysMenuButton);
@ -66,7 +66,7 @@ GuiMain::GuiMain() : Gui() {
gui->drawTextAligned(font20, x + 660, y + 50, currTheme.selectedColor, autoBootName.c_str(), ALIGNED_RIGHT);
};
autobootSelectorButton->inputAction = [&](u32 kdown, bool *isActivated) {
if (kdown & KEY_A) {
if (kdown & HidNpadButton_A) {
autobootNames.clear();
for (auto const &autoBootEntry : m_autoBootConfigs)
@ -74,7 +74,7 @@ GuiMain::GuiMain() : Gui() {
(new ListSelector("Hekate autoboot profile", "\uE0E1 Back \uE0E0 OK", autobootNames, currAutoBootEntryIndex))
->setInputAction([&](u32 k, u16 selectedItem) {
if (k & KEY_A) {
if (k & HidNpadButton_A) {
auto hekateIni = parseOrCreateFileFixed(HEKATE_INI);
currAutoBootEntryIndex = selectedItem;
@ -110,7 +110,7 @@ GuiMain::GuiMain() : Gui() {
gui->drawTextAligned(font20, x + 37, y + 50, currTheme.textColor, "Background services", ALIGNED_LEFT);
};
backgroundServicesButton->inputAction = [&](u32 kdown, bool *isActivated) {
if (kdown & KEY_A)
if (kdown & HidNpadButton_A)
Gui::g_nextGui = GUI_SM_SELECT;
};
add(backgroundServicesButton);
@ -126,7 +126,7 @@ GuiMain::GuiMain() : Gui() {
gui->drawTextAligned(font20, x + 55, y + 50, currTheme.textColor, "Reboot to Hekate", ALIGNED_LEFT);
};
rebootButton->inputAction = [&](u32 kdown, bool *isActivated) {
if (kdown & KEY_A) {
if (kdown & HidNpadButton_A) {
Gui::g_nextGui = GUI_HEKATE;
GuiHekate::m_currRebootConfig = m_currAutoBootConfig;
}
@ -158,6 +158,6 @@ void GuiMain::draw() {
void GuiMain::onInput(u32 kdown) {
if (inputButtons(kdown)) return;
if (kdown & KEY_B && !exitDisabled)
if (kdown & HidNpadButton_B && !exitDisabled)
g_exitApplet = true;
}

View File

@ -33,11 +33,11 @@ GuiOverrideKey::GuiOverrideKey() : Gui() {
// This is supposed to clear the key display, and block exit until a button is pressed.
// For some reason, it doesn't work
m_override.key.key = static_cast<HidControllerKeys>(0);
m_override.key.key = static_cast<HidNpadButton>(0);
m_inputBlocked = true;
Gui::g_exitBlocked = true;
if (kdown && !(kdown & (kdown - 1)) && (kdown <= KEY_DDOWN || kdown >= KEY_SL) && kdown != KEY_TOUCH) {
m_override.key.key = static_cast<HidControllerKeys>(kdown);
if (kdown && !(kdown & (kdown - 1)) && (kdown <= HidNpadButton_Down || kdown >= HidNpadButton_AnySL)) {
m_override.key.key = static_cast<HidNpadButton>(kdown);
//Find or create a loader ini file with set override_key values, and write the result to the file.
simpleIniParser::Ini *ini = parseOrCreateFileFixed(LOADER_INI);
auto keyValue = m_override.key.ToString();
@ -66,9 +66,9 @@ GuiOverrideKey::GuiOverrideKey() : Gui() {
gui->drawTextAligned(font20, x + 360, y + 50, currTheme.selectedColor, m_override.key.overrideByDefault ? "Unpressed" : "Pressed", ALIGNED_RIGHT);
};
comboPressedButton->inputAction = [&](u32 kdown, bool *isActivated) {
if (kdown & KEY_A) {
if (kdown & HidNpadButton_A) {
m_override.key.overrideByDefault = !m_override.key.overrideByDefault;
if (m_override.key.key == static_cast<HidControllerKeys>(0))
if (m_override.key.key == static_cast<HidNpadButton>(0))
return;
//Find or create a loader ini file with set override_key values, and write the result to the file.
@ -108,7 +108,7 @@ GuiOverrideKey::GuiOverrideKey() : Gui() {
gui->drawTextAligned(font20, x + 360, y + 50, m_overrideAnyApp ? currTheme.selectedColor : currTheme.unselectedColor, m_overrideAnyApp ? "On" : "Off", ALIGNED_RIGHT);
};
overrideEnabledButton->inputAction = [&](u64 kdown, bool *isActivated) {
if (kdown & KEY_A) {
if (kdown & HidNpadButton_A) {
m_overrideAnyApp = !m_overrideAnyApp;
//Find or create a loader ini file with set override_key values, and write the result to the file.
@ -152,7 +152,7 @@ GuiOverrideKey::GuiOverrideKey() : Gui() {
}
};
appIconButton->inputAction = [&](u64 kdown, bool *isActivated) {
if (kdown & KEY_A) {
if (kdown & HidNpadButton_A) {
GuiTitleList::selectedAppID = m_override.programID;
Gui::g_nextGui = GUI_TITLE_LIST;
}
@ -183,7 +183,7 @@ void GuiOverrideKey::draw() {
}
void GuiOverrideKey::onInput(u32 kdown) {
if (!m_inputBlocked && kdown & KEY_B)
if (!m_inputBlocked && kdown & HidNpadButton_B)
Gui::g_nextGui = GUI_OVERRIDES_MENU;
inputButtons(kdown);

View File

@ -17,11 +17,11 @@ GuiOverridesMenu::GuiOverridesMenu() : Gui() {
displayDefaultOption = true;
displayAnyTitleOption = true;
if (m_anyAppOverride.key.key != static_cast<HidControllerKeys>(0))
if (m_anyAppOverride.key.key != static_cast<HidNpadButton>(0))
addButton(OverrideButtonType::Any_Title, OverrideKeyType::Any_App_Override, m_anyAppOverride);
for (int i = 0; i != 8; ++i) {
if (m_overrides[i].programID != AppletID::Invalid || (m_overrides[i].key.key != static_cast<HidControllerKeys>(0))) {
if (m_overrides[i].programID != AppletID::Invalid || (m_overrides[i].key.key != static_cast<HidNpadButton>(0))) {
addButton(OverrideButtonType::Custom_Title, static_cast<OverrideKeyType>(i), m_overrides[i]);
}
}
@ -54,10 +54,10 @@ void GuiOverridesMenu::draw() {
void GuiOverridesMenu::onInput(u32 kdown) {
if (inputButtons(kdown)) return;
if (kdown & KEY_B)
if (kdown & HidNpadButton_B)
Gui::g_nextGui = GUI_MAIN;
if (kdown & KEY_X) {
if (kdown & HidNpadButton_X) {
//Get the button options based on selection
auto tuple = m_buttons[getSelectedButtonIndex()];
auto buttonType = std::get<0>(tuple);
@ -121,7 +121,7 @@ void GuiOverridesMenu::addButton(OverrideButtonType buttonType, OverrideKeyType
configNames.reserve(static_cast<int>(OverrideKeyType::Num_OverrideKey_Types));
std::function<void(Gui *, u16, u16, bool *)> drawAction;
std::function<void(u32, bool *)> inputAction = [&, keyType, key](u64 kdown, bool *isActivated) {
if (kdown & KEY_A) {
if (kdown & HidNpadButton_A) {
GuiOverrideKey::g_overrideKey = key;
GuiOverrideKey::g_keyType = keyType;
Gui::g_nextGui = GUI_OVERRIDE_KEY;
@ -161,7 +161,7 @@ void GuiOverridesMenu::addButton(OverrideButtonType buttonType, OverrideKeyType
};
inputAction = [&](u64 kdown, bool *isActivated) {
if (kdown & KEY_A) {
if (kdown & HidNpadButton_A) {
configNames.clear();
if (displayAnyTitleOption)
@ -175,7 +175,7 @@ void GuiOverridesMenu::addButton(OverrideButtonType buttonType, OverrideKeyType
(new ListSelector("Add new key override for:", "\uE0E1 Back \uE0E0 OK", configNames, 0))
->setInputAction([&](u32 k, u16 selectedItem) {
if (k & KEY_A) {
if (k & HidNpadButton_A) {
auto newKeyType = m_addConfigs[0];

View File

@ -98,7 +98,7 @@ GuiSysmodule::GuiSysmodule() : Gui() {
gui->drawTextAligned(font20, x + 420, y + 50, this->m_runningSysmodules.find(sysmodule.first) != this->m_runningSysmodules.end() ? currTheme.selectedColor : Gui::makeColor(0xB8, 0xBB, 0xC2, 0xFF), this->m_runningSysmodules.find(sysmodule.first) != this->m_runningSysmodules.end() ? "On" : "Off", ALIGNED_LEFT);
};
sysmoduleButton->inputAction = [&](u32 kdown, bool *isActivated) {
if (kdown & KEY_A) {
if (kdown & HidNpadButton_A) {
u64 pid;
u64 tid = std::stol(sysmodule.first.c_str(), nullptr, 16);
@ -199,9 +199,9 @@ void GuiSysmodule::draw() {
void GuiSysmodule::onInput(u32 kdown) {
inputButtons(kdown);
if (kdown & KEY_B)
if (kdown & HidNpadButton_B)
Gui::g_nextGui = GUI_MAIN;
if (hidMitmInstalled() && kdown & KEY_X)
if (hidMitmInstalled() && kdown & HidNpadButton_X)
Gui::g_nextGui = GUI_HID_MITM;
}

View File

@ -63,7 +63,7 @@ GuiTitleList::GuiTitleList() : Gui() {
}
};
appButton->inputAction = [&, app](u64 kdown, bool *isActivated) {
if (kdown & KEY_A) {
if (kdown & HidNpadButton_A) {
//convert title id to a hex string
char buffer[17];
@ -127,6 +127,6 @@ void GuiTitleList::draw() {
void GuiTitleList::onInput(u32 kdown) {
if (inputButtons(kdown)) return;
if (kdown & KEY_B)
if (kdown & HidNpadButton_B)
Gui::g_nextGui = GUI_OVERRIDE_KEY;
}

View File

@ -85,28 +85,28 @@ ListSelector *ListSelector::setInputAction(std::function<void(u32, u16)> inputAc
}
void ListSelector::onInput(u32 kdown) {
if (kdown & KEY_B)
if (kdown & HidNpadButton_B)
startYOffsetNext = 500;
if (kdown & KEY_UP)
if (kdown & HidNpadButton_AnyUp)
if (m_selectedItem > 0)
m_selectedItem--;
if (kdown & KEY_DOWN)
if (kdown & HidNpadButton_AnyDown)
if (m_selectedItem < (static_cast<s16>(m_listItems.size() - 1)))
m_selectedItem++;
m_inputActions(kdown, m_selectedItem);
}
void ListSelector::onTouch(touchPosition &touch) {
if (touch.px > 250 && touch.px < Gui::g_framebuffer_width - 250) {
if (touch.py > 325 && touch.py < (325 + 60 * 5)) {
s8 touchPos = ((touch.py - 325) / 60.0F); //325 + 60 * (currItem + 2)
void ListSelector::onTouch(HidTouchState &touch) {
if (touch.x > 250 && touch.x < Gui::g_framebuffer_width - 250) {
if (touch.y > 325 && touch.y < (325 + 60 * 5)) {
s8 touchPos = ((touch.y - 325) / 60.0F); //325 + 60 * (currItem + 2)
if ((m_selectedItem + touchPos - 2) >= 0 && (m_selectedItem + touchPos - 2) <= (static_cast<s16>(m_listItems.size() - 1))) {
if ((touchPos - 2) == 0)
m_inputActions(KEY_A, m_selectedItem);
m_inputActions(HidNpadButton_A, m_selectedItem);
else
m_selectedItem += (touchPos - 2);
}

View File

@ -56,40 +56,40 @@ void MessageBox::draw(Gui *gui) {
void MessageBox::onInput(u32 kdown) {
if (m_options == MessageBox::OKAY) {
if (kdown & KEY_A || kdown & KEY_B) {
if (kdown & HidNpadButton_A || kdown & HidNpadButton_B) {
this->hide();
}
} else if (m_options == MessageBox::YES_NO) {
if (kdown & KEY_LEFT)
if (kdown & HidNpadButton_AnyLeft)
m_selectedOption = fmax(0, m_selectedOption - 1);
if (kdown & KEY_RIGHT)
if (kdown & HidNpadButton_AnyRight)
m_selectedOption = fmin(1, m_selectedOption + 1);
if (kdown & KEY_A) {
if (kdown & HidNpadButton_A) {
m_selectionAction(m_selectedOption);
}
if (kdown & KEY_B) {
if (kdown & HidNpadButton_B) {
m_selectionAction(BUTTON_NO);
this->hide();
}
}
}
void MessageBox::onTouch(touchPosition &touch) {
void MessageBox::onTouch(HidTouchState &touch) {
if (m_options == MessageBox::OKAY) {
if (touch.px > 250 && touch.py > Gui::g_framebuffer_height - 260 && touch.px < Gui::g_framebuffer_width - 250 && touch.py < Gui::g_framebuffer_height - 180) {
if (touch.x > 250 && touch.y > Gui::g_framebuffer_height - 260 && touch.x < Gui::g_framebuffer_width - 250 && touch.y < Gui::g_framebuffer_height - 180) {
m_selectionAction(BUTTON_OKAY);
this->hide();
}
} else if (m_options == MessageBox::YES_NO) {
if (touch.px > 250 && touch.py > Gui::g_framebuffer_height - 260 && touch.px < 250 + (Gui::g_framebuffer_width - 500) / 2 && touch.py < Gui::g_framebuffer_height - 180) {
if (touch.x > 250 && touch.y > Gui::g_framebuffer_height - 260 && touch.x < 250 + (Gui::g_framebuffer_width - 500) / 2 && touch.y < Gui::g_framebuffer_height - 180) {
if (m_selectedOption != BUTTON_YES)
m_selectedOption = BUTTON_YES;
else
m_selectionAction(BUTTON_YES);
} else if (touch.px > 250 + (Gui::g_framebuffer_width - 500) / 2 && touch.py > Gui::g_framebuffer_height - 260 && touch.px < Gui::g_framebuffer_width - 250 && touch.py < Gui::g_framebuffer_height - 180) {
} else if (touch.x > 250 + (Gui::g_framebuffer_width - 500) / 2 && touch.y > Gui::g_framebuffer_height - 260 && touch.x < Gui::g_framebuffer_width - 250 && touch.y < Gui::g_framebuffer_height - 180) {
if (m_selectedOption != BUTTON_NO)
m_selectedOption = BUTTON_NO;
else
@ -98,7 +98,7 @@ void MessageBox::onTouch(touchPosition &touch) {
}
}
void MessageBox::onGesture(touchPosition startPosition, touchPosition endPosition, bool finish) {
void MessageBox::onGesture(HidTouchState &startPosition, HidTouchState &endPosition, bool finish) {
}
void MessageBox::setProgress(s8 progress) {

View File

@ -47,12 +47,9 @@ void update() {
}
int main(int argc, char **argv) {
u64 kdown = 0;
u64 kheld = 0;
u64 lastkheld = 0;
u64 kheldTime = 0;
touchPosition touch;
u8 touchCntOld = 0, touchCnt = 0;
PadState pad;
PadRepeater padRepeater;
s32 prev_touchcount=0;
socketInitializeDefault();
nxlinkStdio();
@ -78,23 +75,17 @@ int main(int argc, char **argv) {
updateThreadRunning = true;
std::thread updateThread(update);
touchCntOld = hidTouchCount();
// Initialize our input (max players, accept input from all controllers, enable repeat input initialize touchscreen)
padConfigureInput(8, HidNpadStyleSet_NpadStandard);
padInitializeAny(&pad);
padRepeaterInitialize(&padRepeater, KREPEAT_MIN_HOLD, KREPEAT_INTERVAL);
hidInitializeTouchScreen();
while (appletMainLoop()) {
hidScanInput();
kdown = 0;
kheld = 0;
for (u8 controller = 0; controller < 10; controller++) {
kdown |= hidKeysDown(static_cast<HidControllerID>(controller));
kheld |= hidKeysHeld(static_cast<HidControllerID>(controller));
}
if ((kheld & (KEY_UP | KEY_DOWN | KEY_LEFT | KEY_RIGHT)) && kheld == lastkheld)
kheldTime++;
else
kheldTime = 0;
lastkheld = kheld;
padUpdate(&pad);
// accept repeat input but only from directional buttons
padRepeaterUpdate(&padRepeater, padGetButtons(&pad) & (HidNpadButton_AnyLeft | HidNpadButton_AnyUp | HidNpadButton_AnyRight | HidNpadButton_AnyDown));
u64 kdown = padGetButtonsDown(&pad) | padRepeaterGetButtons(&padRepeater);
if (Gui::g_nextGui != GUI_INVALID) {
mutexLock(&mutexCurrGui);
@ -138,35 +129,25 @@ int main(int argc, char **argv) {
Gui::g_currListSelector->onInput(kdown);
else if (Gui::g_currMessageBox != nullptr)
Gui::g_currMessageBox->onInput(kdown);
else if ((kdown & KEY_PLUS) && !Gui::g_exitBlocked)
else if ((kdown & HidNpadButton_Plus) && !Gui::g_exitBlocked)
break;
else
currGui->onInput(kdown);
}
if (kheldTime >= KREPEAT_MIN_HOLD && (kheldTime % KREPEAT_INTERVAL == 0)) {
if (Gui::g_currListSelector != nullptr)
Gui::g_currListSelector->onInput(kheld);
else if (Gui::g_currMessageBox != nullptr)
Gui::g_currMessageBox->onInput(kheld);
else
currGui->onInput(kheld);
HidTouchScreenState state={0};
if (hidGetTouchScreenStates(&state, 1)) {
if (state.count > prev_touchcount) {
if (Gui::g_currListSelector != nullptr)
Gui::g_currListSelector->onTouch(state.touches[0]);
else if (Gui::g_currMessageBox != nullptr)
Gui::g_currMessageBox->onTouch(state.touches[0]);
else
currGui->onTouch(state.touches[0]);
}
prev_touchcount = state.count;
}
touchCnt = hidTouchCount();
if (touchCnt > touchCntOld) {
hidTouchRead(&touch, 0);
if (Gui::g_currListSelector != nullptr)
Gui::g_currListSelector->onTouch(touch);
else if (Gui::g_currMessageBox != nullptr)
Gui::g_currMessageBox->onTouch(touch);
else
currGui->onTouch(touch);
}
touchCntOld = touchCnt;
if (g_exitApplet)
break;
}

View File

@ -16,43 +16,43 @@ OverrideKey OverrideKey::StringToKeyCombo(const char *keyString) {
}
if (strcasecmp(keyString, "A") == 0) {
keyCombo.key = KEY_A;
keyCombo.key = HidNpadButton_A;
} else if (strcasecmp(keyString, "B") == 0) {
keyCombo.key = KEY_B;
keyCombo.key = HidNpadButton_B;
} else if (strcasecmp(keyString, "X") == 0) {
keyCombo.key = KEY_X;
keyCombo.key = HidNpadButton_X;
} else if (strcasecmp(keyString, "Y") == 0) {
keyCombo.key = KEY_Y;
keyCombo.key = HidNpadButton_Y;
} else if (strcasecmp(keyString, "LS") == 0) {
keyCombo.key = KEY_LSTICK;
keyCombo.key = HidNpadButton_StickL;
} else if (strcasecmp(keyString, "RS") == 0) {
keyCombo.key = KEY_RSTICK;
keyCombo.key = HidNpadButton_StickR;
} else if (strcasecmp(keyString, "L") == 0) {
keyCombo.key = KEY_L;
keyCombo.key = HidNpadButton_L;
} else if (strcasecmp(keyString, "R") == 0) {
keyCombo.key = KEY_R;
keyCombo.key = HidNpadButton_R;
} else if (strcasecmp(keyString, "ZL") == 0) {
keyCombo.key = KEY_ZL;
keyCombo.key = HidNpadButton_ZL;
} else if (strcasecmp(keyString, "ZR") == 0) {
keyCombo.key = KEY_ZR;
keyCombo.key = HidNpadButton_ZR;
} else if (strcasecmp(keyString, "PLUS") == 0) {
keyCombo.key = KEY_PLUS;
keyCombo.key = HidNpadButton_Plus;
} else if (strcasecmp(keyString, "MINUS") == 0) {
keyCombo.key = KEY_MINUS;
keyCombo.key = HidNpadButton_Minus;
} else if (strcasecmp(keyString, "DLEFT") == 0) {
keyCombo.key = KEY_DLEFT;
keyCombo.key = HidNpadButton_Left;
} else if (strcasecmp(keyString, "DUP") == 0) {
keyCombo.key = KEY_DUP;
keyCombo.key = HidNpadButton_Up;
} else if (strcasecmp(keyString, "DRIGHT") == 0) {
keyCombo.key = KEY_DRIGHT;
keyCombo.key = HidNpadButton_Right;
} else if (strcasecmp(keyString, "DDOWN") == 0) {
keyCombo.key = KEY_DDOWN;
keyCombo.key = HidNpadButton_Down;
} else if (strcasecmp(keyString, "SL") == 0) {
keyCombo.key = KEY_SL;
keyCombo.key = HidNpadButton_AnySL;
} else if (strcasecmp(keyString, "SR") == 0) {
keyCombo.key = KEY_SR;
keyCombo.key = HidNpadButton_AnySR;
} else {
keyCombo.key = static_cast<HidControllerKeys>(0);
keyCombo.key = static_cast<HidNpadButton>(0);
}
return keyCombo;
@ -62,24 +62,24 @@ std::string OverrideKey::KeyComboToString(const OverrideKey &keyCombo) {
std::string keyString;
switch (keyCombo.key) {
// clang-format off
case KEY_A: keyString = "A"; break;
case KEY_B: keyString = "B"; break;
case KEY_X: keyString = "X"; break;
case KEY_Y: keyString = "Y"; break;
case KEY_LSTICK: keyString = "LS"; break;
case KEY_RSTICK: keyString = "RS"; break;
case KEY_L: keyString = "L"; break;
case KEY_R: keyString = "R"; break;
case KEY_ZL: keyString = "ZL"; break;
case KEY_ZR: keyString = "ZR"; break;
case KEY_PLUS: keyString = "PLUS"; break;
case KEY_MINUS: keyString = "MINUS"; break;
case KEY_DLEFT: keyString = "DLEFT"; break;
case KEY_DUP: keyString = "DUP"; break;
case KEY_DRIGHT: keyString = "DRIGHT"; break;
case KEY_DDOWN: keyString = "DDOWN"; break;
case KEY_SL: keyString = "SL"; break;
case KEY_SR: keyString = "SR"; break;
case HidNpadButton_A: keyString = "A"; break;
case HidNpadButton_B: keyString = "B"; break;
case HidNpadButton_X: keyString = "X"; break;
case HidNpadButton_Y: keyString = "Y"; break;
case HidNpadButton_StickL: keyString = "LS"; break;
case HidNpadButton_StickR: keyString = "RS"; break;
case HidNpadButton_L: keyString = "L"; break;
case HidNpadButton_R: keyString = "R"; break;
case HidNpadButton_ZL: keyString = "ZL"; break;
case HidNpadButton_ZR: keyString = "ZR"; break;
case HidNpadButton_Plus: keyString = "PLUS"; break;
case HidNpadButton_Minus: keyString = "MINUS"; break;
case HidNpadButton_Left: keyString = "DLEFT"; break;
case HidNpadButton_Up: keyString = "DUP"; break;
case HidNpadButton_Right: keyString = "DRIGHT"; break;
case HidNpadButton_Down: keyString = "DDOWN"; break;
case HidNpadButton_AnySL: keyString = "SL"; break;
case HidNpadButton_AnySR: keyString = "SR"; break;
default: keyString = ""; break;
// clang-format on
}
@ -87,27 +87,27 @@ std::string OverrideKey::KeyComboToString(const OverrideKey &keyCombo) {
return (keyCombo.overrideByDefault ? "!" : "") + keyString;
}
const char *OverrideKey::KeyToUnicode(HidControllerKeys key) {
const char *OverrideKey::KeyToUnicode(HidNpadButton key) {
switch (key) {
// clang-format off
case KEY_A: return "\uE0E0";
case KEY_B: return "\uE0E1";
case KEY_X: return "\uE0E2";
case KEY_Y: return "\uE0E3";
case KEY_LSTICK: return "\uE101";
case KEY_RSTICK: return "\uE102";
case KEY_L: return "\uE0E4";
case KEY_R: return "\uE0E5";
case KEY_ZL: return "\uE0E6";
case KEY_ZR: return "\uE0E7";
case KEY_PLUS: return "\uE0EF";
case KEY_MINUS: return "\uE0F0";
case KEY_DLEFT: return "\uE0ED";
case KEY_DUP: return "\uE0EB";
case KEY_DRIGHT: return "\uE0EE";
case KEY_DDOWN: return "\uE0EC";
case KEY_SL: return "\uE0E8";
case KEY_SR: return "\uE0E9";
case HidNpadButton_A: return "\uE0E0";
case HidNpadButton_B: return "\uE0E1";
case HidNpadButton_X: return "\uE0E2";
case HidNpadButton_Y: return "\uE0E3";
case HidNpadButton_StickL: return "\uE101";
case HidNpadButton_StickR: return "\uE102";
case HidNpadButton_L: return "\uE0E4";
case HidNpadButton_R: return "\uE0E5";
case HidNpadButton_ZL: return "\uE0E6";
case HidNpadButton_ZR: return "\uE0E7";
case HidNpadButton_Plus: return "\uE0EF";
case HidNpadButton_Minus: return "\uE0F0";
case HidNpadButton_Left: return "\uE0ED";
case HidNpadButton_Up: return "\uE0EB";
case HidNpadButton_Right: return "\uE0EE";
case HidNpadButton_Down: return "\uE0EC";
case HidNpadButton_AnySL: return "\uE0E8";
case HidNpadButton_AnySR: return "\uE0E9";
default: return "";
// clang-format on
}