Make code -Wall -Wextra -pedantic -Wmissing-prototypes -Wold-style-definition

This commit is contained in:
Pim van Pelt
2018-04-22 14:15:35 +02:00
parent 64fe69d3e3
commit 38c3cdf27e
8 changed files with 41 additions and 30 deletions

View File

@ -1,6 +1,7 @@
TARGET = mgos_i2c
CC = gcc
CFLAGS = -g -O -Wall
# CFLAGS = -g -O -Wall -Wextra -std=c89 -pedantic -Wmissing-prototypes -Wstrict-prototypes -Wold-style-definition
CFLAGS = -g -O -Wall -Wextra -pedantic -Wmissing-prototypes -Wold-style-definition
LINKER = gcc
LFLAGS = -O -Wall -I. -lm

View File

@ -46,7 +46,7 @@ int log_print_prefix(enum cs_log_level l, const char *func, const char *file);
printf("\r\n"); \
} while (0)
double mg_time();
double mg_time(void);
void mgos_usleep(uint32_t usecs);
#endif // __MGOS_MOCK_H

View File

@ -60,7 +60,7 @@ bool mgos_barometer_mpl3115_read(struct mgos_barometer *dev) {
return false;
}
uint8_t val = 0;
int val = 0;
uint8_t retries=100;
if ((val = mgos_i2c_read_reg_b(dev->i2c, dev->i2caddr, MPL3115_REG_STATUS)) < 0)
return false;

View File

