drivers/ao_lco: Fix box types to be uint16_t. Also clean other -Wconversion messages
authorKeith Packard <keithp@keithp.com>
Fri, 28 Jan 2022 17:33:17 +0000 (09:33 -0800)
committerKeith Packard <keithp@keithp.com>
Thu, 17 Feb 2022 01:26:49 +0000 (17:26 -0800)
Old LCO code uses 0x1000 as magic value for "DRAG" box, so we need 16
bits. Switch all box variables to 16 bits, use int32_t when switching
box numbers to deal with negative values and still hold the whole
possible range (even though 16 bits "should" be plenty).

Signed-off-by: Keith Packard <keithp@keithp.com>
src/drivers/ao_lco.c
src/drivers/ao_lco.h
src/drivers/ao_lco_bits.c
src/drivers/ao_lco_cmd.c
src/drivers/ao_lco_func.c
src/drivers/ao_lco_two.c

index 2cb885cfc336996f7b5a3e56e4686ed48ed26c8a..bc8f7b48f7788949ba6ea1cdcb4314b19dddb668 100644 (file)
@@ -46,7 +46,7 @@ void
 ao_lco_show_pad(uint8_t pad)
 {
        ao_mutex_get(&ao_lco_display_mutex);
-       ao_seven_segment_set(AO_LCO_PAD_DIGIT, pad | (ao_lco_drag_race << 4));
+       ao_seven_segment_set(AO_LCO_PAD_DIGIT, (uint8_t) (pad | (ao_lco_drag_race << 4)));
        ao_mutex_put(&ao_lco_display_mutex);
 }
 
@@ -72,11 +72,11 @@ ao_lco_show_box(uint16_t box)
 {
        ao_mutex_get(&ao_lco_display_mutex);
        if (box == AO_LCO_BOX_DRAG) {
-               ao_seven_segment_direct(AO_LCO_BOX_DIGIT_10, SEVEN_SEGMENT_d | (ao_lco_drag_race << 7));
-               ao_seven_segment_direct(AO_LCO_BOX_DIGIT_1, SEVEN_SEGMENT_r | (ao_lco_drag_race << 7));
+               ao_seven_segment_direct(AO_LCO_BOX_DIGIT_10, (uint8_t) (SEVEN_SEGMENT_d | (ao_lco_drag_race << 7)));
+               ao_seven_segment_direct(AO_LCO_BOX_DIGIT_1, (uint8_t) (SEVEN_SEGMENT_r | (ao_lco_drag_race << 7)));
        } else {
-               ao_seven_segment_set(AO_LCO_BOX_DIGIT_1, box % 10 | (ao_lco_drag_race << 4));
-               ao_seven_segment_set(AO_LCO_BOX_DIGIT_10, box / 10 | (ao_lco_drag_race << 4));
+               ao_seven_segment_set(AO_LCO_BOX_DIGIT_1, (uint8_t) (box % 10 | (ao_lco_drag_race << 4)));
+               ao_seven_segment_set(AO_LCO_BOX_DIGIT_10, (uint8_t) (box / 10 | (ao_lco_drag_race << 4)));
        }
        ao_mutex_put(&ao_lco_display_mutex);
 }
