Skip to content

Commit

Permalink
Merge pull request #174 from mikeller/add_open_esc_support
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeller committed Nov 7, 2020
2 parents 99ca741 + 8f015df commit ace2ec2
Show file tree
Hide file tree
Showing 19 changed files with 441 additions and 312 deletions.
33 changes: 33 additions & 0 deletions _locales/en/messages.json
Expand Up @@ -274,12 +274,45 @@
"escIgnoreInappropriateMCULayoutWarning": {
"message": "(Flashing inappropriate firmware may damage your ESC, do so at your own risk)"
},
"escDirectionReversed": {
"message": "Direction Reversed"
},
"escBidirectionalMode": {
"message": "Bidirectional Mode"
},
"escSinusoidalStartup": {
"message": "Sinusoidal Startup"
},
"escComplementaryPwm": {
"message": "Complementary PWM"
},
"escVariablePwmFrequency": {
"message": "Variable PWM Frequency"
},
"escStuckRotorProtection": {
"message": "Stuck Rotor Protection"
},
"escTimingAdvance": {
"message": "Timing Advance (degrees)"
},
"escPwmFrequency": {
"message": "PWM Frequency (kHz)"
},
"escMotorKv": {
"message": "Motor KV"
},
"escMotorPoles": {
"message": "Motor Poles"
},
"buttonCancel": {
"message": "Cancel"
},
"hexInvalidSiLabs": {
"message": "HEX does not look like a valid SiLabs BLHeli flash file"
},
"hexInvalidArm": {
"message": "HEX does not look like a valid ARM Open ESC flash file"
},

