#define AO_LCO_BOX_DRAG 0x1000
/* UI values */
-static uint16_t ao_lco_fire_tick;
+static AO_TICK_TYPE ao_lco_fire_tick;
static uint8_t ao_lco_fire_down;
static uint8_t ao_lco_display_mutex;
static struct ao_task ao_lco_drag_task;
static uint8_t ao_lco_drag_active;
-static uint16_t
-ao_lco_drag_button_check(uint16_t now, uint16_t delay)
+static AO_TICK_TYPE
+ao_lco_drag_button_check(AO_TICK_TYPE now, AO_TICK_TYPE delay)
{
- uint16_t button_delay = ~0;
+ AO_TICK_TYPE button_delay = ~0;
/*
* Check to see if the button has been held down long enough
*/
if (ao_lco_fire_down) {
if (ao_lco_drag_race) {
- if ((int16_t) (now - ao_lco_fire_tick) >= AO_LCO_DRAG_RACE_STOP_TIME) {
+ if ((AO_TICK_SIGNED) (now - ao_lco_fire_tick) >= 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 ((int16_t) (now - ao_lco_fire_tick) >= AO_LCO_DRAG_RACE_START_TIME) {
+ if ((AO_TICK_SIGNED) (now - ao_lco_fire_tick) >= AO_LCO_DRAG_RACE_START_TIME) {
ao_lco_drag_enable();
ao_lco_fire_down = 0;
}
static void
ao_lco_drag_monitor(void)
{
- uint16_t delay = ~0;
- uint16_t now;
+ AO_TICK_TYPE delay = ~0;
+ AO_TICK_TYPE now;
ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(200));
for (;;) {
PRINTD("Drag monitor count %d active %d delay %d\n",
ao_lco_drag_beep_count, ao_lco_drag_active, delay);
- if (delay == (uint16_t) ~0)
+ if (delay == (AO_TICK_TYPE) ~0)
ao_sleep(&ao_lco_drag_beep_count);
else
ao_sleep_for(&ao_lco_drag_beep_count, delay);
ao_lco_drag_disable(void);
/* Handle drag beeps, return new delay */
-uint16_t
-ao_lco_drag_beep_check(uint16_t now, uint16_t delay);
+AO_TICK_TYPE
+ao_lco_drag_beep_check(AO_TICK_TYPE now, AO_TICK_TYPE delay);
/* Check if it's time to beep during drag race. Return new delay */
-uint16_t
-ao_lco_drag_warn_check(uint16_t now, uint16_t delay);
+AO_TICK_TYPE
+ao_lco_drag_warn_check(AO_TICK_TYPE now, AO_TICK_TYPE delay);
/* Request 'beeps' additional drag race beeps */
void
struct ao_pad_query ao_pad_query; /* latest query response */
static uint8_t ao_lco_channels[AO_PAD_MAX_BOXES]; /* pad channels available on each box */
-static uint16_t ao_lco_tick_offset[AO_PAD_MAX_BOXES]; /* offset from local to remote tick count */
+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
void
ao_lco_monitor(void)
{
- uint16_t delay;
+ AO_TICK_TYPE delay;
uint8_t box;
for (;;) {
uint8_t ao_lco_drag_beep_count;
static uint8_t ao_lco_drag_beep_on;
-static uint16_t ao_lco_drag_beep_time;
-static uint16_t ao_lco_drag_warn_time;
+static AO_TICK_TYPE ao_lco_drag_beep_time;
+static AO_TICK_TYPE ao_lco_drag_warn_time;
#define AO_LCO_DRAG_BEEP_TIME AO_MS_TO_TICKS(50)
#define AO_LCO_DRAG_WARN_TIME AO_SEC_TO_TICKS(5)
* turn it on or off as necessary and bump the remaining beep counts
*/
-uint16_t
-ao_lco_drag_beep_check(uint16_t now, uint16_t delay)
+AO_TICK_TYPE
+ao_lco_drag_beep_check(AO_TICK_TYPE now, AO_TICK_TYPE delay)
{
PRINTD("beep check count %d delta %d\n",
ao_lco_drag_beep_count,
- (int16_t) (now - ao_lco_drag_beep_time));
+ (AO_TICK_SIGNED) (now - ao_lco_drag_beep_time));
if (ao_lco_drag_beep_count) {
- if ((int16_t) (now - ao_lco_drag_beep_time) >= 0) {
+ if ((AO_TICK_SIGNED) (now - ao_lco_drag_beep_time) >= 0) {
if (ao_lco_drag_beep_on) {
ao_beep(0);
PRINTD("beep stop\n");
}
if (ao_lco_drag_beep_count) {
- uint16_t beep_delay = 0;
+ AO_TICK_TYPE beep_delay = 0;
if (ao_lco_drag_beep_time > now)
beep_delay = ao_lco_drag_beep_time - now;
* active
*/
-uint16_t
-ao_lco_drag_warn_check(uint16_t now, uint16_t delay)
+AO_TICK_TYPE
+ao_lco_drag_warn_check(AO_TICK_TYPE now, AO_TICK_TYPE delay)
{
if (ao_lco_drag_race) {
- uint16_t warn_delay;
+ AO_TICK_TYPE warn_delay;
- if ((int16_t) (now - ao_lco_drag_warn_time) >= 0) {
+ if ((AO_TICK_SIGNED) (now - ao_lco_drag_warn_time) >= 0) {
ao_lco_drag_add_beeps(1);
ao_lco_drag_warn_time = now + AO_LCO_DRAG_WARN_TIME;
}
static uint16_t lco_box;
static uint8_t lco_channels;
-static uint16_t tick_offset;
static void
lco_args(void)
ao_lco_query(uint16_t box, struct ao_pad_query *query, uint16_t *tick_offset)
{
int8_t r;
- uint16_t sent_time;
- uint16_t timeout = AO_MS_TO_TICKS(10);
+ AO_TICK_TYPE sent_time;
+ AO_TICK_TYPE timeout = AO_MS_TO_TICKS(10);
#if HAS_RADIO_RATE
switch (ao_config.radio_rate) {
ao_lco_arm(uint16_t box, uint8_t channels, uint16_t tick_offset)
{
ao_mutex_get(&ao_lco_mutex);
- command.tick = ao_time() - tick_offset;
+ command.tick = (uint16_t) ao_time() - tick_offset;
command.box = box;
command.cmd = AO_PAD_ARM;
command.channels = channels;
static struct ao_pad_command command;
static struct ao_pad_query query;
static uint8_t ao_pad_armed;
-static uint16_t ao_pad_arm_time;
+static AO_TICK_TYPE ao_pad_arm_time;
static uint8_t ao_pad_box;
static uint8_t ao_pad_disabled;
-static uint16_t ao_pad_packet_time;
+static AO_TICK_TYPE ao_pad_packet_time;
#ifndef AO_PAD_RSSI_MINIMUM
#define AO_PAD_RSSI_MINIMUM -90
prev = cur;
}
- if (ao_pad_armed && (int16_t) (ao_time() - ao_pad_arm_time) > AO_PAD_ARM_TIME)
+ if (ao_pad_armed && (AO_TICK_SIGNED) (ao_time() - ao_pad_arm_time) > AO_PAD_ARM_TIME)
ao_pad_armed = 0;
if (ao_pad_armed) {
static void
ao_pad(void)
{
- int16_t time_difference;
+ int16_t tick_difference;
int8_t ret;
ao_pad_box = 0;
if (command.channels & ~(AO_PAD_ALL_CHANNELS))
break;
- time_difference = command.tick - ao_time();
- PRINTD ("arm tick %d local tick %d\n", command.tick, ao_time());
- if (time_difference < 0)
- time_difference = -time_difference;
- if (time_difference > 10) {
- PRINTD ("time difference too large %d\n", time_difference);
+ tick_difference = command.tick - (uint16_t) ao_time();
+ PRINTD ("arm tick %d local tick %d\n", command.tick, (uint16_t) ao_time());
+ if (tick_difference < 0)
+ tick_difference = -tick_difference;
+ if (tick_difference > 10) {
+ PRINTD ("tick difference too large %d\n", tick_difference);
break;
}
if (query.arm_status != AO_PAD_ARM_STATUS_ARMED) {
PRINTD ("not armed\n");
break;
}
- if ((uint16_t) (ao_time() - ao_pad_arm_time) > AO_SEC_TO_TICKS(20)) {
+ if ((AO_TICK_SIGNED) (ao_time() - ao_pad_arm_time) > AO_SEC_TO_TICKS(20)) {
PRINTD ("late pad arm_time %d time %d\n",
ao_pad_arm_time, ao_time());
break;
#if HAS_LOG
if (!ao_log_running) ao_log_start();
#endif
- if ((uint16_t) (ao_time() - ao_pad_arm_time) > AO_SEC_TO_TICKS(20)) {
+ if ((AO_TICK_SIGNED) (ao_time() - ao_pad_arm_time) > AO_SEC_TO_TICKS(20)) {
PRINTD ("late pad arm_time %d time %d\n",
ao_pad_arm_time, ao_time());
break;
static void
ao_lco_drag_monitor(void)
{
- uint16_t delay = ~0;
- uint16_t now;
+ AO_TICK_TYPE delay = ~0;
+ AO_TICK_TYPE now;
ao_beep_for(AO_BEEP_MID, AO_MS_TO_TICKS(200));
for (;;) {
PRINTD("Drag monitor count %d delay %d\n", ao_lco_drag_beep_count, delay);
- if (delay == (uint16_t) ~0)
+ if (delay == (AO_TICK_TYPE) ~0)
ao_sleep(&ao_lco_drag_beep_count);
else
ao_sleep_for(&ao_lco_drag_beep_count, delay);