-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support lightless mode #5
base: master
Are you sure you want to change the base?
Conversation
// Define modes | ||
#define MODE_JOYSTICK 1 | ||
#define MODE_KEYBOARD 2 | ||
#define MODE_LIGHT_ON 1 | ||
#define MODE_LIGHT_OFF 0 | ||
|
||
// Eeprom addresses | ||
#define EEPROM_CONTROL_ADDRESS 0 | ||
#define EEPROM_LIGHT_ADDRESS 1 | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Define new variables for later autocomplete. No more "Which one is joystick mode, which one is keyboard mode"
void updateEEPROM(int address, int newValue) { | ||
int readState = EEPROM.read(address); | ||
|
||
if (readState == newValue) return; | ||
|
||
EEPROM.update(address, newValue); | ||
delay(200); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor updating EEPROM into a function, no need to delay(200) everywhere anymore. Now automatically delay(200) if an update is done
int Button3State = digitalRead(BT_C); //Read Btn-C | ||
|
||
bool IsButtonAPressed = Button1State == LOW; | ||
bool IsButtonBPressed = Button2State == LOW; | ||
bool IsButtonCPressed = Button3State == LOW; | ||
|
||
bool UseJoystick = IsButtonAPressed && !IsButtonBPressed; | ||
bool UseKeyboard = IsButtonBPressed && !IsButtonAPressed; | ||
bool UseLight = !IsButtonCPressed; | ||
|
||
if (UseJoystick) { | ||
updateEEPROM(EEPROM_CONTROL_ADDRESS, MODE_JOYSTICK); | ||
} else if (UseKeyboard) { | ||
updateEEPROM(EEPROM_CONTROL_ADDRESS, MODE_KEYBOARD); | ||
} else { | ||
updateEEPROM(EEPROM_CONTROL_ADDRESS, MODE_JOYSTICK); | ||
} | ||
|
||
if (UseLight) { | ||
updateEEPROM(EEPROM_LIGHT_ADDRESS, MODE_LIGHT_ON); | ||
} else { | ||
updateEEPROM(EEPROM_LIGHT_ADDRESS, MODE_LIGHT_OFF); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactored this as well :D
If C button is pressed then update EEPROM address to LIGHT_OFF, then later in the lights() function it will check if the light address is on or off and determine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that it's independent of control mode
So if (B + C) is pressed -> Keyboard mode and lightless
Joystick with light on by default
int CONTROL_MODE = EEPROM.read(EEPROM_CONTROL_ADDRESS); | ||
|
||
if (CONTROL_MODE == MODE_JOYSTICK) joy_mode(); | ||
else if (CONTROL_MODE == MODE_KEYBOARD) keyboard_mode(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tiny refactor here
I don't have a controller with me to test :( If you have one in handy, can you debug/modify this so it works? :D