From 49c7ae4a26f8dd7d09872b6b5e4c107ef33b4560 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 3 Nov 2013 15:14:44 +0200 Subject: [PATCH] Drop the pretense of C89, put declarations where they make sense A lot of places already had mixed code and declarations, since that's what I'm used to in C++. Might as well use them everywhere and tell the compiler to use C99 mode. --- arducontrol/interface.c | 10 +++------- arducontrol/monitor.c | 6 ++---- arducontrol/motorola.c | 20 ++++++-------------- arducontrol/s88.c | 3 +-- common/build.mk | 2 +- common/lcd.c | 3 +-- s88w/s88w-r.c | 19 ++++++------------- s88w/s88w-t.c | 9 +++------ 8 files changed, 23 insertions(+), 49 deletions(-) diff --git a/arducontrol/interface.c b/arducontrol/interface.c index 2c55e2a..014e8e9 100644 --- a/arducontrol/interface.c +++ b/arducontrol/interface.c @@ -22,11 +22,10 @@ void interface_init(void) void interface_check(void) { - uint8_t count; if(serial_read_overrun()) interface_send1(RECEIVE_OVERRUN); - count = serial_read_available(); + uint8_t count = serial_read_available(); if(count>0) { PORTB |= 0x01; @@ -47,10 +46,9 @@ void interface_check(void) if(cmd_read_poscmd_length) count = cmd_length-cmd_read_pos; - for(i=0; i=cmd_length) @@ -85,10 +83,8 @@ static uint8_t dispatch_command(const uint8_t *cmd, uint8_t length) void interface_send(const uint8_t *cmd, uint8_t length) { - uint8_t i; - serial_write(~length); - for(i=0; i>8; reply[2] = value; @@ -101,12 +100,11 @@ uint8_t monitor_command(const uint8_t *cmd_buf, uint8_t cmd_length) } else if(cmd_buf[0]==READ_INPUT_VOLTAGE) { - uint8_t reply[3]; - if(cmd_length!=1) return LENGTH_ERROR; uint16_t value = input_voltage_millivolts(); + uint8_t reply[3]; reply[0] = INPUT_VOLTAGE; reply[1] = value>>8; reply[2] = value; diff --git a/arducontrol/motorola.c b/arducontrol/motorola.c index ff686ca..883457e 100644 --- a/arducontrol/motorola.c +++ b/arducontrol/motorola.c @@ -14,14 +14,12 @@ static uint8_t motorola_speed_to_value(uint8_t speed) static OutputPacket *motorola_common_packet(uint8_t addr, uint8_t aux, uint8_t value) { - uint8_t i; - OutputPacket *packet = output_create_packet(); packet->bit_duration = 2; packet->length = 18*8; - for(i=0; i<4; ++i) + for(uint8_t i=0; i<4; ++i) { uint8_t d = addr%3; addr /= 3; @@ -33,7 +31,7 @@ static OutputPacket *motorola_common_packet(uint8_t addr, uint8_t aux, uint8_t v packet->data[8] = (aux ? 0x7F : 0x01); packet->data[9] = packet->data[8]; - for(i=0; i<4; ++i) + for(uint8_t i=0; i<4; ++i) { packet->data[10+i*2] = ((value&1) ? 0x7F : 0x01); value >>= 1; @@ -49,11 +47,9 @@ static OutputPacket *motorola_common_packet(uint8_t addr, uint8_t aux, uint8_t v static OutputPacket *motorola_old_packet(uint8_t addr, uint8_t aux, uint8_t value) { - uint8_t i; - OutputPacket *packet = motorola_common_packet(addr, aux, value); - for(i=0; i<4; ++i) + for(uint8_t i=0; i<4; ++i) packet->data[11+i*2] = packet->data[10+i*2]; return packet; @@ -85,12 +81,8 @@ void motorola_locomotive_speed_direction_packet(uint8_t addr, uint8_t aux, uint8 void motorola_locomotive_speed_function_packet(uint8_t addr, uint8_t aux, uint8_t speed, uint8_t func, uint8_t state) { - uint8_t i; - uint8_t value; - OutputPacket *packet; - - value = motorola_speed_to_value(speed); - packet = motorola_common_packet(addr, aux, value); + uint8_t value = motorola_speed_to_value(speed); + OutputPacket *packet = motorola_common_packet(addr, aux, value); /* 001 -> 011 @@ -106,7 +98,7 @@ void motorola_locomotive_speed_function_packet(uint8_t addr, uint8_t aux, uint8_ if(func==value) func = ((value&8) ? 2 : 5) | (func&8); - for(i=0; i<4; ++i) + for(uint8_t i=0; i<4; ++i) { packet->data[11+i*2] = ((func&1) ? 0x7F : 0x01); func >>= 1; diff --git a/arducontrol/s88.c b/arducontrol/s88.c index cfe5367..142455a 100644 --- a/arducontrol/s88.c +++ b/arducontrol/s88.c @@ -32,11 +32,10 @@ void s88_check(void) if(count>=4 || (count>0 && !s88_read_count)) { uint8_t reply[10]; - uint8_t i; reply[0] = S88_DATA; reply[1] = s88_out_index; - for(i=0; i=4) { - uint16_t offset; - uint8_t nibbles; - uint8_t i; - - offset = (decode_hex(rx_buf[0])<<8) | (decode_hex(rx_buf[1])<<4) | decode_hex(rx_buf[2]); - nibbles = (offset&3); + uint8_t offset = (decode_hex(rx_buf[0])<<8) | (decode_hex(rx_buf[1])<<4) | decode_hex(rx_buf[2]); + uint8_t nibbles = (offset&3); offset >>= 2; if(rx_fill>3+nibbles) { - for(i=0; i<=nibbles; ++i) + for(uint8_t i=0; i<=nibbles; ++i) { uint16_t j = offset+nibbles-i; uint8_t shift = 4*(j&1); @@ -151,7 +144,7 @@ void check_input() if(lcd_enabled) { lcd_gotoxy(19-offset-nibbles, 0); - for(i=0; i<=nibbles; ++i) + for(uint8_t i=0; i<=nibbles; ++i) lcd_write(rx_buf[3+i]); } } diff --git a/s88w/s88w-t.c b/s88w/s88w-t.c index 692eac5..a1ff6aa 100644 --- a/s88w/s88w-t.c +++ b/s88w/s88w-t.c @@ -70,14 +70,13 @@ int main() while(1) { - uint8_t i, j; uint16_t input = 0; uint16_t valid = 0xFFF; - for(i=0; i<100; ++i) + for(uint8_t i=0; i<100; ++i) { uint16_t pins = 0; - for(j=0; j<100; ++j) + for(uint8_t j=0; j<100; ++j) pins |= ~((PIND>>2) | ((PINB&0x3F)<<6)); if(i==0) @@ -135,13 +134,11 @@ SERIAL_SET_CALLBACK(receive) void send_state(void) { - uint8_t i; - serial_write(':'); serial_write(hexdigit(offset>>8)); serial_write(hexdigit(offset>>4)); serial_write(hexdigit(offset|(nibbles-1))); - for(i=nibbles; i--;) + for(uint8_t i=nibbles; i--;) serial_write(hexdigit(state>>(i*4))); serial_write('.'); -- 2.43.0