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

Macros Web Config pin 0 fix #937

Merged
merged 1 commit into from
Apr 4, 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
2 changes: 1 addition & 1 deletion headers/addons/input_macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#endif

#ifndef INPUT_MACRO_BOARD_LED_ENABLED
#define INPUT_MACRO_BOARD_LED_ENABLED 1
#define INPUT_MACRO_BOARD_LED_ENABLED 0
#endif

#ifndef INPUT_MACRO_PIN
Expand Down
40 changes: 28 additions & 12 deletions src/config_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,20 @@ void ConfigUtils::initUnsetPropertiesWithDefaults(Config& config)
// Macro options (always on)
INIT_UNSET_PROPERTY(config.addonOptions.macroOptions, enabled, true);
INIT_UNSET_PROPERTY(config.addonOptions.macroOptions, macroBoardLedEnabled, INPUT_MACRO_BOARD_LED_ENABLED);
config.addonOptions.macroOptions.macroList_count = MAX_MACRO_LIMIT;
INIT_UNSET_PROPERTY(config.addonOptions.macroOptions, deprecatedPin, -1);

// Set all macros
for(int i = 0; i < MAX_MACRO_LIMIT; i++) {
INIT_UNSET_PROPERTY(config.addonOptions.macroOptions.macroList[i], enabled, 0);
INIT_UNSET_PROPERTY(config.addonOptions.macroOptions.macroList[i], exclusive, 1);
INIT_UNSET_PROPERTY(config.addonOptions.macroOptions.macroList[i], interruptible, 1);
INIT_UNSET_PROPERTY(config.addonOptions.macroOptions.macroList[i], showFrames, 1);
INIT_UNSET_PROPERTY(config.addonOptions.macroOptions.macroList[i], macroType, MacroType::ON_PRESS);
INIT_UNSET_PROPERTY(config.addonOptions.macroOptions.macroList[i], useMacroTriggerButton, 0);
INIT_UNSET_PROPERTY(config.addonOptions.macroOptions.macroList[i], macroTriggerButton, 0);
INIT_UNSET_PROPERTY_STR(config.addonOptions.macroOptions.macroList[i], macroLabel, "");
INIT_UNSET_PROPERTY(config.addonOptions.macroOptions.macroList[i], deprecatedMacroTriggerPin, -1);
}
}


Expand Down Expand Up @@ -1282,18 +1295,21 @@ void migrateMacroPinsToGpio(Config& config) {
macroOptions.has_deprecatedPin = false;
}

