From 56ebb0a2f50fd56f4f0b0c695e516bee8fae36fb Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 14 Oct 2012 23:16:45 -0700 Subject: altos/telelco: Only present valid pads Limit pad display to valid pads, skipping missing ones. Signed-off-by: Keith Packard --- src/telelco-v0.1/ao_lco.c | 82 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 63 insertions(+), 19 deletions(-) (limited to 'src/telelco-v0.1') diff --git a/src/telelco-v0.1/ao_lco.c b/src/telelco-v0.1/ao_lco.c index 41bba0ba..3421e1df 100644 --- a/src/telelco-v0.1/ao_lco.c +++ b/src/telelco-v0.1/ao_lco.c @@ -43,6 +43,9 @@ static uint8_t ao_lco_box; static uint8_t ao_lco_armed; static uint8_t ao_lco_firing; static uint8_t ao_lco_valid; +static uint16_t ao_lco_tick_offset; + +static struct ao_pad_query ao_pad_query; static void ao_lco_set_pad(void) @@ -71,11 +74,32 @@ ao_lco_box_present(uint8_t box) return (ao_lco_box_mask[MASK_ID(box)] >> MASK_SHIFT(box)) & 1; } +static uint8_t +ao_lco_pad_present(uint8_t pad) +{ + if (!ao_lco_valid || !ao_pad_query.channels) + return pad == 0; + if (pad >= AO_PAD_MAX_CHANNELS) + return 0; + return (ao_pad_query.channels >> pad) & 1; +} + +static uint8_t +ao_lco_pad_first(void) +{ + uint8_t pad; + + for (pad = 0; pad < AO_PAD_MAX_CHANNELS; pad++) + if (ao_lco_pad_present(pad)) + return pad; + return 0; +} + static void ao_lco_input(void) { static struct ao_event event; - int8_t dir; + int8_t dir, new_box; ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(200)); ao_lco_set_pad(); @@ -89,7 +113,17 @@ ao_lco_input(void) switch (event.unit) { case AO_QUADRATURE_PAD: if (!ao_lco_armed) { - ao_lco_pad = event.value & 3; + if (event.value == ao_lco_pad) + break; + dir = ((int8_t) event.value - (int8_t) ao_lco_pad) > 0 ? 1 : -1; + ao_lco_pad = event.value; + while (!ao_lco_pad_present(ao_lco_pad)) { + ao_lco_pad += dir; + if ((int8_t) ao_lco_pad > AO_PAD_MAX_CHANNELS) + ao_lco_pad = 0; + else if ((int8_t) ao_lco_pad < 0) + ao_lco_pad = AO_PAD_MAX_CHANNELS - 1; + } ao_quadrature_count[AO_QUADRATURE_PAD] = ao_lco_pad; ao_lco_set_pad(); } @@ -98,17 +132,21 @@ ao_lco_input(void) if (!ao_lco_armed) { if (event.value == ao_lco_box) break; - dir = (event.value - ao_lco_box) > 0 ? 1 : -1; - ao_lco_box = event.value; - while (!ao_lco_box_present(ao_lco_box)) { - ao_lco_box += dir; - if (ao_lco_box > ao_lco_max_box) - ao_lco_box = ao_lco_min_box; - else if (ao_lco_box < ao_lco_min_box) - ao_lco_box = ao_lco_min_box; + dir = ((int8_t) event.value - (int8_t) ao_lco_box) > 0 ? 1 : -1; + new_box = event.value; + while (!ao_lco_box_present(new_box)) { + new_box += dir; + if (new_box > ao_lco_max_box) + new_box = ao_lco_min_box; + else if (new_box < ao_lco_min_box) + new_box = ao_lco_min_box; + } + ao_quadrature_count[AO_QUADRATURE_PAD] = new_box; + if (ao_lco_box != new_box) { + ao_lco_box = new_box; + ao_lco_valid = 0; + ao_lco_set_box(); } - ao_quadrature_count[AO_QUADRATURE_PAD] = ao_lco_box; - ao_lco_set_box(); } break; } @@ -160,10 +198,6 @@ static AO_LED_TYPE continuity_led[AO_LED_CONTINUITY_NUM] = { #endif }; -static uint16_t ao_lco_tick_offset; - -static struct ao_pad_query ao_pad_query; - static void ao_lco_update(void) { @@ -171,8 +205,14 @@ ao_lco_update(void) uint8_t c; r = ao_lco_query(ao_lco_box, &ao_pad_query, &ao_lco_tick_offset); - if (r == AO_RADIO_CMAC_OK) + if (r == AO_RADIO_CMAC_OK) { + c = ao_lco_valid; ao_lco_valid = 1; + if (!c) { + ao_lco_pad = ao_lco_pad_first(); + ao_lco_set_pad(); + } + } #if 0 PRINTD("lco_query success arm_status %d i0 %d i1 %d i2 %d i3 %d\n", @@ -213,7 +253,11 @@ ao_lco_search(void) ao_lco_box_set_present(ao_lco_box); } } - ao_lco_box = ao_lco_min_box; + if (ao_lco_min_box <= ao_lco_max_box) + ao_lco_box = ao_lco_min_box; + else + ao_lco_box = 0; + ao_lco_valid = 0; ao_lco_pad = 0; } @@ -233,7 +277,7 @@ ao_lco_igniter_status(void) continue; } PRINTD("RSSI %d\n", ao_radio_cmac_rssi); - if (ao_radio_cmac_rssi < -70) + if (ao_radio_cmac_rssi < -90) ao_led_on(AO_LED_RED|AO_LED_GREEN); else { ao_led_on(AO_LED_GREEN); -- cgit v1.2.3 From b042f3d6e6b3241cd5e55cf893242ea599d3c0e9 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 14 Oct 2012 23:24:49 -0700 Subject: altos/telelco: Handle case where no boxes are present Don't infinite loop looking for something which isn't there Signed-off-by: Keith Packard --- src/telelco-v0.1/ao_lco.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) (limited to 'src/telelco-v0.1') diff --git a/src/telelco-v0.1/ao_lco.c b/src/telelco-v0.1/ao_lco.c index 3421e1df..1bf2a825 100644 --- a/src/telelco-v0.1/ao_lco.c +++ b/src/telelco-v0.1/ao_lco.c @@ -99,7 +99,7 @@ static void ao_lco_input(void) { static struct ao_event event; - int8_t dir, new_box; + int8_t dir, new_box, new_pad; ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(200)); ao_lco_set_pad(); @@ -116,16 +116,20 @@ ao_lco_input(void) if (event.value == ao_lco_pad) break; dir = ((int8_t) event.value - (int8_t) ao_lco_pad) > 0 ? 1 : -1; - ao_lco_pad = event.value; - while (!ao_lco_pad_present(ao_lco_pad)) { - ao_lco_pad += dir; - if ((int8_t) ao_lco_pad > AO_PAD_MAX_CHANNELS) - ao_lco_pad = 0; - else if ((int8_t) ao_lco_pad < 0) - ao_lco_pad = AO_PAD_MAX_CHANNELS - 1; + new_pad = event.value; + while (!ao_lco_pad_present(new_pad)) { + new_pad += dir; + if (new_pad > AO_PAD_MAX_CHANNELS) + new_pad = 0; + else if (new_pad < 0) + new_pad = AO_PAD_MAX_CHANNELS - 1; + if (new_pad == ao_lco_pad) + break; + } + if (new_pad != ao_lco_pad) { + ao_quadrature_count[AO_QUADRATURE_PAD] = ao_lco_pad; + ao_lco_set_pad(); } - ao_quadrature_count[AO_QUADRATURE_PAD] = ao_lco_pad; - ao_lco_set_pad(); } break; case AO_QUADRATURE_BOX: @@ -140,6 +144,8 @@ ao_lco_input(void) new_box = ao_lco_min_box; else if (new_box < ao_lco_min_box) new_box = ao_lco_min_box; + if (new_box == ao_lco_box) + break; } ao_quadrature_count[AO_QUADRATURE_PAD] = new_box; if (ao_lco_box != new_box) { @@ -256,7 +262,7 @@ ao_lco_search(void) if (ao_lco_min_box <= ao_lco_max_box) ao_lco_box = ao_lco_min_box; else - ao_lco_box = 0; + ao_lco_min_box = ao_lco_max_box = ao_lco_box = 0; ao_lco_valid = 0; ao_lco_pad = 0; } -- cgit v1.2.3 From 44c13005f34fdf7d4831e86e1f3e8729e9b67a68 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sun, 14 Oct 2012 23:40:58 -0700 Subject: altos/telelco: Actually set pad when it changes Oops. Lost the actual assignment to the current pad Signed-off-by: Keith Packard --- src/telelco-v0.1/ao_lco.c | 1 + 1 file changed, 1 insertion(+) (limited to 'src/telelco-v0.1') diff --git a/src/telelco-v0.1/ao_lco.c b/src/telelco-v0.1/ao_lco.c index 1bf2a825..ab9f6747 100644 --- a/src/telelco-v0.1/ao_lco.c +++ b/src/telelco-v0.1/ao_lco.c @@ -127,6 +127,7 @@ ao_lco_input(void) break; } if (new_pad != ao_lco_pad) { + ao_lco_pad = new_pad; ao_quadrature_count[AO_QUADRATURE_PAD] = ao_lco_pad; ao_lco_set_pad(); } -- cgit v1.2.3 From fdc00ec143022356bf8cdbb28812f045b439c549 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 15 Oct 2012 00:07:57 -0700 Subject: altos/telelco: Only display every 10th box number during scan This reduces the scan time to about 4 seconds, which seems tolerable Signed-off-by: Keith Packard --- src/telelco-v0.1/ao_lco.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/telelco-v0.1') diff --git a/src/telelco-v0.1/ao_lco.c b/src/telelco-v0.1/ao_lco.c index ab9f6747..df7f865b 100644 --- a/src/telelco-v0.1/ao_lco.c +++ b/src/telelco-v0.1/ao_lco.c @@ -250,7 +250,8 @@ ao_lco_search(void) ao_lco_min_box = 0xff; ao_lco_max_box = 0x00; for (ao_lco_box = 0; ao_lco_box < AO_PAD_MAX_BOXES; ao_lco_box++) { - ao_lco_set_box(); + if ((ao_lco_box % 10) == 0) + ao_lco_set_box(); r = ao_lco_query(ao_lco_box, &ao_pad_query, &ao_lco_tick_offset); if (r == AO_RADIO_CMAC_OK) { if (ao_lco_box < ao_lco_min_box) -- cgit v1.2.3 From 60880bda2153ba3122c7102cd2bacbcca73b9e0d Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Mon, 15 Oct 2012 00:24:57 -0700 Subject: altos/telelco: Make the RSSI led turn red when no packet is received This involved splitting out the notion of ever having received an answer and having received an answer from the last query. Signed-off-by: Keith Packard --- src/telelco-v0.1/ao_lco.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/telelco-v0.1') diff --git a/src/telelco-v0.1/ao_lco.c b/src/telelco-v0.1/ao_lco.c index df7f865b..79f3896b 100644 --- a/src/telelco-v0.1/ao_lco.c +++ b/src/telelco-v0.1/ao_lco.c @@ -43,6 +43,7 @@ static uint8_t ao_lco_box; static uint8_t ao_lco_armed; static uint8_t ao_lco_firing; static uint8_t ao_lco_valid; +static uint8_t ao_lco_got_channels; static uint16_t ao_lco_tick_offset; static struct ao_pad_query ao_pad_query; @@ -77,7 +78,7 @@ ao_lco_box_present(uint8_t box) static uint8_t ao_lco_pad_present(uint8_t pad) { - if (!ao_lco_valid || !ao_pad_query.channels) + if (!ao_lco_got_channels || !ao_pad_query.channels) return pad == 0; if (pad >= AO_PAD_MAX_CHANNELS) return 0; @@ -151,7 +152,7 @@ ao_lco_input(void) ao_quadrature_count[AO_QUADRATURE_PAD] = new_box; if (ao_lco_box != new_box) { ao_lco_box = new_box; - ao_lco_valid = 0; + ao_lco_got_channels = 0; ao_lco_set_box(); } } @@ -213,13 +214,15 @@ ao_lco_update(void) r = ao_lco_query(ao_lco_box, &ao_pad_query, &ao_lco_tick_offset); if (r == AO_RADIO_CMAC_OK) { - c = ao_lco_valid; + c = ao_lco_got_channels; + ao_lco_got_channels = 1; ao_lco_valid = 1; if (!c) { ao_lco_pad = ao_lco_pad_first(); ao_lco_set_pad(); } - } + } else + ao_lco_valid = 0; #if 0 PRINTD("lco_query success arm_status %d i0 %d i1 %d i2 %d i3 %d\n", @@ -266,6 +269,7 @@ ao_lco_search(void) else ao_lco_min_box = ao_lco_max_box = ao_lco_box = 0; ao_lco_valid = 0; + ao_lco_got_channels = 0; ao_lco_pad = 0; } -- cgit v1.2.3