mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-20 14:55:21 +03:00
Merge pull request #3307 from mikeller/add_dshot_command_switch
Changed 'pwmWriteDshotCommand' to use switch for better readability.
This commit is contained in:
commit
dc69c03886
4 changed files with 20 additions and 8 deletions
|
@ -338,11 +338,21 @@ void pwmWriteDshotCommand(uint8_t index, uint8_t command)
|
||||||
motorDmaOutput_t *const motor = getMotorDmaOutput(index);
|
motorDmaOutput_t *const motor = getMotorDmaOutput(index);
|
||||||
|
|
||||||
unsigned repeats;
|
unsigned repeats;
|
||||||
if ((command >= DSHOT_CMD_SPIN_ONE_WAY && command <= DSHOT_CMD_3D_MODE_ON ) || command == DSHOT_CMD_SAVE_SETTINGS || (command >= DSHOT_CMD_ROTATE_NORMAL && command <= DSHOT_CMD_ROTATE_REVERSE) ) {
|
switch (command) {
|
||||||
|
case DSHOT_CMD_SPIN_DIRECTION_1:
|
||||||
|
case DSHOT_CMD_SPIN_DIRECTION_2:
|
||||||
|
case DSHOT_CMD_3D_MODE_OFF:
|
||||||
|
case DSHOT_CMD_3D_MODE_ON:
|
||||||
|
case DSHOT_CMD_SAVE_SETTINGS:
|
||||||
|
case DSHOT_CMD_SPIN_DIRECTION_NORMAL:
|
||||||
|
case DSHOT_CMD_SPIN_DIRECTION_REVERSED:
|
||||||
repeats = 10;
|
repeats = 10;
|
||||||
} else {
|
break;
|
||||||
|
default:
|
||||||
repeats = 1;
|
repeats = 1;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (; repeats; repeats--) {
|
for (; repeats; repeats--) {
|
||||||
motor->requestTelemetry = true;
|
motor->requestTelemetry = true;
|
||||||
pwmWritePtr(index, command);
|
pwmWritePtr(index, command);
|
||||||
|
|
|
@ -36,14 +36,14 @@ typedef enum {
|
||||||
DSHOT_CMD_BEEP4,
|
DSHOT_CMD_BEEP4,
|
||||||
DSHOT_CMD_BEEP5,
|
DSHOT_CMD_BEEP5,
|
||||||
DSHOT_CMD_ESC_INFO,
|
DSHOT_CMD_ESC_INFO,
|
||||||
DSHOT_CMD_SPIN_ONE_WAY,
|
DSHOT_CMD_SPIN_DIRECTION_1,
|
||||||
DSHOT_CMD_SPIN_OTHER_WAY,
|
DSHOT_CMD_SPIN_DIRECTION_2,
|
||||||
DSHOT_CMD_3D_MODE_OFF,
|
DSHOT_CMD_3D_MODE_OFF,
|
||||||
DSHOT_CMD_3D_MODE_ON,
|
DSHOT_CMD_3D_MODE_ON,
|
||||||
DSHOT_CMD_SETTINGS_REQUEST,
|
DSHOT_CMD_SETTINGS_REQUEST,
|
||||||
DSHOT_CMD_SAVE_SETTINGS,
|
DSHOT_CMD_SAVE_SETTINGS,
|
||||||
DSHOT_CMD_ROTATE_NORMAL = 20, //Blheli_S only command
|
DSHOT_CMD_SPIN_DIRECTION_NORMAL = 20, //Blheli_S only command
|
||||||
DSHOT_CMD_ROTATE_REVERSE = 21, //Blheli_S only command
|
DSHOT_CMD_SPIN_DIRECTION_REVERSED = 21, //Blheli_S only command
|
||||||
DSHOT_CMD_MAX = 47
|
DSHOT_CMD_MAX = 47
|
||||||
} dshotCommands_e;
|
} dshotCommands_e;
|
||||||
|
|
||||||
|
|
|
@ -207,16 +207,17 @@ void mwArm(void)
|
||||||
}
|
}
|
||||||
if (!ARMING_FLAG(PREVENT_ARMING)) {
|
if (!ARMING_FLAG(PREVENT_ARMING)) {
|
||||||
#ifdef USE_DSHOT
|
#ifdef USE_DSHOT
|
||||||
|
//TODO: Use BOXDSHOTREVERSE here
|
||||||
if (!feature(FEATURE_3D) && !IS_RC_MODE_ACTIVE(BOX3DDISABLESWITCH)) {
|
if (!feature(FEATURE_3D) && !IS_RC_MODE_ACTIVE(BOX3DDISABLESWITCH)) {
|
||||||
reverseMotors = false;
|
reverseMotors = false;
|
||||||
for (unsigned index = 0; index < getMotorCount(); index++) {
|
for (unsigned index = 0; index < getMotorCount(); index++) {
|
||||||
pwmWriteDshotCommand(index, DSHOT_CMD_ROTATE_NORMAL);
|
pwmWriteDshotCommand(index, DSHOT_CMD_SPIN_DIRECTION_NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!feature(FEATURE_3D) && IS_RC_MODE_ACTIVE(BOX3DDISABLESWITCH)) {
|
if (!feature(FEATURE_3D) && IS_RC_MODE_ACTIVE(BOX3DDISABLESWITCH)) {
|
||||||
reverseMotors = true;
|
reverseMotors = true;
|
||||||
for (unsigned index = 0; index < getMotorCount(); index++) {
|
for (unsigned index = 0; index < getMotorCount(); index++) {
|
||||||
pwmWriteDshotCommand(index, DSHOT_CMD_ROTATE_REVERSE);
|
pwmWriteDshotCommand(index, DSHOT_CMD_SPIN_DIRECTION_REVERSED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -370,6 +370,7 @@ void initActiveBoxIds(void)
|
||||||
|
|
||||||
BME(BOXFPVANGLEMIX);
|
BME(BOXFPVANGLEMIX);
|
||||||
|
|
||||||
|
//TODO: Split this into BOX3DDISABLESWITCH and BOXDSHOTREVERSE
|
||||||
BME(BOX3DDISABLESWITCH);
|
BME(BOX3DDISABLESWITCH);
|
||||||
|
|
||||||
if (feature(FEATURE_SERVO_TILT)) {
|
if (feature(FEATURE_SERVO_TILT)) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue