uint8_t ao_lco_debug;
-uint8_t ao_lco_pad;
+int8_t ao_lco_pad;
int16_t ao_lco_box;
uint8_t ao_lco_armed; /* arm active */
static uint16_t ao_lco_tick_offset[AO_PAD_MAX_BOXES]; /* 16 bit offset from local to remote tick count */
static uint8_t ao_lco_selected[AO_PAD_MAX_BOXES]; /* pads selected to fire */
-#define AO_LCO_VALID_LAST 1
-#define AO_LCO_VALID_EVER 2
-
-static uint8_t ao_lco_valid[AO_PAD_MAX_BOXES]; /* AO_LCO_VALID bits per box */
+uint8_t ao_lco_valid[AO_PAD_MAX_BOXES]; /* AO_LCO_VALID bits per box */
static const AO_LED_TYPE continuity_led[AO_LED_CONTINUITY_NUM] = {
#ifdef AO_LED_CONTINUITY_0
}
uint8_t
-ao_lco_pad_present(int16_t box, uint8_t pad)
+ao_lco_pad_present(int16_t box, int8_t pad)
{
/* voltage measurement is always valid */
- if (pad == AO_LCO_PAD_VOLTAGE)
+ if (ao_lco_pad_pseudo(pad))
return 1;
if (!ao_lco_channels[box])
return 0;
return (ao_lco_channels[box] >> (pad - 1)) & 1;
}
-uint8_t
+int8_t
ao_lco_pad_first(int16_t box)
{
- uint8_t pad;
+ int8_t pad;
for (pad = 1; pad <= AO_PAD_MAX_CHANNELS; pad++)
if (ao_lco_pad_present(box, pad))
if (ao_lco_get_channels(ao_lco_box, &ao_pad_query) & AO_LCO_VALID_LAST) {
if (!(previous_valid & AO_LCO_VALID_EVER)) {
- if (ao_lco_pad != AO_LCO_PAD_VOLTAGE)
+ if (!ao_lco_pad_pseudo(ao_lco_pad))
ao_lco_set_pad(ao_lco_pad_first(ao_lco_box));
}
- if (ao_lco_pad == AO_LCO_PAD_VOLTAGE)
+ if (ao_lco_pad_pseudo(ao_lco_pad))
ao_lco_show();
}
}
}
void
-ao_lco_set_pad(uint8_t new_pad)
+ao_lco_set_pad(int8_t new_pad)
{
ao_lco_pad = new_pad;
ao_lco_show();
{
int16_t new_pad;
+ switch (ao_lco_box) {
#ifdef AO_LCO_HAS_CONTRAST
- if (ao_lco_box == AO_LCO_CONTRAST) {
- int16_t contrast = ao_lco_get_contrast();
+ case AO_LCO_CONTRAST: {
+ int32_t contrast = ao_lco_get_contrast();
- contrast += (int16_t) (dir * AO_LCO_CONTRAST_STEP);
+ contrast = (contrast + AO_LCO_CONTRAST_STEP - 1) / AO_LCO_CONTRAST_STEP;
+ contrast += dir;
+ contrast *= AO_LCO_CONTRAST_STEP;
if (contrast < AO_LCO_MIN_CONTRAST)
contrast = AO_LCO_MIN_CONTRAST;
if (contrast > AO_LCO_MAX_CONTRAST)
contrast = AO_LCO_MAX_CONTRAST;
ao_lco_set_contrast(contrast);
+ ao_lco_show();
+ break;
}
#endif
- new_pad = (int16_t) ao_lco_pad;
- do {
- new_pad += dir;
- if (new_pad > AO_PAD_MAX_CHANNELS)
- new_pad = AO_LCO_PAD_VOLTAGE;
- if (new_pad < 0)
- new_pad = AO_PAD_MAX_CHANNELS;
- if (new_pad == ao_lco_pad)
- break;
- } while (!ao_lco_pad_present(ao_lco_box, (uint8_t) new_pad));
- PRINTD("New pad %d\n", new_pad);
- ao_lco_set_pad((uint8_t) new_pad);
+#ifdef AO_LCO_HAS_BACKLIGHT
+ case AO_LCO_BACKLIGHT: {
+ int32_t backlight = ao_lco_get_backlight();
+
+ backlight = (backlight + AO_LCO_BACKLIGHT_STEP - 1) / AO_LCO_BACKLIGHT_STEP;
+ backlight += dir;
+ backlight *= AO_LCO_BACKLIGHT_STEP;
+ if (backlight < AO_LCO_MIN_BACKLIGHT)
+ backlight = AO_LCO_MIN_BACKLIGHT;
+ if (backlight > AO_LCO_MAX_BACKLIGHT)
+ backlight = AO_LCO_MAX_BACKLIGHT;
+ ao_lco_set_backlight(backlight);
+ ao_lco_show();
+ break;
+ }
+#endif
+#ifdef AO_LCO_HAS_INFO
+ case AO_LCO_INFO: {
+#if AO_LCO_MIN_INFO_PAGE < AO_LCO_MAX_INFO_PAGE
+ int32_t info_page = ao_lco_get_info_page();
+
+ info += dir;
+ if (info_page < AO_LCO_MIN_INFO_PAGE)
+ info_page = AO_LCO_MIN_INFO_PAGE;
+ if (info_page > AO_LCO_MAX_INFO_PAGE)
+ info_page = AO_LCO_MAX_INFO_PAGE;
+ ao_lco_set_info_page();
+#endif
+ break;
+ }
+#endif
+ default:
+ new_pad = (int16_t) ao_lco_pad;
+ do {
+ new_pad += dir;
+ if (new_pad > AO_PAD_MAX_CHANNELS)
+ new_pad = AO_LCO_PAD_FIRST;
+ if (new_pad < AO_LCO_PAD_FIRST)
+ new_pad = AO_PAD_MAX_CHANNELS;
+ if (new_pad == ao_lco_pad)
+ break;
+ } while (!ao_lco_pad_present(ao_lco_box, (int8_t) new_pad));
+ PRINTD("New pad %d\n", new_pad);
+ ao_lco_set_pad((int8_t) new_pad);
+ break;
+ }
}
uint8_t
new_box += dir;
if (new_box > ao_lco_max_box)
new_box = AO_LCO_BOX_FIRST;
-#ifdef AO_LCO_HAS_CONTRAST
- else if (new_box < AO_LCO_CONTRAST)
-#else
- else if (new_box < 0)
-#endif
+ else if (new_box < AO_LCO_BOX_FIRST)
new_box = ao_lco_max_box;
if (new_box == ao_lco_box)
break;
ao_wakeup(&ao_lco_armed);
}
+#if 0
+static int16_t fake_boxes[] = {
+ 1, 2, 3, 5, 8, 11, 13, 17, 19, 23, 29, 31, 37, 62, 97
+};
+#define ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0]))
+#define NFAKE ARRAYSIZE(fake_boxes)
+
+static bool
+is_fake(int16_t box)
+{
+ unsigned i;
+ for (i = 0; i < NFAKE; i++)
+ if (fake_boxes[i] == box)
+ return true;
+ return false;
+}
+#else
+#define is_fake(b) false
+#endif
+
void
ao_lco_search(void)
{
ao_lco_tick_offset[box] = 0;
r = ao_lco_query((uint16_t) box, &ao_pad_query, &ao_lco_tick_offset[box]);
PRINTD("box %d result %d offset %d\n", box, r, ao_lco_tick_offset[box]);
- if (r == AO_RADIO_CMAC_OK) {
+ if (r == AO_RADIO_CMAC_OK || is_fake(box)) {
++boxes;
ao_lco_box_set_present(box);
#ifdef AO_LCO_SEARCH_API
ao_lco_search_box_present(box);
#else
- ao_lco_show_pad((uint8_t) (boxes % 10));
+ ao_lco_show_pad((int8_t) (boxes % 10));
#endif
ao_delay(AO_MS_TO_TICKS(30));
break;
#if AO_LCO_DRAG
-uint8_t ao_lco_drag_beep_count;
+int8_t ao_lco_drag_beep_count;
static uint8_t ao_lco_drag_beep_on;
static AO_TICK_TYPE ao_lco_drag_beep_time;
static AO_TICK_TYPE ao_lco_drag_warn_time;
/* Request 'beeps' additional drag race beeps */
void
-ao_lco_drag_add_beeps(uint8_t beeps)
+ao_lco_drag_add_beeps(int8_t beeps)
{
PRINTD("beep %d\n", beeps);
if (ao_lco_drag_beep_count == 0)
void
ao_lco_toggle_drag(void)
{
- if (ao_lco_drag_race && ao_lco_pad != AO_LCO_PAD_VOLTAGE && !ao_lco_box_pseudo(ao_lco_box)) {
+ if (ao_lco_drag_race && !ao_lco_pad_pseudo(ao_lco_pad) && !ao_lco_box_pseudo(ao_lco_box)) {
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]);