rc_proto: allow to configure timers
[protos/xbee-avr.git] / rc_proto.c
index d8c4727..8ea3767 100644 (file)
 
 #define RX_DB_THRESHOLD 65 /* mean -65 dB */
 
-/* XXX make it configurable */
-/* min time between 2 servo_send */
-#define SEND_SERVO_MIN_TIME_MS 50
-/* max time between 2 servo_send */
-#define SEND_SERVO_MAX_TIME_MS 300
-/* time before switching into bypass mode when no servo command received */
-#define AUTO_BYPASS_TIME_MS 500
+/* default values */
+struct rc_proto_timers rc_proto_timers = {
+       .send_servo_min_ms = 50,
+       .send_servo_max_ms = 300,
+       .send_power_probe_ms = 500,
+       .autobypass_ms = 500,
+};
 
 /* rc_proto statistics, accessed with sched_prio=XBEE_PRIO */
 struct rc_proto_stats_data {
@@ -368,7 +368,7 @@ static int8_t rc_proto_send_servos(void)
        /* if we transmitted servos values recently, nothing to do */
        ms = get_time_ms();
        diff = ms - servo_tx.time;
-       if (diff < SEND_SERVO_MIN_TIME_MS)
+       if (diff < rc_proto_timers.send_servo_min_ms)
                return 0;
 
        /* prepare values to send */
@@ -401,7 +401,7 @@ static int8_t rc_proto_send_servos(void)
        /* if no value changed and last message is acknowledged, don't transmit
         * if we already transmitted quite recently */
        if (updated == 0 && ack == servo_tx.seq &&
-               diff < SEND_SERVO_MAX_TIME_MS)
+               diff < rc_proto_timers.send_servo_max_ms)
                return 0;
 
        /* ok, we need to transmit */
@@ -711,7 +711,7 @@ static void rc_proto_cb(struct callout_mgr *cm, struct callout *tim, void *arg)
        /* send power probe periodically */
        if (rc_proto_flags & RC_PROTO_FLAGS_TX_POW_PROBE) {
                diff = t - prev_power_probe;
-               if (diff > AUTO_BYPASS_TIME_MS) {
+               if (diff > rc_proto_timers.send_power_probe_ms) {
                        pow_probe++;
                        if (pow_probe > 4)
                                pow_probe = 0;
@@ -723,7 +723,7 @@ static void rc_proto_cb(struct callout_mgr *cm, struct callout *tim, void *arg)
        /* on wing, auto bypass servos if no commands since some time */
        if (rc_proto_flags & RC_PROTO_FLAGS_RX_AUTOBYPASS) {
                diff = t - servo_rx.time;
-               if (diff > AUTO_BYPASS_TIME_MS)
+               if (diff > rc_proto_timers.autobypass_ms)
                        spi_servo_set_bypass(1);
        }