Skip to content
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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Kyokatarz
Copy link

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

Comment on lines +45 to +54
// 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

Copy link
Author

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"

Comment on lines +96 to +104
void updateEEPROM(int address, int newValue) {
int readState = EEPROM.read(address);

if (readState == newValue) return;

EEPROM.update(address, newValue);
delay(200);
}

Copy link
Author

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

Comment on lines +118 to +139
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);
Copy link
Author

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

Copy link
Author

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

Comment on lines +147 to +150
int CONTROL_MODE = EEPROM.read(EEPROM_CONTROL_ADDRESS);

if (CONTROL_MODE == MODE_JOYSTICK) joy_mode();
else if (CONTROL_MODE == MODE_KEYBOARD) keyboard_mode();
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tiny refactor here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant