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

(WIP-ish) custom presets implementation #6

Merged
merged 4 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 61 additions & 0 deletions constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ enum boardTypes_e {
arduinoNanoRP2040,
waveshareZero,
vccgndYD,
presetBoardsCount,
generic = 255
};

Expand Down Expand Up @@ -109,6 +110,66 @@ enum layoutTypes_e {
layoutDiamond
};

const uint8_t boardCustomPresetsCount[presetBoardsCount] = {
0, // padding
1, // rpipico
1, // rpipicow
2, // itsybitsy
0, // KB2040
0, // arduinoNano
0, // waveshareZero
0, // vccgnd
};

const QStringList rpipicoPresetsList = {
"EZCon"
};

const QStringList adafruitItsyBitsyRP2040PresetsList = {
"SAMCO 2.0",
"SAMCO 1.1"
};

/* Inputs map order:
* Trigger, A, B, C, Start, Select,
* Up, Down, Left, Right, Pedal, Pedal2,
* Home, Pump, Rumble Sig, Solenoid Sig, Rumble Switch, Solenoid Switch,
* Autofire Switch, NeoPixel, LEDR, LEDG, LEDB, Camera SDA,
* Camera SCL, Periph SDA, Periph SCL, Battery, Analog X, Analog Y,
* Temperature
*/

const int8_t rpipicoPresets[1][boardInputsCount-1] = {
// name 1: this is currently a placeholder for testing
{1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1,
-1, -1, -1, -1, -1, -1,
-1}
,
// name 2: subsequent layouts go here
};

const int8_t adafruitItsyBitsyRP2040Presets[2][boardInputsCount-1] = {
// SAMCO 2.0
{6, 27, 26, -1, 28, 29,
9, 7, 8, 10, 4, -1,
11, -1, 24, 25, -1, -1,
-1, -1, -1, -1, -1, 2,
3, -1, -1, -1, -1, -1,
-1}
,
// SAMCO 1.1
{10, 6, 7, -1, -1, -1,
-1, -1, -1, -1, 27, -1,
9, -1, 8, -1, -1, -1,
-1, -1, -1, -1, -1, 2,
3, -1, -1, -1, -1, -1,
-1}
,
};

typedef struct boardInfo_t {
uint8_t type = nothing;
float versionNumber = 0.0;
Expand Down
58 changes: 58 additions & 0 deletions guiwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1402,6 +1402,22 @@ void guiWindow::BoxesFill()
pinBoxes[i]->insertSeparator(periphSCL);
}
}
if(boardCustomPresetsCount[board.type]) {
ui->presetsBox->clear();
switch(board.type) {
case rpipico:
case rpipicow:
ui->presetsBox->setEnabled(true);
ui->presetsBox->addItems(rpipicoPresetsList);
break;
case adafruitItsyRP2040:
ui->presetsBox->setEnabled(true);
ui->presetsBox->addItems(adafruitItsyBitsyRP2040PresetsList);
break;
default:
ui->presetsBox->setEnabled(false);
}
}
BoxesUpdate();
}

Expand Down Expand Up @@ -1453,6 +1469,10 @@ void guiWindow::pinBoxes_activated(int index)
}
}

if(ui->presetsBox->currentIndex() > -1) {
ui->presetsBox->setCurrentIndex(-1);
}

if(!index) {
inputsMap[currentPins.value(pin) - 1] = -1;
currentPins[pin] = btnUnmapped;
Expand Down Expand Up @@ -1598,6 +1618,44 @@ void guiWindow::on_customPinsEnabled_stateChanged(int arg1)
}


void guiWindow::on_presetsBox_currentIndexChanged(int index)
{
if(index > -1) {
if(!ui->customPinsEnabled->isChecked()) { ui->customPinsEnabled->setChecked(true); }
for(uint8_t i = 0; i < 30; i++) {
pinBoxes[i]->setCurrentIndex(btnUnmapped);
pinBoxesOldIndex[i] = btnUnmapped;
currentPins[i] = btnUnmapped;
}
for(uint8_t i = 0; i < boardInputsCount-1; i++) {
switch(board.type) {
case rpipico:
case rpipicow:
if(rpipicoPresets[index][i] > -1) {
pinBoxes[rpipicoPresets[index][i]]->setCurrentIndex(i+1);
pinBoxesOldIndex[rpipicoPresets[index][i]] = i+1;
currentPins[rpipicoPresets[index][i]] = i+1;
}
inputsMap[i] = rpipicoPresets[index][i];
break;
case adafruitItsyRP2040:
if(adafruitItsyBitsyRP2040Presets[index][i] > -1) {
pinBoxes[adafruitItsyBitsyRP2040Presets[index][i]]->setCurrentIndex(i+1);
pinBoxesOldIndex[adafruitItsyBitsyRP2040Presets[index][i]] = i+1;
currentPins[adafruitItsyBitsyRP2040Presets[index][i]] = i+1;
}
inputsMap[i] = adafruitItsyBitsyRP2040Presets[index][i];
break;
default:
// lol wut
break;
}
}
DiffUpdate();
}
}


void guiWindow::on_rumbleToggle_stateChanged(int arg1)
{
boolSettings[rumble] = arg1;
Expand Down
2 changes: 2 additions & 0 deletions guiwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ private slots:

void on_customPinsEnabled_stateChanged(int arg1);

void on_presetsBox_currentIndexChanged(int index);

void on_rumbleTestBtn_clicked();

void on_solenoidTestBtn_clicked();
Expand Down
74 changes: 44 additions & 30 deletions guiwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -137,36 +137,50 @@
<item>
<layout class="QHBoxLayout" name="PinsTopHalf"/>
</item>
<item alignment="Qt::AlignmentFlag::AlignBottom">
<widget class="QCheckBox" name="customPinsEnabled">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>20</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>Enable to use custom pins mapping, or disable to use the default mappings for the current board.</string>
</property>
<property name="text">
<string>Use Custom Pins</string>
</property>
</widget>
<item>
<layout class="QHBoxLayout" name="PinsBottomHalf">
<item alignment="Qt::AlignmentFlag::AlignBottom">
<widget class="QCheckBox" name="customPinsEnabled">
<property name="enabled">
<bool>true</bool>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>20</height>
</size>
</property>
<property name="baseSize">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
<property name="toolTip">
<string>Enable to use custom pins mapping, or disable to use the default mappings for the current board.</string>
</property>
<property name="text">
<string>Use Custom Pins</string>
</property>
</widget>
</item>
<item alignment="Qt::AlignmentFlag::AlignRight|Qt::AlignmentFlag::AlignBottom">
<widget class="QComboBox" name="presetsBox">
<property name="enabled">
<bool>false</bool>
</property>
<property name="placeholderText">
<string>Preset Layouts</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
Expand Down