const static GpioAction actionList[6] = { GpioAction::BUTTON_PRESS_MACRO_1, GpioAction::BUTTON_PRESS_MACRO_2,
GpioAction::BUTTON_PRESS_MACRO_3, GpioAction::BUTTON_PRESS_MACRO_4,
GpioAction::BUTTON_PRESS_MACRO_5, GpioAction::BUTTON_PRESS_MACRO_6 };
for(int i = 0; i < 6; i++ ) {
if ( macroOptions.macroList[i].has_deprecatedMacroTriggerPin && isValidPin(macroOptions.macroList[i].deprecatedMacroTriggerPin) ) {
Pin_t pin = macroOptions.macroList[i].deprecatedMacroTriggerPin;
config.gpioMappings.pins[pin].action = actionList[i];
for (uint8_t profileNum = 0; profileNum <= 2; profileNum++) {
config.profileOptions.gpioMappingsSets[profileNum].pins[pin].action = actionList[i];
if ( macroOptions.macroList_count == MAX_MACRO_LIMIT ) {
const static GpioAction actionList[6] = { GpioAction::BUTTON_PRESS_MACRO_1, GpioAction::BUTTON_PRESS_MACRO_2,
GpioAction::BUTTON_PRESS_MACRO_3, GpioAction::BUTTON_PRESS_MACRO_4,
GpioAction::BUTTON_PRESS_MACRO_5, GpioAction::BUTTON_PRESS_MACRO_6 };
for(int i = 0; i < MAX_MACRO_LIMIT; i++ ) {
if ( macroOptions.macroList[i].has_deprecatedMacroTriggerPin &&
isValidPin(macroOptions.macroList[i].deprecatedMacroTriggerPin) ) {
Pin_t pin = macroOptions.macroList[i].deprecatedMacroTriggerPin;
config.gpioMappings.pins[pin].action = actionList[i];
for (uint8_t profileNum = 0; profileNum <= 2; profileNum++) {
config.profileOptions.gpioMappingsSets[profileNum].pins[pin].action = actionList[i];
}
macroOptions.macroList[i].deprecatedMacroTriggerPin = -1; // set our turbo options to -1 for subsequent calls
macroOptions.macroList[i].has_deprecatedMacroTriggerPin = false;
}
macroOptions.macroList[i].deprecatedMacroTriggerPin = -1; // set our turbo options to -1 for subsequent calls
macroOptions.macroList[i].has_deprecatedMacroTriggerPin = false;
}
}
}
Expand Down
37 changes: 16 additions & 21 deletions www/src/Pages/InputMacroAddonPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,13 @@ import { AppContext } from '../Contexts/AppContext';
import { Badge, Button, Col, Form, Nav, OverlayTrigger, Row, Tab, Table, Tooltip } from 'react-bootstrap';
import { Formik, useFormikContext } from 'formik';
import * as yup from 'yup';
import { Trans, useTranslation } from 'react-i18next';
import { useTranslation } from 'react-i18next';
import omit from 'lodash/omit';
import zip from 'lodash/zip';

import Section from '../Components/Section';
import CaptureButton from '../Components/CaptureButton';
import FormControl from '../Components/FormControl';
import WebApi from '../Services/WebApi';
import { getButtonLabels, BUTTONS, BUTTON_MASKS } from '../Data/Buttons';

import usePinStore from '../Store/usePinStore';

type PinCell = [string, PinActionValues];
type PinRow = [PinCell, PinCell];
type PinList = [PinRow];

const MACRO_TYPES = [
{ label: 'InputMacroAddon:input-macro-type.press', value: 1 },
{ label: 'InputMacroAddon:input-macro-type.hold-repeat', value: 2 },
Expand Down Expand Up @@ -52,21 +43,25 @@ const MACRO_INPUTS_MAX = 30;

const MACRO_LIMIT = 6;

const defaultMacroInput = { buttonMask: 0, duration: 16666, waitDuration: 0 };
const defaultMacroInput = {
buttonMask: 0,
duration: 16666,
waitDuration: 0
};

const defaultValues = {
macroList: Array(MACRO_LIMIT).fill({
macroType: 1,
macroLabel: '',
enabled: 1,
enabled: 0,
exclusive: 1,
interruptible: 1,
showFrames: 1,
useMacroTriggerButton: 0,
macroTriggerButton: 0,
macroInputs: [defaultMacroInput],
}),
macroBoardLedEnabled: 1,
macroBoardLedEnabled: 0,
};

const EMPTY_INPUT = null;
Expand Down Expand Up @@ -163,8 +158,8 @@ const MacroInputComponent = (props) => {
return (
<Row key={key} className="py-2 flex-nowrap">
<Col style={{
'min-width': '150px',
'max-width': '150px',
'minWidth': '150px',
'maxWidth': '150px',
}}>
<Row className="d-flex justify-content-center">
<Col sm={6} className="px-0">
Expand Down Expand Up @@ -241,12 +236,12 @@ const MacroInputComponent = (props) => {
</Row>
</Col>
<Col style={{
'min-width': '125px',
'max-width': '125px',
'minWidth': '125px',
'maxWidth': '125px',
}} className="d-flex justify-content-center text-nowrap"> release and wait </Col>
<Col style={{
'min-width': '150px',
'max-width': '150px',
'minWidth': '150px',
'maxWidth': '150px',
}}>
<Row className="d-flex justify-content-center">
<Col sm={6} className="px-0">
Expand Down Expand Up @@ -555,11 +550,11 @@ export default function MacrosPage() {
<Row>
<Col sm={2}>
<Nav variant="pills" className="flex-column text-nowrap">
<Nav.Item>
<Nav.Item key="pills-header">
<Nav.Link eventKey="settings">{t('InputMacroAddon:input-macro-header-text')}</Nav.Link>
</Nav.Item>
{values.macroList.map((macro, i) => (
<Nav.Item>
<Nav.Item key={`pills-item-${i}`}>
<Nav.Link eventKey={`macro-${i}`}>
{macro.macroLabel.length == 0 ? `Macro ${i+1}` :
macro.macroLabel.length > 24 ?
Expand Down