Skip to content

Commit d35e661

Browse files
committed
Refactor internal "highRes" funcs to "dataMode"
This isn't explicitly about high resolution mode anymore, but about reading the current data mode of the controller. The public-facing functions will still be kept as "highRes" because it's more idiomatic to check whether a specific mode is 'true' rather than trying to match up the boolean values to a specific mode.
1 parent 65b1a22 commit d35e661

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/controllers/ClassicController.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,17 +105,17 @@ 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 'writeHighRes' function also checks the current mode of the controller
108+
* The 'setDataMode' 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-
return writeHighRes(true); // 'success' if no comms errors
115+
return setDataMode(true); // try to set 'high res' mode. 'success' if no comms errors
116116
}
117117

118-
boolean ClassicController_Shared::checkHighRes(boolean *hr) const {
118+
boolean ClassicController_Shared::checkDataMode(boolean *hr) const {
119119
/* Programmator Emptor: vvv This is where all of the headaches stem from vvv */
120120

121121
/* Okay, so here's the deal. The Wii Classic Controller reports its data
@@ -182,12 +182,12 @@ boolean ClassicController_Shared::checkHighRes(boolean *hr) const {
182182
return true; // successfully read state
183183
}
184184

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

189189
boolean currentMode = false; // check controller's HR setting
190-
if (!checkHighRes(&currentMode)) return false; // error: could not read mode
190+
if (!checkDataMode(&currentMode)) return false; // error: could not read mode
191191
highRes = currentMode; // save current mode to class
192192

193193
if (getHighRes() == true && getRequestSize() < 8) {
@@ -202,7 +202,7 @@ boolean ClassicController_Shared::writeHighRes(boolean hr) {
202202

203203
boolean ClassicController_Shared::setHighRes(boolean hr) {
204204
// 'success' if the mode is changed to the one we're trying to set
205-
return writeHighRes(hr) && (getHighRes() == hr);
205+
return setDataMode(hr) && (getHighRes() == hr);
206206
}
207207

208208
boolean ClassicController_Shared::getHighRes() const {

src/controllers/ClassicController.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,9 @@ namespace NintendoExtensionCtrl {
156156

157157
protected:
158158
boolean highRes = false; // 'high resolution' mode setting
159-
boolean checkHighRes(boolean *hr) const;
160-
boolean writeHighRes(boolean hr);
159+
160+
boolean checkDataMode(boolean *hr) const;
161+
boolean setDataMode(boolean hr);
161162
};
162163

163164

0 commit comments

Comments
 (0)