Skip to content

Commit

Permalink
Add AM32 settings and descriptions. Allow for a slider to be dragged …
Browse files Browse the repository at this point in the history
…into a 'disabled' state. #373 (#374)
  • Loading branch information
stylesuxx authored May 9, 2023
1 parent 85592ef commit 3433cee
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 5 deletions.
3 changes: 3 additions & 0 deletions src/Components/Flash/CommonSettings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ function CommonSettings({
availableSettings[setting.name] = value;
}

let disableValue = description.disableValue || null;

switch (setting.type) {
case 'bool': {
return (
Expand Down Expand Up @@ -226,6 +228,7 @@ function CommonSettings({

return (
<Slider
disableValue={disableValue}
disabled={disabled}
factor={setting.displayFactor}
hint={hint}
Expand Down
16 changes: 15 additions & 1 deletion src/Components/Input/Slider/index.jsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useTranslation } from 'react-i18next';
import PropTypes from 'prop-types';
import React, {
useCallback,
Expand All @@ -14,6 +15,7 @@ import './style.scss';
function Slider({
name,
value,
disableValue,
step,
min,
max,
Expand All @@ -27,6 +29,8 @@ function Slider({
hint,
disabled,
}) {
const { t } = useTranslation('common');

const [currentValue, setCurrentValue] = useState(value);
useEffect(() => {
setCurrentValue(value);
Expand Down Expand Up @@ -60,7 +64,15 @@ function Slider({
}, 100);
}, [onChange, offset, factor, name]);

const format = useCallback((value) => `${value}${suffix}`, [suffix]);
const format = useCallback((value) => {
let label = `${value}${suffix}`;

if (value === disableValue) {
label = t("disabled");
}

return label;
}, [suffix, disableValue, t]);

return (
<div className="number">
Expand Down Expand Up @@ -92,6 +104,7 @@ function Slider({
}

Slider.defaultProps = {
disableValue: null,
disabled: false,
factor: 1,
hint: null,
Expand All @@ -106,6 +119,7 @@ Slider.defaultProps = {
};

Slider.propTypes = {
disableValue: PropTypes.number,
disabled: PropTypes.bool,
factor: PropTypes.number,
hint: PropTypes.string,
Expand Down
13 changes: 11 additions & 2 deletions src/sources/AM32/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ describe('AM32', () => {
const keys = Object.keys(SETTINGS_DESCRIPTIONS.COMMON);
const settings = { VARIABLE_PWM_FREQUENCY: 0 };

let truthy = 0;
let falsy = 0;
const visibleIf = [];
for(let i = 0; i < keys.length; i += 1) {
const revision = keys[i];
Expand All @@ -17,11 +19,18 @@ describe('AM32', () => {
visibleIf.push(current.visibleIf);
}
}

for(let i = 0; i < visibleIf.length; i += 1) {
expect(visibleIf[i](settings)).toBeTruthy();
const result = visibleIf[i](settings);
if (result) {
truthy += 1;
} else {
falsy += 1;
}
}
}

expect(truthy).toEqual(6);
expect(falsy).toEqual(2);
});

it('should return display name', () => {
Expand Down
16 changes: 16 additions & 0 deletions src/sources/AM32/eeprom.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,22 @@ const LAYOUT = {
offset: 0x29,
size: 1,
},
RUNNING_BRAKE_LEVEL: {
offset: 0x2A,
size: 1,
},
TEMPERATURE_LIMIT: {
offset: 0x2B,
size: 1,
},
CURRENT_LIMIT: {
offset: 0x2C,
size: 1,
},
SINE_MODE_POWER: {
offset: 0x2D,
size: 1,
},
ESC_PROTOCOL: {
offset: 0x2E,
size: 1,
Expand Down
41 changes: 41 additions & 0 deletions src/sources/AM32/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ const SETTINGS_LAYOUT_2 = [
min: 5,
max: 25,
step: 1,
visibleIf: (settings) => settings.SINUSOIDAL_STARTUP === 1,
},
{
name: 'BRAKE_STRENGTH',
Expand Down Expand Up @@ -200,6 +201,42 @@ const SETTINGS_LAYOUT_2 = [
},
],
},
{
name: 'RUNNING_BRAKE_LEVEL',
type: 'number',
label: 'am32RunningBrakeLevel',
min: 0,
max: 10,
step: 1,
},
{
name: 'TEMPERATURE_LIMIT',
type: 'number',
label: 'am32TemperatureLimit',
min: 70,
max: 141,
step: 1,
disableValue: 141,
},
{
name: 'CURRENT_LIMIT',
type: 'number',
label: 'am32CurrentLimit',
min: 0,
max: 202,
step: 2,
displayFactor: 2,
disableValue: 202,
},
{
name: 'SINE_MODE_POWER',
type: 'number',
label: 'am32SineModePower',
min: 1,
max: 10,
step: 1,
visibleIf: (settings) => settings.SINUSOIDAL_STARTUP === 1,
},
];

const COMMON = {
Expand Down Expand Up @@ -284,6 +321,10 @@ const DEFAULT_SETTINGS_2 = {
USE_HALL_SENSORS: 0,
SINE_MODE_RANGE: 8,
BRAKE_STRENGTH: 10,
RUNNING_BRAKE_LEVEL: 10,
TEMPERATURE_LIMIT: 141,
CURRENT_LIMIT: 101,
SINE_MODE_POWER: 6,
ESC_PROTOCOL: 0,
};

Expand Down
7 changes: 6 additions & 1 deletion src/translations/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@
"escHallSensors": "Hall Sensors",
"escSineModeRange": "Sine Mode Range",
"escBrakeStrength": "Braking Strength",
"am32RunningBrakeLevel": "Running Brake Level",
"am32TemperatureLimit": "Temperature Limit",
"am32CurrentLimit": "Current Limit",
"am32SineModePower": "Sine Mode Power",
"bluejayTextLine1": "Bluejay is BLHeli_S based firmware capable of bi-directional DShot - so a great choice if you want to run RPM filtering on your rig. This project also aims to clean up and simplify the original BLHeli_S source code.",
"bluejayTextLine2": "A startup sound editor is also part of the deal.",
"bluejaySupportedHardwareLine1": "Please take the time to help us document hardware on which you have successfully flashed and tested Bluejay by [adding it to the Wiki](https://github.com/bird-sanctuary/bluejay/wiki/Tested-Hardware).",
Expand Down Expand Up @@ -181,5 +185,6 @@
"mistaggedTagged": "Tagged",
"mistaggedDetected": "Detected",
"update": "Update available! To update the app, refresh or restart it.",
"resettingDevice": "Resetting device..."
"resettingDevice": "Resetting device...",
"disabled": "Disabled"
}
6 changes: 5 additions & 1 deletion src/translations/en/hints.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,9 @@
"PWM_THRESHOLD_HIGH": "Above this throttle, a 24kHz PWM signal will be used.",
"FORCE_EDT_ARM": "Only arm after successfull EDT handshake. Flight controller firmware has to support this feature.",
"ESC_PROTOCOL": "Select the ESC protocol you want to use. This is for safety, with a preselected esc protocol, false throttle signale detections are prevented!",
"RCPULSE_FILTER": "Values above 0 will enable the RC pulse filter, the higher the number the more aggressive the filter. Only use to compensate for really bad tunes."
"RCPULSE_FILTER": "Values above 0 will enable the RC pulse filter, the higher the number the more aggressive the filter. Only use to compensate for really bad tunes.",
"RUNNING_BRAKE_LEVEL": "The tamount of braking used when the motor is running.",
"TEMPERATURE_LIMIT": "Will significantly decrease maximum power when threshold is reached.",
"CURRENT_LIMIT": "Will hold the maximum possible RPM at the allowed current.",
"SINE_MODE_POWER": "Fixed duty cycle level to be used when using sine mode. CAUTION: Values above 6 might damage motor and/or ESC."
}

0 comments on commit 3433cee

Please sign in to comment.