@ -30,7 +30,7 @@
#define I2CBUSNR 5
void i2c_scanner(struct mgos_i2c *i2c) {
static void i2c_scanner(struct mgos_i2c *i2c) {
int i;
if (!i2c) {
@ -47,6 +47,7 @@ void i2c_scanner(struct mgos_i2c *i2c) {
}
}
bool i2c_dumpregs(struct mgos_i2c *i2c, uint8_t i2caddr);
bool i2c_dumpregs(struct mgos_i2c *i2c, uint8_t i2caddr) {
uint16_t reg;
int value;
@ -66,7 +67,7 @@ bool i2c_dumpregs(struct mgos_i2c *i2c, uint8_t i2caddr) {
return true;
}
bool do_ccs811(struct mgos_ccs811 *sensor) {
static bool do_ccs811(struct mgos_ccs811 *sensor) {
float eco2, tvoc;
if (!sensor) {
@ -80,7 +81,7 @@ bool do_ccs811(struct mgos_ccs811 *sensor) {
return true;
}
bool do_sht31(struct mgos_sht31 *sensor) {
static bool do_sht31(struct mgos_sht31 *sensor) {
float temp, humid;
if (!sensor) {
@ -94,7 +95,7 @@ bool do_sht31(struct mgos_sht31 *sensor) {
return true;
}
bool do_si7021(struct mgos_si7021 *sensor) {
static bool do_si7021(struct mgos_si7021 *sensor) {
float temp, humid;
if (!sensor) {
@ -108,7 +109,7 @@ bool do_si7021(struct mgos_si7021 *sensor) {
return true;
}
bool do_htu21df(struct mgos_htu21df *sensor) {
static bool do_htu21df(struct mgos_htu21df *sensor) {
float temp, humid;
if (!sensor) {
@ -122,7 +123,7 @@ bool do_htu21df(struct mgos_htu21df *sensor) {
return true;
}
bool do_mcp9808(struct mgos_mcp9808 *sensor) {
static bool do_mcp9808(struct mgos_mcp9808 *sensor) {
float temp;
if (!sensor) {
@ -135,7 +136,7 @@ bool do_mcp9808(struct mgos_mcp9808 *sensor) {
return true;
}
bool do_mpu9250(struct mgos_mpu9250 *sensor) {
static bool do_mpu9250(struct mgos_mpu9250 *sensor) {
float ax, ay, az;
float gx, gy, gz;
float mx, my, mz;
@ -156,7 +157,7 @@ bool do_mpu9250(struct mgos_mpu9250 *sensor) {
return true;
}
bool do_baro(struct mgos_barometer *sensor) {
static bool do_baro(struct mgos_barometer *sensor) {
float pressure, temperature;
if (!sensor)
@ -173,15 +174,15 @@ bool do_baro(struct mgos_barometer *sensor) {
return true;
}
int main() {
struct mgos_i2c * i2c;
struct mgos_si7021 * si7021;
struct mgos_sht31 * sht31;
struct mgos_htu21df *htu21df;
struct mgos_mcp9808 *mcp9808;
struct mgos_ccs811 * ccs811;
struct mgos_mpu9250 *mpu9250;
struct mgos_barometer *baro1, *baro2;
int main(int argc, char **argv, char **environ) {
struct mgos_i2c * i2c = NULL;
struct mgos_si7021 * si7021 = NULL;
struct mgos_sht31 * sht31 = NULL;
struct mgos_htu21df *htu21df = NULL;
struct mgos_mcp9808 *mcp9808 = NULL;
struct mgos_ccs811 * ccs811 = NULL;
struct mgos_mpu9250 *mpu9250 = NULL;
struct mgos_barometer *baro1 = NULL, *baro2 = NULL;
if (!mgos_i2c_open(I2CBUSNR)) {
LOG(LL_ERROR, ("Cannot open I2C bus %u", I2CBUSNR));
@ -230,14 +231,12 @@ int main() {
}
for (;;) {
/*
* do_sht31(sht31);
* do_si7021(si7021);
* do_htu21df(htu21df);
* do_mcp9808(mcp9808);
* do_ccs811(ccs811);
* do_mpu9250(mpu9250);
*/
do_sht31(sht31);
do_si7021(si7021);
do_htu21df(htu21df);
do_mcp9808(mcp9808);
do_ccs811(ccs811);
do_mpu9250(mpu9250);
do_baro(baro1);
do_baro(baro2);
sleep(1);
@ -253,4 +252,7 @@ int main() {
mgos_barometer_destroy(&baro2);
return 0;
(void)argc;
(void)argv;
(void)environ;
}

View File

@ -75,6 +75,7 @@ bool mgos_i2c_read(struct mgos_i2c *i2c, uint16_t addr, void *data, size_t len,
return false;
}
return true;
(void)stop;
}
@ -96,22 +97,26 @@ bool mgos_i2c_write(struct mgos_i2c *i2c, uint16_t addr, const void *data, size_
return false;
}
return true;
(void)stop;
}
void mgos_i2c_stop(struct mgos_i2c *i2c) {
return;
(void)i2c;
}
int mgos_i2c_get_freq(struct mgos_i2c *i2c) {
return MGOS_I2C_FREQ_100KHZ;
(void)i2c;
}
bool mgos_i2c_set_freq(struct mgos_i2c *i2c, int freq) {
if (freq==MGOS_I2C_FREQ_100KHZ) return true;
return false;
(void)i2c;
}
@ -224,6 +229,7 @@ bool mgos_i2c_write_reg_n(struct mgos_i2c *i2c, uint16_t addr, uint8_t reg, size
void mgos_i2c_close(struct mgos_i2c *i2c) {
return;
(void)i2c;
}

View File

@ -21,7 +21,7 @@
// Private functions end
// Public functions follow
struct mgos_imu *mgos_imu_create(struct mgos_i2c *i2c, uint8_t i2caddr) {
struct mgos_imu *mgos_imu_create_i2c(struct mgos_i2c *i2c) {
struct mgos_imu *sensor;
if (!i2c) {

View File

@ -49,7 +49,7 @@ int log_print_prefix(enum cs_log_level l, const char *func, const char *file) {
}
double mg_time() {
double mg_time(void) {
struct timespec ts;
double ret;

View File

@ -301,6 +301,7 @@ bool mgos_mpu9250_set_magnetometer_speed(struct mgos_mpu9250 *imu, enum mgos_mpu
return false;
}
return false;
(void) speed;
}
bool mgos_mpu9250_get_magnetometer_speed(struct mgos_mpu9250 *imu, enum mgos_mpu9250_magnetometer_speed *speed) {
@ -308,6 +309,7 @@ bool mgos_mpu9250_get_magnetometer_speed(struct mgos_mpu9250 *imu, enum mgos_mpu
return false;
}
return false;
(void) speed;
}
bool mgos_mpu9250_get_magnetometer(struct mgos_mpu9250 *imu, float *x, float *y, float *z) {