Skip to content

Commit

Permalink
Merge pull request #251 from fiendie/formatting
Browse files Browse the repository at this point in the history
Made formatting consistent with baseflight coding style guidelines.
  • Loading branch information
trollcop committed Feb 26, 2015
2 parents c7ed337 + f8b4c5e commit 5fffabb
Show file tree
Hide file tree
Showing 30 changed files with 820 additions and 803 deletions.
2 changes: 1 addition & 1 deletion src/board.h
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ typedef struct baro_t {
// #define SOFT_I2C_PB1011 // If SOFT_I2C is enabled above, need to define pinout as well (I2C1 = PB67, I2C2 = PB1011)
// #define SOFT_I2C_PB67

// AfroFlight32
// AfroFlight32
#include "drv_adc.h"
#include "drv_adxl345.h"
#include "drv_bma280.h"
Expand Down
16 changes: 8 additions & 8 deletions src/buzzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
*/
// fast beep:
static const uint8_t buzz_shortBeep[] = {
5,5, 0xFF
5, 5, 0xFF
};
// fast beep:
static const uint8_t buzz_BatteryBeep[] = {
10,5, 0xFF
10, 5, 0xFF
};
// medium beep
static const uint8_t buzz_mediumBeepFast[] = {
Expand All @@ -38,23 +38,23 @@ static const uint8_t buzz_longBeep[] = {
};
// SOS morse code:
static const uint8_t buzz_sos[] = {
10,10, 10,10, 10,40, 40,10, 40,10, 40,40, 10,10, 10,10, 10,70, 0xFF
10, 10, 10, 10, 10, 40, 40, 10, 40, 10, 40, 40, 10, 10, 10, 10, 10, 70, 0xFF
};
// Arming when GPS is fixed
static const uint8_t buzz_armed[] = {
5,5, 15,5, 5,5, 15,30, 0xFF
5, 5, 15, 5, 5, 5, 15, 30, 0xFF
};
// Ready beeps. When gps has fix and copter is ready to fly.
static const uint8_t buzz_readyBeep[] = {
4,5, 4,5, 8,5, 15,5, 8,5, 4,5, 4,5, 0xFF
4, 5, 4, 5, 8, 5, 15, 5, 8, 5, 4, 5, 4, 5, 0xFF
};
// 2 fast short beeps
static const uint8_t buzz_2shortBeeps[] = {
5,5, 5,5, 0xFF
5, 5, 5, 5, 0xFF
};
// 3 fast short beeps
static const uint8_t buzz_3shortBeeps[] = {
5,5, 5,5, 5,5, 0xFF
5, 5, 5, 5, 5, 5, 0xFF
};
// Array used for beeps when reporting GPS satellite count (up to 10 satellites)
static uint8_t buzz_countSats[22];
Expand All @@ -64,7 +64,7 @@ static uint8_t buzzerMode = BUZZER_STOPPED;
// Buzzer off = 0 Buzzer on = 1
static uint8_t buzzerIsOn = 0;
// Pointer to current sequence
static const uint8_t* buzzerPtr = NULL;
static const uint8_t *buzzerPtr = NULL;
// Place in current sequence
static uint16_t buzzerPos = 0;
// Time when buzzer routine must act next time
Expand Down
61 changes: 33 additions & 28 deletions src/cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,17 @@ static float _atof(const char *p);
static char *ftoa(float x, char *floatString);

// sync this with MultiType enum from mw.h
static const char * const mixerNames[] = {
static const char *const mixerNames[] = {
"TRI", "QUADP", "QUADX", "BI",
"GIMBAL", "Y6", "HEX6",
"FLYING_WING", "Y4", "HEX6X", "OCTOX8", "OCTOFLATP", "OCTOFLATX",
"AIRPLANE", "HELI_120_CCPM", "HELI_90_DEG", "VTAIL4",
"AIRPLANE", "HELI_120_CCPM", "HELI_90_DEG", "VTAIL4",
"HEX6H", "PPM_TO_SERVO", "DUALCOPTER", "SINGLECOPTER",
"ATAIL4", "CUSTOM", "CUSTOMPLANE", NULL
};

// sync this with AvailableFeatures enum from board.h
static const char * const featureNames[] = {
static const char *const featureNames[] = {
"PPM", "VBAT", "INFLIGHT_ACC_CAL", "SERIALRX", "MOTOR_STOP",
"SERVO_TILT", "SOFTSERIAL", "LED_RING", "GPS",
"FAILSAFE", "SONAR", "TELEMETRY", "POWERMETER", "VARIO", "3D",
Expand All @@ -68,17 +68,17 @@ static const char * const featureNames[] = {
};

// sync this with AvailableSensors enum from board.h
static const char * const sensorNames[] = {
static const char *const sensorNames[] = {
"GYRO", "ACC", "BARO", "MAG", "SONAR", "GPS", "GPS+MAG", NULL
};

// sync this with AccelSensors enum from board.h
static const char * const accNames[] = {
static const char *const accNames[] = {
"", "ADXL345", "MPU6050", "MMA845x", "BMA280", "MPU6500", "None", NULL
};

// sync this with HardwareRevision in board.h
static const char * const hwNames[] = {
static const char *const hwNames[] = {
"", "Naze 32", "Naze32 rev.5", "Naze32 SP"
};

Expand Down Expand Up @@ -404,8 +404,14 @@ static float _atof(const char *p)

// 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; }
while (expon >= 8) {
scale *= 1E8f;
expon -= 8;
}
while (expon > 0) {
scale *= 10.0f;
expon -= 1;
}
}

// Return signed and scaled floating point result.
Expand Down Expand Up @@ -645,7 +651,7 @@ static void cliServoMix(char *cmdline)
printf("change the direction a servo reacts to a input channel: \r\nservo input -1|1\r\n");
printf("s");
for (channel = 0; channel < INPUT_ITEMS; channel++)
printf("\ti%d",channel + 1);
printf("\ti%d", channel + 1);
printf("\r\n");

for (servoIndex = 0; servoIndex < MAX_SERVOS; servoIndex++) {
Expand All @@ -662,12 +668,12 @@ static void cliServoMix(char *cmdline)
args[check++] = atoi(ptr);
ptr = strtok(NULL, " ");
}

if (ptr != NULL || check != ARGS_COUNT) {
printf("Wrong number of arguments, needs servo input direction\r\n");
return;
}

if (args[SERVO] >= 1 && args[SERVO] <= MAX_SERVOS && args[INPUT] >= 1 && args[INPUT] <= INPUT_ITEMS && (args[DIRECTION] == -1 || args[DIRECTION] == 1)) {
args[SERVO] -= 1;
args[INPUT] -= 1;
Expand All @@ -679,20 +685,19 @@ static void cliServoMix(char *cmdline)
printf("ERR: Wrong range for arguments\r\n");

cliServoMix("direction");
}
else {
} else {
enum {RULE = 0, TARGET, INPUT, RATE, SPEED, MIN, MAX, BOX, ARGS_COUNT};
ptr = strtok(cmdline, " ");
while (ptr != NULL && check < ARGS_COUNT) {
args[check++] = atoi(ptr);
ptr = strtok(NULL, " ");
}

if (ptr != NULL || check != ARGS_COUNT) {
printf("ERR: Wrong number of arguments, needs rule target_channel input_channel rate speed min max box\r\n");
return;
}

i = args[RULE] - 1;
if (i >= 0 && i < MAX_SERVO_RULES &&
args[TARGET] > 0 && args[TARGET] <= MAX_SERVOS &&
Expand All @@ -702,14 +707,14 @@ static void cliServoMix(char *cmdline)
args[MIN] >= 0 && args[MIN] <= 100 &&
args[MAX] >= 0 && args[MAX] <= 100 && args[MIN] < args[MAX] &&
args[BOX] >= 0 && args[BOX] <= MAX_SERVO_BOXES) {
mcfg.customServoMixer[i].targetChannel = args[TARGET] - 1;
mcfg.customServoMixer[i].fromChannel = args[INPUT] - 1;
mcfg.customServoMixer[i].rate = args[RATE];
mcfg.customServoMixer[i].speed = args[SPEED];
mcfg.customServoMixer[i].min = args[MIN];
mcfg.customServoMixer[i].max = args[MAX];
mcfg.customServoMixer[i].box = args[BOX];
cliServoMix("");
mcfg.customServoMixer[i].targetChannel = args[TARGET] - 1;
mcfg.customServoMixer[i].fromChannel = args[INPUT] - 1;
mcfg.customServoMixer[i].rate = args[RATE];
mcfg.customServoMixer[i].speed = args[SPEED];
mcfg.customServoMixer[i].min = args[MIN];
mcfg.customServoMixer[i].max = args[MAX];
mcfg.customServoMixer[i].box = args[BOX];
cliServoMix("");
} else
printf("ERR: Wrong range for arguments\r\n");
}
Expand Down Expand Up @@ -768,7 +773,7 @@ static void cliDump(char *cmdline)
}
printf("cmix %d 0 0 0 0\r\n", i + 1);
}

// print custom servo mixer if exists
if (mcfg.customServoMixer[0].rate != 0) {
for (i = 0; i < MAX_SERVO_RULES; i++) {
Expand All @@ -785,13 +790,13 @@ static void cliDump(char *cmdline)
}
printf("smix %d 0 0 0 0\r\n", i + 1);
}

// print servo directions
for (i = 0; i < 8; i++)
for (channel = 0; channel < INPUT_ITEMS; channel++)
if (cfg.servoConf[i].direction & (1 << channel))
printf("smix direction %d %d -1\r\n",i + 1 ,channel + 1);
printf("smix direction %d %d -1\r\n", i + 1 , channel + 1);

// print enabled features
mask = featureMask();
for (i = 0; ; i++) { // disable all feature first
Expand Down Expand Up @@ -1198,7 +1203,7 @@ static void cliStatus(char *cmdline)
uint32_t mask;

printf("System Uptime: %d seconds, Voltage: %d * 0.1V (%dS battery)\r\n",
millis() / 1000, vbat, batteryCellCount);
millis() / 1000, vbat, batteryCellCount);
mask = sensorsMask();

printf("Hardware: %s @ %dMHz, detected sensors: ", hwNames[hw_revision], (SystemCoreClock / 1000000));
Expand Down
6 changes: 3 additions & 3 deletions src/drv_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Driver for STM32F103CB onboard ADC
// VBAT is connected to PA4 (ADC1_IN4) with 10k:1k divider
// rev.5 hardware has PA5 (ADC1_IN5) on breakout pad on bottom of board
// Additional channel can be stolen from RC_CH2 (PA1, ADC1_IN1) or
// Additional channel can be stolen from RC_CH2 (PA1, ADC1_IN1) or
// RC_CH8 (PB1, ADC1_IN9) by using set power_adc_channel=1|9

typedef struct adc_config_t {
Expand Down Expand Up @@ -77,9 +77,9 @@ void adcInit(drv_adc_config_t *init)

// Calibrate ADC
ADC_ResetCalibration(ADC1);
while(ADC_GetResetCalibrationStatus(ADC1));
while (ADC_GetResetCalibrationStatus(ADC1));
ADC_StartCalibration(ADC1);
while(ADC_GetCalibrationStatus(ADC1));
while (ADC_GetCalibrationStatus(ADC1));

// Fire off ADC
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
Expand Down
20 changes: 10 additions & 10 deletions src/drv_ak8975.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* This file is part of baseflight
* Licensed under GPL V3 or modified DCL - see https://github.com/multiwii/baseflight/blob/master/README.md
*/

#include "board.h"

// This sensor is available on MPU-9150. The accel/gyro in that chip use the same driver as MPU-6050.
Expand All @@ -12,38 +12,38 @@
#define AK8975_MAG_ID_ADDRESS 0x00
#define AK8975_MAG_DATA_ADDRESS 0x03
#define AK8975_MAG_CONTROL_ADDRESS 0x0A

static sensor_align_e magAlign = CW180_DEG;
bool ak8975detect(sensor_t * mag)

bool ak8975detect(sensor_t *mag)
{
bool ack = false;
uint8_t sig = 0;

// device ID is in register 0 and is equal to 'H'
ack = i2cRead(AK8975_MAG_I2C_ADDRESS, AK8975_MAG_ID_ADDRESS, 1, &sig);
if (!ack || sig != 'H')
return false;

mag->init = ak8975Init;
mag->read = ak8975Read;

return true;
}

void ak8975Init(sensor_align_e align)
{
if (align > 0)
magAlign = align;

i2cWrite(AK8975_MAG_I2C_ADDRESS, AK8975_MAG_CONTROL_ADDRESS, 0x01); // start reading
}

void ak8975Read(int16_t *magData)
{
uint8_t buf[6];
int16_t mag[3];

i2cRead(AK8975_MAG_I2C_ADDRESS, AK8975_MAG_DATA_ADDRESS, 6, buf);
// align sensors to match MPU6050:
// x -> y
Expand All @@ -52,8 +52,8 @@ void ak8975Read(int16_t *magData)
mag[X] = -(int16_t)(buf[3] << 8 | buf[2]) * 4;
mag[Y] = -(int16_t)(buf[1] << 8 | buf[0]) * 4;
mag[Z] = -(int16_t)(buf[5] << 8 | buf[4]) * 4;

alignSensors(mag, magData, magAlign);

i2cWrite(AK8975_MAG_I2C_ADDRESS, AK8975_MAG_CONTROL_ADDRESS, 0x01); // start reading again
}
4 changes: 2 additions & 2 deletions src/drv_hmc5883l.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ bool hmc5883lDetect(sensor_t *mag)

mag->init = hmc5883lInit;
mag->read = hmc5883lRead;

return true;
}

Expand All @@ -106,7 +106,7 @@ void hmc5883lInit(sensor_align_e align)

if (align > 0)
magAlign = align;

if (hw_revision == NAZE32) {
// PB12 - MAG_DRDY output on rev4 hardware
gpio.pin = Pin_12;
Expand Down
Loading

0 comments on commit 5fffabb

Please sign in to comment.