Skip to content

Commit 65b1a22

Browse files
committed
Use internal function to read CC high res success
This allows 'specificInit' to return false and fail the connection check if there's a communication error, instead of approving the connection and continuing without knowing the controller's current data mode.
1 parent eddd9f7 commit 65b1a22

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

src/controllers/ClassicController.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,16 +105,14 @@ boolean ClassicController_Shared::specificInit() {
105105
/* On init, try to set the controller to work in "high resolution" mode so
106106
* we get a full byte of data for each analog input.
107107
*
108-
* The 'setHighRes' function also checks the current mode of the controller
108+
* The 'writeHighRes' function also checks the current mode of the controller
109109
* after the HR setting is set, so the data maps should match the data
110110
* reporting type. This way the class flexes to support controllers that
111111
* only work in standard mode, only work in high res mode, or can support
112112
* both.
113113
*/
114114
delayMicroseconds(I2C_ConversionDelay); // wait after ID read before writing register
115-
setHighRes(true); // attempt to set, otherwise will read mode from controller
116-
117-
return true; // unconditional connection
115+
return writeHighRes(true); // 'success' if no comms errors
118116
}
119117

120118
boolean ClassicController_Shared::checkHighRes(boolean *hr) const {
@@ -184,7 +182,7 @@ boolean ClassicController_Shared::checkHighRes(boolean *hr) const {
184182
return true; // successfully read state
185183
}
186184

187-
boolean ClassicController_Shared::setHighRes(boolean hr) {
185+
boolean ClassicController_Shared::writeHighRes(boolean hr) {
188186
const uint8_t regVal = hr ? 0x03 : 0x01; // 0x03 for high res, 0x01 for standard
189187
if (!writeRegister(0xFE, regVal)) return false; // write to controller
190188

@@ -199,7 +197,12 @@ boolean ClassicController_Shared::setHighRes(boolean hr) {
199197
setRequestSize(MinRequestSize); // if not in HR and *trying* not to be, set back to min
200198
}
201199

202-
return hr == highRes; // 'success' if the value we're setting is the one we read
200+
return true; // 'success' if no communication errors, regardless of setting
201+
}
202+
203+
boolean ClassicController_Shared::setHighRes(boolean hr) {
204+
// 'success' if the mode is changed to the one we're trying to set
205+
return writeHighRes(hr) && (getHighRes() == hr);
203206
}
204207

205208
boolean ClassicController_Shared::getHighRes() const {

src/controllers/ClassicController.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@ namespace NintendoExtensionCtrl {
157157
protected:
158158
boolean highRes = false; // 'high resolution' mode setting
159159
boolean checkHighRes(boolean *hr) const;
160+
boolean writeHighRes(boolean hr);
160161
};
161162

162163

0 commit comments

Comments
 (0)