"readSetupStarted": {
"message": "Reading setup"
Expand Down
7 changes: 7 additions & 0 deletions gulpfile.js
Expand Up @@ -185,6 +185,13 @@ gulp.task('dist', ['clean-dist', 'build-js'], function () {
'./js/blheli_versions.js',
'./js/blheli_versions.json',
'./js/blheli_defaults.js',
'./js/open_esc_escs.js',
'./js/open_esc_escs.json',
'./js/open_esc_versions.js',
'./js/open_esc_versions.json',
'./js/open_esc_defaults.js',
'./js/open_esc_eeprom_layout.js',
'./js/open_esc_settings_description.js',
'./js/fetch_json.js',
// Configurator components
'./js/build/*.js',
Expand Down
3 changes: 1 addition & 2 deletions js/_4way_if.js
Expand Up @@ -45,8 +45,7 @@ var _4way_modes = {
SiLBLB: 1,
AtmBLB: 2,
AtmSK: 3,
ARMBLB: 4

ARMBLB: 4,
};

function _4way_command_to_string(command) {
Expand Down
24 changes: 12 additions & 12 deletions js/blheli_eeprom_layout.js
Expand Up @@ -90,19 +90,19 @@ function blheliModeToString(mode) {
}
}

function blheliSettingsObject(settingsUint8Array) {
function blheliSettingsObject(settingsUint8Array, layout) {
var object = {};

for (var prop in BLHELI_LAYOUT) {
if (BLHELI_LAYOUT.hasOwnProperty(prop)) {
let setting = BLHELI_LAYOUT[prop];
for (var prop in layout) {
if (layout.hasOwnProperty(prop)) {
let setting = layout[prop];

if (setting.size === 1) {
object[prop] = settingsUint8Array[setting.offset];
} else if (setting.size === 2) {
object[prop] = (settingsUint8Array[setting.offset] << 8) | settingsUint8Array[setting.offset + 1];
} else if (setting.size === 16) {
object[prop] = String.fromCharCode.apply(undefined, settingsUint8Array.subarray(setting.offset).subarray(0, 16)).trim();
} else if (setting.size > 2 ) {
object[prop] = String.fromCharCode.apply(undefined, settingsUint8Array.subarray(setting.offset).subarray(0, setting.size)).trim();
} else {
throw new Error('Logic error')
}
Expand All @@ -112,19 +112,19 @@ function blheliSettingsObject(settingsUint8Array) {
return object;
}

function blheliSettingsArray(settingsObject) {
var array = new Uint8Array(BLHELI_LAYOUT_SIZE).fill(0xff);
function blheliSettingsArray(settingsObject, layout, layoutSize) {
var array = new Uint8Array(layoutSize).fill(0xff);

for (var prop in BLHELI_LAYOUT) {
if (BLHELI_LAYOUT.hasOwnProperty(prop)) {
let setting = BLHELI_LAYOUT[prop];
for (var prop in layout) {
if (layout.hasOwnProperty(prop)) {
let setting = layout[prop];

if (setting.size === 1) {
array[setting.offset] = settingsObject[prop];
} else if (setting.size === 2) {
array[setting.offset] = (settingsObject[prop] >> 8) & 0xff;
array[setting.offset + 1] = (settingsObject[prop]) & 0xff;
} else if (setting.size === 16) {
} else if (setting.size > 2) {
for (let i = 0, len = settingsObject[prop].length; i < setting.size; ++i) {
array[setting.offset + i] = i < len ? settingsObject[prop].charCodeAt(i) : ' '.charCodeAt(0);
}
Expand Down
21 changes: 11 additions & 10 deletions js/flashing_helpers.js
Expand Up @@ -62,10 +62,10 @@ function selectFile(ext) {
var reader = new FileReader();

reader.onprogress = function (e) {
if (e.total > 32 * 1024) {
// 32 KiB
deferred.reject('File size limit of 32 KiB exceeded');
}
// if (e.total > 32 * 1024) {
// // 32 KiB
// deferred.reject('File size limit of 32 KiB exceeded');
// }
};

reader.onloadend = function (e) {
Expand Down Expand Up @@ -112,12 +112,13 @@ function saveFile(str) {
}

// Fills a memory image of ESC MCU's address space with target firmware
function fillImage(data, size) {
function fillImage(data, size, flashOffset) {
var image = new Uint8Array(size).fill(0xFF);

data.data.forEach(function (block) {
let address = block.address - flashOffset;
// Check preconditions
if (block.address >= image.byteLength) {
if (address >= image.byteLength) {
// if (block.address == BLHELI_SILABS_BOOTLOADER_ADDRESS) {
// GUI.log('Block at 0x' + block.address.toString(0x10) + ' of 0x' + block.bytes.toString(0x10) + ' bytes contains bootloader, skipping\n');
// } else {
Expand All @@ -127,13 +128,13 @@ function fillImage(data, size) {
return;
}

if (block.address + block.bytes >= image.byteLength) {}
if (address + block.bytes >= image.byteLength) {}
// GUI.log('Block at 0x' + block.address.toString(0x10) + ' spans past the end of target address space\n');


// block.data may be too large, select maximum allowed size
var clamped_length = Math.min(block.bytes, image.byteLength - block.address);
image.set(block.data.slice(0, clamped_length), block.address);
var clamped_length = Math.min(block.bytes, image.byteLength - address);
image.set(block.data.slice(0, clamped_length), address);
});

return image;
Expand Down Expand Up @@ -184,4 +185,4 @@ function setToLocalStorage(key, content) {
});

return deferred.promise;
}
}
18 changes: 18 additions & 0 deletions js/open_esc_defaults.js
@@ -0,0 +1,18 @@
'use strict';

var OPEN_ESC_DEFAULTS = {
'0': {
MOTOR_DIRECTION: 0,
BIDIRECTIONAL_MODE: 0,
SINUSOIDAL_STARTUP: 0,
COMPLEMENTARY_PWM: 1,
VARIABLE_PWM_FREQUENCY: 1,
STUCK_ROTOR_PROTECTION: 1,
TIMING_ADVANCE: 2,
PWM_FREQUENCY: 24,
STARTUP_POWER: 100,
MOTOR_KV: 55,
MOTOR_POLES: 14,
BRAKE_ON_STOP: 1,
}
};
32 changes: 32 additions & 0 deletions js/open_esc_eeprom_layout.js
@@ -0,0 +1,32 @@
'use strict';

const OPEN_ESC_TYPES = {
ARM: 'Arm'
};

const OPEN_ESC_PAGE_SIZE = 0x0400
const OPEN_ESC_EEPROM_OFFSET = 0x7c00
const OPEN_ESC_LAYOUT_SIZE = 0x30

const OPEN_ESC_LAYOUT = {
BOOT_BYTE: { offset: 0x00, size: 1 },
LAYOUT_REVISION: { offset: 0x01, size: 1 },
BOOT_LOADER_REVISION: { offset: 0x02, size: 1 },
MAIN_REVISION: { offset: 0x03, size: 1 },
SUB_REVISION: { offset: 0x04, size: 1 },

NAME: { offset: 0x05, size: 12 },

MOTOR_DIRECTION: { offset: 0x11, size: 1 },
BIDIRECTIONAL_MODE: { offset: 0x12, size: 1 },
SINUSOIDAL_STARTUP: { offset: 0x13, size: 1 },
COMPLEMENTARY_PWM: { offset: 0x14, size: 1 },
VARIABLE_PWM_FREQUENCY: { offset: 0x15, size: 1 },
STUCK_ROTOR_PROTECTION: { offset: 0x16, size: 1 },
TIMING_ADVANCE: { offset: 0x17, size: 1 },
STARTUP_POWER: { offset: 0x18, size: 1 },
PWM_FREQUENCY: { offset: 0x19, size: 1 },
MOTOR_KV: { offset: 0x1a, size: 1 },
MOTOR_POLES: { offset: 0x1b, size: 1 },
BRAKE_ON_STOP: { offset: 0x1c, size: 1 },
};
3 changes: 3 additions & 0 deletions js/open_esc_escs.js
@@ -0,0 +1,3 @@
var OPEN_ESC_ESCS_REMOTE = 'https://raw.githubusercontent.com/blheli-configurator/blheli-configurator/master/js/open_esc_escs.json';
var OPEN_ESC_ESCS_LOCAL = './js/open_esc_escs.json';
var OPEN_ESC_ESCS_KEY = 'open_esc_escs';
18 changes: 18 additions & 0 deletions js/open_esc_escs.json
@@ -0,0 +1,18 @@
{
"layouts": {
"Arm": {
"FD6288": { "name": "FD6288 based", "fileName": "FD6288" },
"HGLRC60A": { "name": "HGLRC 60A", "fileName": "HGLRC60A" },
"IFLIGHT": { "name": "iFlight 50A", "fileName": "IFLIGHT" },
"MP6531": { "name": "MP6531 based", "fileName": "MP6531" },
"SISKIN": { "name": "Sunrise Siskin", "fileName": "SISKIN" },
"TMOTOR45A": { "name": "T-motor 45A", "fileName": "TMOTOR45A" },
"TMOTOR55A": { "name": "T-motor 55A", "fileName": "TMOTOR55A" }
}
},
"signatures": {
"Arm": [
{ "name": "STM32F051", "signature": "0x1f06", "page_size": 1024, "flash_size": 65536, "flash_offset": "0x08000000", "firmware_start": "0x1000" }
]
}
}
56 changes: 56 additions & 0 deletions js/open_esc_settings_description.js
@@ -0,0 +1,56 @@
'use strict';

var OPEN_ESC_SETTINGS_LAYOUT_0 = [
{
name: 'SINUSOIDAL_STARTUP', type: 'bool', label: 'escSinusoidalStartup'
},
{
name: 'COMPLEMENTARY_PWM', type: 'bool', label: 'escComplementaryPwm'
},
{
name: 'VARIABLE_PWM_FREQUENCY', type: 'bool', label: 'escVariablePwmFrequency'
},
{
name: 'STUCK_ROTOR_PROTECTION', type: 'bool', label: 'escStuckRotorProtection'
},
{
name: 'TIMING_ADVANCE', type: 'number', min: 0, max: 22.5, step: 7.5, label: 'escTimingAdvance', displayFactor: 7.5
},
{
name: 'MOTOR_KV', type: 'number', min: 20, max: 10220, step: 40, label: 'escMotorKv', displayFactor: 40, displayOffset: 20
},
{
name: 'MOTOR_POLES', type: 'number', min: 2, max: 36, step: 1, label: 'escMotorPoles'
},
{
name: 'STARTUP_POWER', type: 'number', min: 50, max: 150, step: 1, label: 'escStartupPower'
},
{
name: 'PWM_FREQUENCY', type: 'number', min: 24, max: 48, step: 1, label: 'escPwmFrequency'
},
{
name: 'BRAKE_ON_STOP', type: 'bool', label: 'escBrakeOnStop'
},
];

var OPEN_ESC_SETTINGS_DESCRIPTIONS = {
'0': {
base: OPEN_ESC_SETTINGS_LAYOUT_0
},
};

// @todo add validation for min/max throttle
var OPEN_ESC_INDIVIDUAL_SETTINGS = [
{
name: 'MOTOR_DIRECTION', type: 'bool', label: 'escDirectionReversed'
},
{
name: 'BIDIRECTIONAL_MODE', type: 'bool', label: 'escBidirectionalMode'
},
];

var OPEN_ESC_INDIVIDUAL_SETTINGS_DESCRIPTIONS = {
'0': {
base: OPEN_ESC_INDIVIDUAL_SETTINGS
},
};
3 changes: 3 additions & 0 deletions js/open_esc_versions.js
@@ -0,0 +1,3 @@
var OPEN_ESC_VERSIONS_REMOTE = 'https://raw.githubusercontent.com/blheli-configurator/blheli-configurator/master/js/open_esc_versions.json';
var OPEN_ESC_VERSIONS_LOCAL = './js/open_esc_versions.json';
var OPEN_ESC_VERSIONS_KEY = 'open_esc_versions';
9 changes: 9 additions & 0 deletions js/open_esc_versions.json
@@ -0,0 +1,9 @@
{
"Arm": [
{
"name": "1.58",
"url": "https://raw.githubusercontent.com/AlkaMotors/AM32-MultiRotor-ESC-firmware/master/Release/1_58/{0}_1_58.hex",
"key": "1.58"
}
]
}
9 changes: 4 additions & 5 deletions jsx/base_components.jsx
Expand Up @@ -67,16 +67,15 @@ var Number = React.createClass({
);
},
handleChange: function(component, value) {
var value = parseInt(value);
if (this.props.offset && this.props.factor) {
value = Math.floor((value - this.props.offset) / this.props.factor);
if (this.props.offset || this.props.factor) {
value = Math.floor((value - (this.props.offset || 0)) / (this.props.factor || 1));
}

this.props.onChange(component.props.name, value);
},
getDisplayValue: function() {
if (this.props.offset && this.props.factor) {
return this.props.factor * this.props.value + this.props.offset;
if (this.props.offset || this.props.factor) {
return this.props.factor * (this.props.value || 1) + (this.props.offset || 0);
}

return this.props.value;
Expand Down

0 comments on commit ace2ec2

Please sign in to comment.