Skip to content
This repository has been archived by the owner on Feb 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #151 from deeebug/button-layout-to-webconfig
Browse files Browse the repository at this point in the history
Add left and right screen layout to web config (#106)
  • Loading branch information
arntsonl authored Nov 22, 2022
2 parents 18c6ec8 + ef173c8 commit 6e3405f
Show file tree
Hide file tree
Showing 8 changed files with 31,847 additions and 31,615 deletions.
5 changes: 5 additions & 0 deletions include/storagemanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ struct BoardOptions
uint8_t pinSliderLS;
uint8_t pinSliderRS;
ButtonLayout buttonLayout;
ButtonLayoutRight buttonLayoutRight;
int i2cSDAPin;
int i2cSCLPin;
int i2cBlock;
Expand Down Expand Up @@ -139,6 +140,10 @@ class Storage {

void ResetSettings(); // EEPROM Reset Feature

int GetButtonLayout();

int GetButtonLayoutRight();

private:
Storage() : gamepad(0) {
EEPROM.start(); // init EEPROM
Expand Down
63,338 changes: 31,741 additions & 31,597 deletions lib/httpd/fsdata.c

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions src/addons/i2cdisplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void I2CDisplayAddon::process() {
drawSplashScreen(SPLASH_MODE, 90);
} else {
drawStatusBar(gamepad);
switch (BUTTON_LAYOUT)
switch (Storage::getInstance().GetButtonLayout())
{
case BUTTON_LAYOUT_STICK:
drawArcadeStick(8, 28, 8, 2);
Expand Down Expand Up @@ -84,7 +84,7 @@ void I2CDisplayAddon::process() {
break;
}

switch (BUTTON_LAYOUT_RIGHT)
switch (Storage::getInstance().GetButtonLayoutRight())
{
case BUTTON_LAYOUT_ARCADE:
drawArcadeButtons(8, 28, 8, 2);
Expand Down
36 changes: 20 additions & 16 deletions src/configs/webconfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,14 +159,16 @@ std::string setDisplayOptions()
{
DynamicJsonDocument doc = get_post_data();
BoardOptions boardOptions = Storage::getInstance().getBoardOptions();
boardOptions.hasI2CDisplay = doc["enabled"];
boardOptions.i2cSDAPin = doc["sdaPin"] == -1 ? 0xFF : doc["sdaPin"];
boardOptions.i2cSCLPin = doc["sclPin"] == -1 ? 0xFF : doc["sclPin"];
boardOptions.displayI2CAddress = doc["i2cAddress"];
boardOptions.i2cBlock = doc["i2cBlock"];
boardOptions.i2cSpeed = doc["i2cSpeed"];
boardOptions.displayFlip = doc["flipDisplay"];
boardOptions.displayInvert = doc["invertDisplay"];
boardOptions.hasI2CDisplay = doc["enabled"];
boardOptions.i2cSDAPin = doc["sdaPin"] == -1 ? 0xFF : doc["sdaPin"];
boardOptions.i2cSCLPin = doc["sclPin"] == -1 ? 0xFF : doc["sclPin"];
boardOptions.displayI2CAddress = doc["i2cAddress"];
boardOptions.i2cBlock = doc["i2cBlock"];
boardOptions.i2cSpeed = doc["i2cSpeed"];
boardOptions.displayFlip = doc["flipDisplay"];
boardOptions.displayInvert = doc["invertDisplay"];
boardOptions.buttonLayout = doc["buttonLayout"];
boardOptions.buttonLayoutRight = doc["buttonLayoutRight"];
ConfigManager::getInstance().setBoardOptions(boardOptions);
return serialize_json(doc);
}
Expand All @@ -175,14 +177,16 @@ std::string getDisplayOptions() // Manually set Document Attributes for the disp
{
DynamicJsonDocument doc(LWIP_HTTPD_POST_MAX_PAYLOAD_LEN);
BoardOptions boardOptions = Storage::getInstance().getBoardOptions();
doc["enabled"] = boardOptions.hasI2CDisplay ? 1 : 0;
doc["sdaPin"] = boardOptions.i2cSDAPin == 0xFF ? -1 : boardOptions.i2cSDAPin;
doc["sclPin"] = boardOptions.i2cSCLPin == 0xFF ? -1 : boardOptions.i2cSCLPin;
doc["i2cAddress"] = boardOptions.displayI2CAddress;
doc["i2cBlock"] = boardOptions.i2cBlock;
doc["i2cSpeed"] = boardOptions.i2cSpeed;
doc["flipDisplay"] = boardOptions.displayFlip ? 1 : 0;
doc["invertDisplay"] = boardOptions.displayInvert ? 1 : 0;
doc["enabled"] = boardOptions.hasI2CDisplay ? 1 : 0;
doc["sdaPin"] = boardOptions.i2cSDAPin == 0xFF ? -1 : boardOptions.i2cSDAPin;
doc["sclPin"] = boardOptions.i2cSCLPin == 0xFF ? -1 : boardOptions.i2cSCLPin;
doc["i2cAddress"] = boardOptions.displayI2CAddress;
doc["i2cBlock"] = boardOptions.i2cBlock;
doc["i2cSpeed"] = boardOptions.i2cSpeed;
doc["flipDisplay"] = boardOptions.displayFlip ? 1 : 0;
doc["invertDisplay"] = boardOptions.displayInvert ? 1 : 0;
doc["buttonLayout"] = boardOptions.buttonLayout;
doc["buttonLayoutRight"] = boardOptions.buttonLayoutRight;

Gamepad * gamepad = Storage::getInstance().GetGamepad();
auto usedPins = doc.createNestedArray("usedPins");
Expand Down
11 changes: 11 additions & 0 deletions src/storagemanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ void Storage::setDefaultBoardOptions()
boardOptions.pinSliderLS = PIN_SLIDER_LS;
boardOptions.pinSliderRS = PIN_SLIDER_RS;
boardOptions.buttonLayout = BUTTON_LAYOUT;
boardOptions.buttonLayoutRight = BUTTON_LAYOUT_RIGHT;
boardOptions.i2cSDAPin = I2C_SDA_PIN;
boardOptions.i2cSCLPin = I2C_SCL_PIN;
boardOptions.i2cBlock = (I2C_BLOCK == i2c0) ? 0 : 1;
Expand Down Expand Up @@ -209,6 +210,16 @@ uint8_t * Storage::GetFeatureData()
return featureData;
}

int Storage::GetButtonLayout()
{
return boardOptions.buttonLayout;
}

int Storage::GetButtonLayoutRight()
{
return boardOptions.buttonLayoutRight;
}

/* Animation stuffs */
AnimationOptions AnimationStorage::getAnimationOptions()
{
Expand Down
2 changes: 2 additions & 0 deletions www/server/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ app.get('/api/getDisplayOptions', (req, res) => {
i2cSpeed: 400000,
flipDisplay: 0,
invertDisplay: 1,
buttonLayout: 0,
buttonLayoutRight: 0
});
});

Expand Down
64 changes: 64 additions & 0 deletions www/src/Pages/DisplayConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,36 @@ const I2C_BLOCKS = [
{ label: 'i2c1', value: 1 },
];

const BUTTON_LAYOUT = [
{ label: 'Stick', value: 0 }, // BUTTON_LAYOUT_STICK
{ label: 'Stickless', value: 1 }, // BUTTON_LAYOUT_STICKLESS
{ label: 'Buttons Angled', value: 2 }, // BUTTON_LAYOUT_BUTTONS_ANGLED
{ label: 'Buttons Basic', value: 3 }, // BUTTON_LAYOUT_BUTTONS_BASIC
{ label: 'Keyboard Angled', value: 4 }, // BUTTON_LAYOUT_KEYBOARD_ANGLED
{ label: 'Keyboard', value: 5 }, // BUTTON_LAYOUT_KEYBOARDA
{ label: 'Dancepad', value: 6 }, // BUTTON_LAYOUT_DANCEPADA
{ label: 'Twinstick', value: 7 }, // BUTTON_LAYOUT_TWINSTICKA
{ label: 'Blank', value: 8 }, // BUTTON_LAYOUT_BLANKA
{ label: 'VLX', value: 9 } // BUTTON_LAYOUT_VLXA
];

const BUTTON_LAYOUT_RIGHT = [
{ label: 'Arcade', value: 0 }, // BUTTON_LAYOUT_ARCADE
{ label: 'Stickless', value: 1 }, // BUTTON_LAYOUT_STICKLESSB
{ label: 'Buttons Angled', value: 2 }, // BUTTON_LAYOUT_BUTTONS_ANGLEDB
{ label: 'Viewlix', value: 3 }, // BUTTON_LAYOUT_VEWLIX
{ label: 'Viewlix 7', value: 4 }, // BUTTON_LAYOUT_VEWLIX7
{ label: 'Capcom', value: 5 }, // BUTTON_LAYOUT_CAPCOM
{ label: 'Capcom 6', value: 6 }, // BUTTON_LAYOUT_CAPCOM6
{ label: 'Sega 2P', value: 7 }, // BUTTON_LAYOUT_SEGA2P
{ label: 'Noir 8', value: 8 }, // BUTTON_LAYOUT_NOIR8
{ label: 'Keyboard', value: 9 }, // BUTTON_LAYOUT_KEYBOARDB
{ label: 'Dancepad', value: 10 }, // BUTTON_LAYOUT_DANCEPADB
{ label: 'Twinstick', value: 11 }, // BUTTON_LAYOUT_TWINSTICKB
{ label: 'Blank', value: 12 }, // BUTTON_LAYOUT_BLANKB
{ label: 'VLX', value: 13 } // BUTTON_LAYOUT_VLXB
];

const defaultValues = {
enabled: false,
sdaPin: -1,
Expand All @@ -26,6 +56,8 @@ const defaultValues = {
i2cSpeed: 400000,
flipDisplay: false,
invertDisplay: false,
buttonLayout: 0,
buttonLayoutRight: 0
};

let usedPins = [];
Expand All @@ -41,6 +73,8 @@ const schema = yup.object().shape({
i2cSpeed: yup.number().required().label('I2C Speed'),
flipDisplay: yup.number().label('Flip Display'),
invertDisplay: yup.number().label('Invert Display'),
buttonLayout: yup.number().required().oneOf(BUTTON_LAYOUT.map(o => o.value)).label('Button Layout Left'),
buttonLayoutRight: yup.number().required().oneOf(BUTTON_LAYOUT_RIGHT.map(o => o.value)).label('Button Layout Right'),
});

const FormContext = () => {
Expand All @@ -64,6 +98,10 @@ const FormContext = () => {
values.flipDisplay = parseInt(values.flipDisplay);
if (!!values.invertDisplay)
values.invertDisplay = parseInt(values.invertDisplay);
if (!!values.buttonLayout)
values.buttonLayout = parseInt(values.buttonLayout);
if (!!values.buttonLayoutRight)
values.buttonLayoutRight = parseInt(values.buttonLayoutRight);
}, [values, setValues]);

return null;
Expand Down Expand Up @@ -237,6 +275,32 @@ export default function DisplayConfigPage() {
{ON_OFF_OPTIONS.map((o, i) => <option key={`invertDisplay-option-${i}`} value={o.value}>{o.label}</option>)}
</FormSelect>
</Row>
<Row className="mb-3">
<FormSelect
label="Button Layout (Left)"
name="buttonLayout"
className="form-select-sm"
groupClassName="col-sm-3 mb-3"
value={values.buttonLayout}
error={errors.buttonLayout}
isInvalid={errors.buttonLayout}
onChange={handleChange}
>
{BUTTON_LAYOUT.map((o, i) => <option key={`buttonLayout-option-${i}`} value={o.value}>{o.label}</option>)}
</FormSelect>
<FormSelect
label="Button Layout (Right)"
name="buttonLayoutRight"
className="form-select-sm"
groupClassName="col-sm-3 mb-3"
value={values.buttonLayoutRight}
error={errors.buttonLayoutRight}
isInvalid={errors.buttonLayoutRight}
onChange={handleChange}
>
{BUTTON_LAYOUT_RIGHT.map((o, i) => <option key={`buttonLayoutRight-option-${i}`} value={o.value}>{o.label}</option>)}
</FormSelect>
</Row>
<div className="mt-3">
<Button type="submit">Save</Button>
{saveMessage ? <span className="alert">{saveMessage}</span> : null}
Expand Down
2 changes: 2 additions & 0 deletions www/src/Services/WebApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ async function getDisplayOptions() {
async function setDisplayOptions(options) {
let newOptions = { ...options };
newOptions.i2cAddress = parseInt(options.i2cAddress);
newOptions.buttonLayout = parseInt(options.buttonLayout);
newOptions.buttonLayoutRight = parseInt(options.buttonLayoutRight);
return axios.post(`${baseUrl}/api/setDisplayOptions`, newOptions)
.then((response) => {
console.log(response.data);
Expand Down

0 comments on commit 6e3405f

Please sign in to comment.