]> git.tdb.fi Git - model-railway-devices.git/blobdiff - arducontrol/motorola.c
Drop the pretense of C89, put declarations where they make sense
[model-railway-devices.git] / arducontrol / motorola.c
index ff686caf8ac072a00c6cafbc407eacdd77c33cd8..883457ecf52b4bd44b5badccf0ae3f7ec14be826 100644 (file)
@@ -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;