@@ -86,9 +86,9 @@ ao_lco_show_voltage(uint16_t decivolts)
 {
        uint8_t tens, ones, tenths;
 
-       tenths = decivolts % 10;
-       ones = (decivolts / 10) % 10;
-       tens = (decivolts / 100) % 10;
+       tenths = (uint8_t) (decivolts % 10);
+       ones = (uint8_t) ((decivolts / 10) % 10);
+       tens = (uint8_t) ((decivolts / 100) % 10);
        ao_mutex_get(&ao_lco_display_mutex);
        ao_seven_segment_set(AO_LCO_PAD_DIGIT, tenths);
        ao_seven_segment_set(AO_LCO_BOX_DIGIT_1, ones | 0x10);
@@ -127,7 +127,7 @@ static uint8_t              ao_lco_drag_active;
 static AO_TICK_TYPE
 ao_lco_drag_button_check(AO_TICK_TYPE now, AO_TICK_TYPE delay)
 {
-       AO_TICK_TYPE    button_delay = ~0;
+       AO_TICK_TYPE    button_delay = ~0UL;
 
        /*
         * Check to see if the button has been held down long enough
@@ -135,14 +135,14 @@ ao_lco_drag_button_check(AO_TICK_TYPE now, AO_TICK_TYPE delay)
         */
        if (ao_lco_fire_down) {
                if (ao_lco_drag_race) {
-                       if ((AO_TICK_SIGNED) (now - ao_lco_fire_tick) >= AO_LCO_DRAG_RACE_STOP_TIME) {
+                       if ((AO_TICK_SIGNED) (now - ao_lco_fire_tick) >= (AO_TICK_SIGNED) AO_LCO_DRAG_RACE_STOP_TIME) {
                                ao_lco_drag_disable();
                                ao_lco_fire_down = 0;
                        }
                        else
                                button_delay = ao_lco_fire_tick + AO_LCO_DRAG_RACE_STOP_TIME - now;
                } else {
-                       if ((AO_TICK_SIGNED) (now - ao_lco_fire_tick) >= AO_LCO_DRAG_RACE_START_TIME) {
+                       if ((AO_TICK_SIGNED) (now - ao_lco_fire_tick) >= (AO_TICK_SIGNED) AO_LCO_DRAG_RACE_START_TIME) {
                                ao_lco_drag_enable();
                                ao_lco_fire_down = 0;
                        }
@@ -158,7 +158,7 @@ ao_lco_drag_button_check(AO_TICK_TYPE now, AO_TICK_TYPE delay)
 static void
 ao_lco_drag_monitor(void)
 {
-       AO_TICK_TYPE    delay = ~0;
+       AO_TICK_TYPE    delay = ~0UL;
        AO_TICK_TYPE    now;
 
        ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(200));
@@ -170,7 +170,7 @@ ao_lco_drag_monitor(void)
                else
                        ao_sleep_for(&ao_lco_drag_beep_count, delay);
 
-               delay = ~0;
+               delay = ~0UL;
                if (!ao_lco_drag_active)
                        continue;
 
@@ -181,7 +181,7 @@ ao_lco_drag_monitor(void)
 
                /* check to see if there's anything left to do here */
                if (!ao_lco_fire_down && !ao_lco_drag_race && !ao_lco_drag_beep_count) {
-                       delay = ~0;
+                       delay = ~0UL;
                        ao_lco_drag_active = 0;
                }
        }
@@ -190,7 +190,7 @@ ao_lco_drag_monitor(void)
 static void
 ao_lco_step_box(int8_t dir)
 {
-       int16_t new_box = ao_lco_box;
+       int32_t new_box = (int32_t) ao_lco_box;
        do {
                if (new_box == AO_LCO_BOX_DRAG) {
                        if (dir < 0)
@@ -204,10 +204,10 @@ ao_lco_step_box(int8_t dir)
                        else if (new_box < ao_lco_min_box)
                                new_box = AO_LCO_BOX_DRAG;
                }
-               if (new_box == ao_lco_box)
+               if (new_box == (int32_t) ao_lco_box)
                        break;
-       } while (!ao_lco_box_present(new_box));
-       ao_lco_set_box(new_box);
+       } while (!ao_lco_box_present((uint16_t) new_box));
+       ao_lco_set_box((uint16_t) new_box);
 }
 
 static void
@@ -235,12 +235,12 @@ ao_lco_input(void)
                case AO_EVENT_BUTTON:
                        switch (event.unit) {
                        case AO_BUTTON_ARM:
-                               ao_lco_set_armed(event.value);
+                               ao_lco_set_armed((uint8_t) event.value);
                                break;
                        case AO_BUTTON_FIRE:
                                if (ao_lco_armed) {
                                        ao_lco_fire_down = 0;
-                                       ao_lco_set_firing(event.value);
+                                       ao_lco_set_firing((uint8_t) event.value);
                                } else {
                                        if (event.value) {
                                                if (ao_lco_box == AO_LCO_BOX_DRAG) {
@@ -290,7 +290,7 @@ ao_lco_batt_voltage(void)
 
        ao_adc_single_get(&packet);
        decivolt = ao_battery_decivolt(packet.v_batt);
-       ao_lco_show_voltage(decivolt);
+       ao_lco_show_voltage((uint16_t) decivolt);
        ao_delay(AO_MS_TO_TICKS(1000));
 }
 #endif
@@ -319,7 +319,7 @@ ao_lco_main(void)
 static void
 ao_lco_set_debug(void)
 {
-       uint16_t r  = ao_cmd_decimal();
+       uint32_t r  = ao_cmd_decimal();
        if (ao_cmd_status == ao_cmd_success)
                ao_lco_debug = r != 0;
 }
index 452092a092df80a4aa940e27f3b623977b5a1020..65e9a8c9cb76c4a70a6650eb7145a75682056885 100644 (file)
@@ -39,7 +39,7 @@ extern uint8_t        ao_lco_drag_race;       /* true when drag race mode enabled */
 #endif
 
 extern uint8_t ao_lco_pad;             /* Currently selected pad */
-extern int16_t ao_lco_box;             /* Currently selected box */
+extern uint16_t        ao_lco_box;             /* Currently selected box */
 
 extern uint8_t ao_lco_armed;           /* armed mode active */
 extern uint8_t ao_lco_firing;          /* fire button pressed */
@@ -48,7 +48,7 @@ extern struct ao_pad_query    ao_pad_query;   /* Last received QUERY from pad */
 
 #define AO_LCO_PAD_VOLTAGE     0               /* Pad number to show box voltage */
 
-extern uint8_t ao_lco_min_box, ao_lco_max_box;
+extern uint16_t        ao_lco_min_box, ao_lco_max_box;
 
 #define AO_LCO_MASK_SIZE(n)    (((n) + 7) >> 3)
 #define AO_LCO_MASK_ID(n)      ((n) >> 3)
@@ -67,10 +67,10 @@ void
 ao_lco_update(void);
 
 uint8_t
-ao_lco_pad_present(uint8_t box, uint8_t pad);
+ao_lco_pad_present(uint16_t box, uint8_t pad);
 
 uint8_t
-ao_lco_pad_first(uint8_t box);
+ao_lco_pad_first(uint16_t box);
 
 void
 ao_lco_set_pad(uint8_t new_pad);
index b97662a0b29fd1eda6423eb5d1092b7b5300a8d3..c88170b8c91dec772d36747715b955978d502de0 100644 (file)
 uint8_t                ao_lco_debug;
 
 uint8_t                ao_lco_pad;
-int16_t                ao_lco_box;
+uint16_t       ao_lco_box;
 
 uint8_t                ao_lco_armed;                                   /* arm active */
 uint8_t                ao_lco_firing;                                  /* fire active */
 
-uint8_t                ao_lco_min_box, ao_lco_max_box;
+uint16_t       ao_lco_min_box, ao_lco_max_box;
 
 #if AO_LCO_DRAG
 uint8_t                ao_lco_drag_race;
@@ -136,7 +136,7 @@ ao_lco_igniter_status(void)
 }
 
 uint8_t
-ao_lco_pad_present(uint8_t box, uint8_t pad)
+ao_lco_pad_present(uint16_t box, uint8_t pad)
 {
        /* voltage measurement is always valid */
        if (pad == AO_LCO_PAD_VOLTAGE)
@@ -149,7 +149,7 @@ ao_lco_pad_present(uint8_t box, uint8_t pad)
 }
 
 uint8_t
-ao_lco_pad_first(uint8_t box)
+ao_lco_pad_first(uint16_t box)
 {
        uint8_t pad;
 
@@ -160,7 +160,7 @@ ao_lco_pad_first(uint8_t box)
 }
 
 static uint8_t
-ao_lco_get_channels(uint8_t box, struct ao_pad_query *query)
+ao_lco_get_channels(uint16_t box, struct ao_pad_query *query)
 {
        int8_t                  r;
 
@@ -169,7 +169,7 @@ ao_lco_get_channels(uint8_t box, struct ao_pad_query *query)
                ao_lco_channels[box] = query->channels;
                ao_lco_valid[box] = AO_LCO_VALID_LAST | AO_LCO_VALID_EVER;
        } else
-               ao_lco_valid[box] &= ~AO_LCO_VALID_LAST;
+               ao_lco_valid[box] &= (uint8_t) ~AO_LCO_VALID_LAST;
        PRINTD("ao_lco_get_channels(%d) rssi %d valid %d ret %d offset %d\n", box, ao_radio_cmac_rssi, ao_lco_valid[box], r, ao_lco_tick_offset[box]);
        ao_wakeup(&ao_pad_query);
        return ao_lco_valid[box];
@@ -201,7 +201,7 @@ ao_lco_box_reset_present(void)
 }
 
 static void
-ao_lco_box_set_present(uint8_t box)
+ao_lco_box_set_present(uint16_t box)
 {
        if (box < ao_lco_min_box)
                ao_lco_min_box = box;
@@ -209,7 +209,7 @@ ao_lco_box_set_present(uint8_t box)
                ao_lco_max_box = box;
        if (box >= AO_PAD_MAX_BOXES)
                return;
-       ao_lco_box_mask[AO_LCO_MASK_ID(box)] |= 1 << AO_LCO_MASK_SHIFT(box);
+       ao_lco_box_mask[AO_LCO_MASK_ID(box)] |= (uint8_t) (1 << AO_LCO_MASK_SHIFT(box));
 }
 
 void
@@ -232,9 +232,9 @@ ao_lco_set_box(uint16_t new_box)
 void
 ao_lco_step_pad(int8_t dir)
 {
-       int8_t  new_pad;
+       int16_t new_pad;
 
-       new_pad = ao_lco_pad;
+       new_pad = (int16_t) ao_lco_pad;
        do {
                new_pad += dir;
                if (new_pad > AO_PAD_MAX_CHANNELS)
@@ -243,8 +243,8 @@ ao_lco_step_pad(int8_t dir)
                        new_pad = AO_PAD_MAX_CHANNELS;
                if (new_pad == ao_lco_pad)
                        break;
-       } while (!ao_lco_pad_present(ao_lco_box, new_pad));
-       ao_lco_set_pad(new_pad);
+       } while (!ao_lco_pad_present(ao_lco_box, (uint8_t) new_pad));
+       ao_lco_set_pad((uint8_t) new_pad);
 }
 
 void
@@ -255,7 +255,7 @@ ao_lco_set_armed(uint8_t armed)
        if (ao_lco_armed) {
 #if AO_LCO_DRAG
                if (ao_lco_drag_race) {
-                       uint8_t box;
+                       uint16_t        box;
 
                        for (box = ao_lco_min_box; box <= ao_lco_max_box; box++)
                                if (ao_lco_selected[box])
@@ -323,7 +323,7 @@ void
 ao_lco_monitor(void)
 {
        AO_TICK_TYPE            delay;
-       uint8_t                 box;
+       uint16_t                box;
 
        for (;;) {
                PRINTD("monitor armed %d firing %d\n",
@@ -380,7 +380,7 @@ void
 ao_lco_toggle_drag(void)
 {
        if (ao_lco_drag_race && ao_lco_pad != AO_LCO_PAD_VOLTAGE) {
-               ao_lco_selected[ao_lco_box] ^= (1 << (ao_lco_pad - 1));
+               ao_lco_selected[ao_lco_box] ^= (uint8_t) (1 << (ao_lco_pad - 1));
                PRINTD("Toggle box %d pad %d (pads now %x) to drag race\n",
                       ao_lco_pad, ao_lco_box, ao_lco_selected[ao_lco_box]);
                ao_lco_drag_add_beeps(ao_lco_pad);
index 0184363533390736f2e831f829285e8a83e6e676..391b4547560bc69a8950cf15dad8448c21548bf8 100644 (file)
@@ -32,8 +32,8 @@ static uint8_t        lco_channels;
 static void
 lco_args(void) 
 {
-       lco_box = ao_cmd_decimal();
-       lco_channels = ao_cmd_hex();
+       lco_box = (uint16_t) ao_cmd_decimal();
+       lco_channels = (uint8_t) ao_cmd_hex();
 }
 
 static struct ao_pad_query     ao_pad_query;
@@ -126,7 +126,7 @@ lco_fire_cmd(void)
        int8_t          r;
 
        lco_args();
-       secs = ao_cmd_decimal();
+       secs = (uint8_t) ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        r = lco_query();
@@ -140,7 +140,7 @@ lco_fire_cmd(void)
                lco_arm();
        }
 
-       secs = secs * 10 - 5;
+       secs = (uint8_t) (secs * 10 - 5);
        if (secs > 100)
                secs = 100;
        for (i = 0; i < secs; i++) {
@@ -159,7 +159,7 @@ lco_static_cmd(void)
        int8_t          r;
 
        lco_args();
-       secs = ao_cmd_decimal();
+       secs = (uint8_t) ao_cmd_decimal();
        if (ao_cmd_status != ao_cmd_success)
                return;
        r = lco_query();
@@ -173,7 +173,7 @@ lco_static_cmd(void)
                lco_arm();
        }
 
-       secs = secs * 10 - 5;
+       secs = (uint8_t) (secs * 10 - 5);
        if (secs > 100)
                secs = 100;
        for (i = 0; i < secs; i++) {
index 1960683fa6b214a56cd7fd87800cd1a7c6e7562d..5aacd0e48c3f51dd52d81fb1e75e15cff0bd4693 100644 (file)
@@ -45,7 +45,7 @@ ao_lco_query(uint16_t box, struct ao_pad_query *query, uint16_t *tick_offset)
        }
 #endif
        ao_mutex_get(&ao_lco_mutex);
-       command.tick = ao_time();
+       command.tick = (uint16_t) ao_time();
        command.box = box;
        command.cmd = AO_PAD_QUERY;
        command.channels = 0;
@@ -53,7 +53,7 @@ ao_lco_query(uint16_t box, struct ao_pad_query *query, uint16_t *tick_offset)
        sent_time = ao_time();
        r = ao_radio_cmac_recv(query, sizeof (*query), timeout);
        if (r == AO_RADIO_CMAC_OK)
-               *tick_offset = sent_time - query->tick;
+               *tick_offset = (uint16_t) sent_time - query->tick;
        ao_mutex_put(&ao_lco_mutex);
        return r;
 }
index 8d4476efdbe08c1c4f6ff6185ff2e5f8b591be5b..0eb90080acb76dae8d288b8fe466d6d39b06ab32 100644 (file)
@@ -85,15 +85,15 @@ ao_lco_input(void)
                case AO_EVENT_BUTTON:
                        switch (event.unit) {
                        case AO_BUTTON_BOX:
-                               ao_lco_set_box(event.value);
+                               ao_lco_set_box((uint16_t) event.value);
                                ao_lco_set_armed(0);
                                break;
                        case AO_BUTTON_ARM:
-                               ao_lco_set_armed(event.value);
+                               ao_lco_set_armed((uint8_t) event.value);
                                break;
                        case AO_BUTTON_FIRE:
                                if (ao_lco_armed)
-                                       ao_lco_set_firing(event.value);
+                                       ao_lco_set_firing((uint8_t) event.value);
                                break;
                        }
                        break;
@@ -114,9 +114,9 @@ ao_lco_main(void)
        ao_add_task(&ao_lco_input_task, ao_lco_input, "lco input");
        ao_add_task(&ao_lco_arm_warn_task, ao_lco_arm_warn, "lco arm warn");
        ao_add_task(&ao_lco_igniter_status_task, ao_lco_igniter_status, "lco igniter status");
-       ao_led_on(~0);
+       ao_led_on((uint16_t) ~0);
        ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(200));
-       ao_led_off(~0);
+       ao_led_off((uint16_t) ~0);
        ao_lco_monitor();
 }
 
@@ -124,9 +124,9 @@ ao_lco_main(void)
 static void
 ao_lco_set_debug(void)
 {
-       uint16_t r = ao_cmd_decimal();
+       uint32_t r = ao_cmd_decimal();
        if (ao_cmd_status == ao_cmd_success)
-               ao_lco_debug = r;
+               ao_lco_debug = r != 0;
 }
 
 const struct ao_cmds ao_lco_cmds[] = {