Permalink
Browse files

Remove serial_cli.c's dependency on mw.h/board.h.

Rename yawdeadband to yaw_deadband to match other variables/cli
commands.

Fix a couple of usages of MAX_MOTORS where MAX_SUPPORTED_MOTORS should
be used instead.
  • Loading branch information...
hydra committed Apr 23, 2014
1 parent bcc55ab commit a5f0999c267c4d255ec11648a072102e33b80bca
Showing with 250 additions and 220 deletions.
  1. +2 −0 src/battery.h
  2. +177 −0 src/common/typeconversion.c
  3. +6 −0 src/common/typeconversion.h
  4. +1 −1 src/config.c
  5. +1 −1 src/config_profile.h
  6. +6 −6 src/flight_mixer.c
  7. +6 −0 src/flight_mixer.h
  8. +3 −3 src/mw.c
  9. +1 −2 src/mw.h
  10. +2 −0 src/rx_common.h
  11. +43 −205 src/serial_cli.c
  12. +2 −2 src/serial_msp.c
View
@@ -6,6 +6,8 @@ typedef struct batteryConfig_s {
uint8_t vbatmincellvoltage; // minimum voltage per cell, this triggers battery out alarms, in 0.1V units, default is 33 (3.3V)
} batteryConfig_t;
extern uint8_t vbat;
extern uint8_t batteryCellCount;
extern uint16_t batteryWarningVoltage;
uint16_t batteryAdcToVoltage(uint16_t src);
View
@@ -1,4 +1,8 @@
#include <stdint.h>
#include <string.h>
#include <math.h>
#include "build_config.h"
#include "maths.h"
#ifdef REQUIRE_PRINTF_LONG_SUPPORT
@@ -85,3 +89,176 @@ char a2i(char ch, char **src, int base, int *nump)
*nump = num;
return ch;
}
#ifndef HAVE_ITOA_FUNCTION
/*
** The following two functions together make up an itoa()
** implementation. Function i2a() is a 'private' function
** called by the public itoa() function.
**
** itoa() takes three arguments:
** 1) the integer to be converted,
** 2) a pointer to a character conversion buffer,
** 3) the radix for the conversion
** which can range between 2 and 36 inclusive
** range errors on the radix default it to base10
** Code from http://groups.google.com/group/comp.lang.c/msg/66552ef8b04fe1ab?pli=1
*/
static char *_i2a(unsigned i, char *a, unsigned r)
{
if (i / r > 0)
a = _i2a(i / r, a, r);
*a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i % r];
return a + 1;
}
char *itoa(int i, char *a, int r)
{
if ((r < 2) || (r > 36))
r = 10;
if (i < 0) {
*a = '-';
*_i2a(-(unsigned)i, a + 1, r) = 0;
} else
*_i2a(i, a, r) = 0;
return a;
}
#endif
char *ftoa(float x, char *floatString)
{
int32_t value;
char intString1[12];
char intString2[12] = { 0, };
char *decimalPoint = ".";
uint8_t dpLocation;
if (x > 0) // Rounding for x.xxx display format
x += 0.0005f;
else
x -= 0.0005f;
value = (int32_t) (x * 1000.0f); // Convert float * 1000 to an integer
itoa(abs(value), intString1, 10); // Create string from abs of integer value
if (value >= 0)
intString2[0] = ' '; // Positive number, add a pad space
else
intString2[0] = '-'; // Negative number, add a negative sign
if (strlen(intString1) == 1) {
intString2[1] = '0';
intString2[2] = '0';
intString2[3] = '0';
strcat(intString2, intString1);
} else if (strlen(intString1) == 2) {
intString2[1] = '0';
intString2[2] = '0';
strcat(intString2, intString1);
} else if (strlen(intString1) == 3) {
intString2[1] = '0';
strcat(intString2, intString1);
} else {
strcat(intString2, intString1);
}
dpLocation = strlen(intString2) - 3;
strncpy(floatString, intString2, dpLocation);
floatString[dpLocation] = '\0';
strcat(floatString, decimalPoint);
strcat(floatString, intString2 + dpLocation);
return floatString;
}
// Simple and fast atof (ascii to float) function.
//
// - Executes about 5x faster than standard MSCRT library atof().
// - An attractive alternative if the number of calls is in the millions.
// - Assumes input is a proper integer, fraction, or scientific format.
// - Matches library atof() to 15 digits (except at extreme exponents).
// - Follows atof() precedent of essentially no error checking.
//
// 09-May-2009 Tom Van Baak (tvb) www.LeapSecond.com
#define white_space(c) ((c) == ' ' || (c) == '\t')
#define valid_digit(c) ((c) >= '0' && (c) <= '9')
float fastA2F(const char *p)
{
int frac = 0;
float sign, value, scale;
// Skip leading white space, if any.
while (white_space(*p) ) {
p += 1;
}
// Get sign, if any.
sign = 1.0f;
if (*p == '-') {
sign = -1.0f;
p += 1;
} else if (*p == '+') {
p += 1;
}
// Get digits before decimal point or exponent, if any.
value = 0.0f;
while (valid_digit(*p)) {
value = value * 10.0f + (*p - '0');
p += 1;
}
// Get digits after decimal point, if any.
if (*p == '.') {
float pow10 = 10.0f;
p += 1;
while (valid_digit(*p)) {
value += (*p - '0') / pow10;
pow10 *= 10.0f;
p += 1;
}
}
// Handle exponent, if any.
scale = 1.0f;
if ((*p == 'e') || (*p == 'E')) {
unsigned int expon;
p += 1;
// Get sign of exponent, if any.
frac = 0;
if (*p == '-') {
frac = 1;
p += 1;
} else if (*p == '+') {
p += 1;
}
// Get digits of exponent, if any.
expon = 0;
while (valid_digit(*p)) {
expon = expon * 10 + (*p - '0');
p += 1;
}
if (expon > 308)
expon = 308;
// Calculate scaling factor.
// while (expon >= 50) { scale *= 1E50f; expon -= 50; }
while (expon >= 8) { scale *= 1E8f; expon -= 8; }
while (expon > 0) { scale *= 10.0f; expon -= 1; }
}
// Return signed and scaled floating point result.
return sign * (frac ? (value / scale) : (value * scale));
}
@@ -5,3 +5,9 @@ void li2a(long num, char *bf);
void ui2a(unsigned int num, unsigned int base, int uc, char *bf);
void i2a(int num, char *bf);
char a2i(char ch, char **src, int base, int *nump);
char *ftoa(float x, char *floatString);
float fastA2F(const char *p);
#ifndef HAVE_ITOA_FUNCTION
char *itoa(int i, char *a, int r);
#endif
View
@@ -345,7 +345,7 @@ static void resetConf(void)
// Radio
parseRcChannels("AETR1234", &masterConfig.rxConfig);
currentProfile.deadband = 0;
currentProfile.yawdeadband = 0;
currentProfile.yaw_deadband = 0;
currentProfile.alt_hold_throttle_neutral = 40;
currentProfile.alt_hold_fast_change = 1;
currentProfile.throttle_correction_value = 0; // could 10 with althold or 40 for fpv
View
@@ -29,7 +29,7 @@ typedef struct profile_s {
// Radio/ESC-related configuration
uint8_t deadband; // introduce a deadband around the stick center for pitch and roll axis. Must be greater than zero.
uint8_t yawdeadband; // introduce a deadband around the stick center for yaw axis. Must be greater than zero.
uint8_t yaw_deadband; // introduce a deadband around the stick center for yaw axis. Must be greater than zero.
uint8_t alt_hold_throttle_neutral; // defines the neutral zone of throttle stick during altitude hold, default setting is +/-40
uint8_t alt_hold_fast_change; // when disabled, turn off the althold when throttle stick is out of deadband defined with alt_hold_throttle_neutral; when enabled, altitude changes slowly proportional to stick movement
uint16_t throttle_correction_angle; // the angle when the throttle correction is maximal. in 0.1 degres, ex 225 = 22.5 ,30.0, 450 = 45.0 deg
View
@@ -8,13 +8,13 @@
#include "flight_common.h"
static uint8_t numberMotor = 0;
int16_t motor[MAX_MOTORS];
int16_t motor_disarmed[MAX_MOTORS];
int16_t motor[MAX_SUPPORTED_MOTORS];
int16_t motor_disarmed[MAX_SUPPORTED_MOTORS];
int16_t servo[MAX_SERVOS] = { 1500, 1500, 1500, 1500, 1500, 1500, 1500, 1500 };
static int useServo;
static motorMixer_t currentMixer[MAX_MOTORS];
static motorMixer_t currentMixer[MAX_SUPPORTED_MOTORS];
static const motorMixer_t mixerTri[] = {
{ 1.0f, 0.0f, 1.333333f, 0.0f }, // REAR
@@ -198,7 +198,7 @@ void mixerInit(void)
if (masterConfig.mixerConfiguration == MULTITYPE_CUSTOM) {
// load custom mixer into currentMixer
for (i = 0; i < MAX_MOTORS; i++) {
for (i = 0; i < MAX_SUPPORTED_MOTORS; i++) {
// check if done
if (masterConfig.customMixer[i].throttle == 0.0f)
break;
@@ -239,7 +239,7 @@ void mixerResetMotors(void)
{
int i;
// set disarmed motor values
for (i = 0; i < MAX_MOTORS; i++)
for (i = 0; i < MAX_SUPPORTED_MOTORS; i++)
motor_disarmed[i] = feature(FEATURE_3D) ? masterConfig.neutral3d : masterConfig.mincommand;
}
@@ -250,7 +250,7 @@ void mixerLoadMix(int index)
// we're 1-based
index++;
// clear existing
for (i = 0; i < MAX_MOTORS; i++)
for (i = 0; i < MAX_SUPPORTED_MOTORS; i++)
masterConfig.customMixer[i].throttle = 0.0f;
// do we have anything here to begin with?
View
@@ -59,3 +59,9 @@ typedef struct servoParam_t {
bool isMixerUsingServos(void);
void mixerInit(void);
void writeAllMotors(int16_t mc);
void mixerLoadMix(int index);
void mixerResetMotors(void);
// from mixer.c
extern int16_t motor_disarmed[MAX_SUPPORTED_MOTORS];
View
@@ -84,9 +84,9 @@ void annexCode(void)
prop1 = 100 - (uint16_t)currentProfile.controlRateConfig.rollPitchRate * tmp / 500;
prop1 = (uint16_t)prop1 * prop2 / 100;
} else { // YAW
if (currentProfile.yawdeadband) {
if (tmp > currentProfile.yawdeadband) {
tmp -= currentProfile.yawdeadband;
if (currentProfile.yaw_deadband) {
if (tmp > currentProfile.yaw_deadband) {
tmp -= currentProfile.yaw_deadband;
} else {
tmp = 0;
}
View
@@ -51,10 +51,9 @@ extern int32_t BaroPID;
extern int32_t vario;
extern int16_t throttleAngleCorrection;
extern int16_t headFreeModeHold;
extern int16_t motor[MAX_MOTORS];
extern int16_t motor[MAX_SUPPORTED_MOTORS];
extern int16_t servo[MAX_SERVOS];
extern uint16_t rssi; // range: [0;1023]
extern uint8_t vbat;
extern int16_t telemTemperature1; // gyro sensor temperature
extern uint8_t toggleBeep;
View
@@ -18,6 +18,8 @@ typedef enum {
#define MAX_SUPPORTED_RC_PPM_AND_PWM_CHANNEL_COUNT 8
#define MAX_SUPPORTED_RC_CHANNEL_COUNT (18)
extern const char rcChannelLetters[];
extern int16_t rcData[MAX_SUPPORTED_RC_CHANNEL_COUNT]; // interval [1000;2000]
typedef struct rxConfig_s {
Oops, something went wrong.

0 comments on commit a5f0999

Please sign in to comment.