1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-11-28 12:22:02 +00:00

Updater JC color swapper to latest libnx

This commit is contained in:
flb 2020-12-28 14:27:24 +01:00
parent 7d1710c68d
commit dd19949328
3 changed files with 24 additions and 21 deletions

View file

@ -45,7 +45,7 @@ DATA := data
INCLUDES := include lib/zipper/include INCLUDES := include lib/zipper/include
APP_TITLE := All-in-One Switch Updater APP_TITLE := All-in-One Switch Updater
APP_AUTHOR := HamletDuFromage APP_AUTHOR := HamletDuFromage
APP_VERSION := 1.3.1 APP_VERSION := 1.3.2
TARGET := $(notdir $(CURDIR))-v$(APP_VERSION) TARGET := $(notdir $(CURDIR))-v$(APP_VERSION)
ROMFS := resources ROMFS := resources

View file

@ -1,6 +1,7 @@
#pragma once #pragma once
#include <iomanip> #include <iomanip>
#include <string>
#include <fstream> #include <fstream>
#include <sstream> #include <sstream>
#include <filesystem> #include <filesystem>
@ -10,6 +11,7 @@
#include <switch.h> #include <switch.h>
#include "constants.hpp" #include "constants.hpp"
#include "progress_event.hpp" #include "progress_event.hpp"
#include "utils.hpp"
#include "json.hpp" #include "json.hpp"
int hexToBGR(std::string hex); int hexToBGR(std::string hex);

View file

@ -28,9 +28,9 @@ int setColor(std::vector<int> colors){
Result pads, ljc, rjc; Result pads, ljc, rjc;
int res = 0; int res = 0;
s32 nbEntries; s32 nbEntries;
u64 UniquePadIds[2] = {}; HidsysUniquePadId UniquePadIds[2] = {};
pads = hidsysGetUniquePadsFromNpad(CONTROLLER_HANDHELD, UniquePadIds, 2,&nbEntries); pads = hidsysGetUniquePadsFromNpad(HidNpadIdType_Handheld, UniquePadIds, 2,&nbEntries);
if(R_SUCCEEDED(pads)){ if(R_SUCCEEDED(pads)){
ljc = hiddbgUpdateControllerColor(colors[0], colors[1], UniquePadIds[0]); ljc = hiddbgUpdateControllerColor(colors[0], colors[1], UniquePadIds[0]);
if (R_FAILED(ljc)) res +=1; if (R_FAILED(ljc)) res +=1;
@ -44,10 +44,11 @@ int setColor(std::vector<int> colors){
} }
int backupToJSON(json &profiles, const char* path){ int backupToJSON(json &profiles, const char* path){
HidControllerColors colors; HidNpadControllerColor color_left;
hidGetControllerColors(CONTROLLER_P1_AUTO, &colors); HidNpadControllerColor color_right;
Result res = hidGetNpadControllerColorSplit(HidNpadIdType_Handheld, &color_left, &color_right);
std::vector<int> oldBackups; std::vector<int> oldBackups;
if (colors.splitSet) { if (R_SUCCEEDED(res)) {
int i = 0; int i = 0;
for (const auto& x : profiles.items()){ for (const auto& x : profiles.items()){
if(x.value()["name"] == "_backup") { if(x.value()["name"] == "_backup") {
@ -60,10 +61,10 @@ int backupToJSON(json &profiles, const char* path){
} }
json newBackup = json::object({ json newBackup = json::object({
{"name", "_backup"}, {"name", "_backup"},
{"L_JC", BGRToHex(colors.leftColorBody)}, {"L_JC", BGRToHex(color_left.main)},
{"L_BTN", BGRToHex(colors.leftColorButtons)}, {"L_BTN", BGRToHex(color_left.sub)},
{"R_JC", BGRToHex(colors.rightColorBody)}, {"R_JC", BGRToHex(color_right.main)},
{"R_BTN", BGRToHex(colors.rightColorButtons)} {"R_BTN", BGRToHex(color_right.sub)}
}); });
profiles.push_back(newBackup); profiles.push_back(newBackup);
writeJSONToFile(profiles, path); writeJSONToFile(profiles, path);
@ -76,16 +77,16 @@ int backupToJSON(json &profiles, const char* path){
json backupProfile(){ json backupProfile(){
json newBackup; json newBackup;
HidControllerColors colors; HidNpadControllerColor color_left;
hidGetControllerColors(CONTROLLER_P1_AUTO, &colors); HidNpadControllerColor color_right;
//if(0){ Result res = hidGetNpadControllerColorSplit(HidNpadIdType_Handheld, &color_left, &color_right);
if (colors.splitSet) { if (R_SUCCEEDED(res)) {
newBackup = json::object({ newBackup = json::object({
{"name", "_backup"}, {"name", "_backup"},
{"L_JC", BGRToHex(colors.leftColorBody)}, {"L_JC", BGRToHex(color_left.main)},
{"L_BTN", BGRToHex(colors.leftColorButtons)}, {"L_BTN", BGRToHex(color_left.sub)},
{"R_JC", BGRToHex(colors.rightColorBody)}, {"R_JC", BGRToHex(color_right.main)},
{"R_BTN", BGRToHex(colors.rightColorButtons)} {"R_BTN", BGRToHex(color_right.sub)}
}); });
} }
return newBackup; return newBackup;
@ -153,9 +154,9 @@ void changeJCColor(std::vector<int> values){
hidsysInitialize(); hidsysInitialize();
ProgressEvent::instance().reset(); ProgressEvent::instance().reset();
ProgressEvent::instance().setStep(1); ProgressEvent::instance().setStep(1);
int res = -1; int res = setColor(values);
while(res !=0){ if(res != 0){
res = setColor(values); showDialogBox("Could not change the Joy-Cons color. Make sure they're docked and try again.\nError :" + std::to_string(res), "Ok");
} }
hiddbgExit(); hiddbgExit();
hidsysExit(); hidsysExit();