Skip to content

Commit c8f0057

Browse files
committed
Make verification optional for CC setHighRes
As requested in #63. Useful for testing or if the user wants to implement their own verification function.
1 parent d1a0c63 commit c8f0057

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

src/controllers/ClassicController.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,18 @@ boolean ClassicController_Shared::checkDataMode(boolean *hr) const {
184184
return true; // successfully read state
185185
}
186186

187-
boolean ClassicController_Shared::setDataMode(boolean hr) {
187+
boolean ClassicController_Shared::setDataMode(boolean hr, boolean verify) {
188188
const uint8_t regVal = hr ? 0x03 : 0x01; // 0x03 for high res, 0x01 for standard
189189
if (!writeRegister(0xFE, regVal)) return false; // write to controller
190190

191-
boolean currentMode = false; // check controller's HR setting
192-
if (!checkDataMode(&currentMode)) return false; // error: could not read mode
193-
highRes = currentMode; // save current mode to class
191+
if (verify == true) {
192+
boolean currentMode = false; // check controller's HR setting
193+
if (!checkDataMode(&currentMode)) return false; // error: could not read mode
194+
highRes = currentMode; // save current mode to class
195+
}
196+
else {
197+
highRes = hr; // save mode (no verification)
198+
}
194199

195200
if (getHighRes() == true && getRequestSize() < 8) {
196201
setRequestSize(8); // 8 bytes needed for hr mode
@@ -202,9 +207,9 @@ boolean ClassicController_Shared::setDataMode(boolean hr) {
202207
return true; // 'success' if no communication errors, regardless of setting
203208
}
204209

205-
boolean ClassicController_Shared::setHighRes(boolean hr) {
210+
boolean ClassicController_Shared::setHighRes(boolean hr, boolean verify) {
206211
// 'success' if the mode is changed to the one we're trying to set
207-
return setDataMode(hr) && (getHighRes() == hr);
212+
return setDataMode(hr, verify) && (getHighRes() == hr);
208213
}
209214

210215
boolean ClassicController_Shared::getHighRes() const {

src/controllers/ClassicController.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ namespace NintendoExtensionCtrl {
116116

117117
boolean specificInit();
118118

119-
boolean setHighRes(boolean hr = true);
119+
boolean setHighRes(boolean hr = true, boolean verify = true);
120120
boolean getHighRes() const;
121121

122122
uint8_t leftJoyX() const; // 8 bits, 6 shifted in std mode
@@ -158,7 +158,7 @@ namespace NintendoExtensionCtrl {
158158
boolean highRes = false; // 'high resolution' mode setting
159159

160160
boolean checkDataMode(boolean *hr) const;
161-
boolean setDataMode(boolean hr);
161+
boolean setDataMode(boolean hr, boolean verify = true);
162162
};
163163

164164

0 commit comments

Comments
 (0)