From 81ebe6b307f7f3cc12cca6fd7745b412cb13e429 Mon Sep 17 00:00:00 2001 From: dufourj Date: Thu, 17 May 2007 05:23:42 +0000 Subject: * Sharp: - enhance detection of front objects by using sharp with "ack" solution in ES AVR program. --- n/es-2007/src/ack.c | 1 + n/es-2007/src/ack.h | 8 ++------ n/es-2007/src/main.c | 31 ++++++++++++++++++++++++++++++- n/es-2007/src/others.h | 14 +++++--------- 4 files changed, 38 insertions(+), 16 deletions(-) diff --git a/n/es-2007/src/ack.c b/n/es-2007/src/ack.c index 7d75d6c..9ad730a 100644 --- a/n/es-2007/src/ack.c +++ b/n/es-2007/src/ack.c @@ -42,6 +42,7 @@ void ack_init (void) /* Set an ack */ void ack_set (uint8_t ack_code) { + // TODO: make an or ? ack_value = ack_code; } diff --git a/n/es-2007/src/ack.h b/n/es-2007/src/ack.h index 53a2927..2441cd9 100644 --- a/n/es-2007/src/ack.h +++ b/n/es-2007/src/ack.h @@ -32,12 +32,8 @@ * You must use a different number for each code and it must be lower than 255 * of course ! */ #define ACK_NOTHING 0 /* Nothing to ack */ -#define ACK_CONTACT_FRONT 1 /* Something in the front */ -#define ACK_BARILLET_BALL_FRONT 2 /* A ball has been get from the front - */ -#define ACK_BARILLET_BALL_REAR 3 /* Ball in the rear */ - -#define ACK_BARILLET_BALL_ARRIVED 4 /* Ball is comming */ +#define ACK_SHARP_FRONT 1 /* Something in the front */ +/* XXX Different value if right or left sharp detect something in front */ // FIXME, inline ? static ? diff --git a/n/es-2007/src/main.c b/n/es-2007/src/main.c index bf5b734..8f96cb2 100644 --- a/n/es-2007/src/main.c +++ b/n/es-2007/src/main.c @@ -54,7 +54,11 @@ uint8_t sniff_ball_stat_enable, sniff_ball_stats; uint8_t sharp_stat_enable[SHARP_NUMBER], sharp_stat_freq[SHARP_NUMBER]; uint8_t sharp_enable[SHARP_NUMBER], sharp_enable_freq[SHARP_NUMBER]; /* Analysed value of the sharps (something in front ?) */ +/* FIXME: For debug only */ uint8_t sharp_analyse_enable[SHARP_NUMBER], sharp_analyse_freq[SHARP_NUMBER]; +/* Shark Attack, maximum before considering ack is finished. */ +uint8_t sharp_ack = 10; // Default value +uint8_t sharp_ack_count = 0; /* Stats for colour selection and jack */ uint8_t others_jackcolor_stat_enable, others_jackcolor_stats; @@ -182,6 +186,7 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) if (args[0] & _BV(compt)) sharp_stat_enable[compt] = sharp_stat_freq[compt] = args[1]; break; + case c ('o', 5): sharp_config_threshold (args[0], v8_to_v16 (args[1], args[2]), v8_to_v16 (args[3], args[4])); @@ -194,6 +199,12 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args) for (compt = 0; compt < SHARP_NUMBER; compt++) if (args[0] & _BV(compt)) sharp_analyse_enable[compt] = sharp_analyse_freq[compt] = args[1]; + break; + + /* Set the value for the sharp ack disable cycle time */ + case c ('K', 1): + sharp_ack = args[0]; + break; /* LCD */ @@ -408,7 +419,6 @@ main (void) lcd_print ("> Default NFS <", 16); } } - } ascenseur_update(); @@ -421,7 +431,25 @@ main (void) { /* Re init update system for this sharp */ sharp_enable_freq[compt] = sharp_enable[compt]; + /* Compute value for the Sharp */ sharp_update_values (compt); + /* If we not are not blocked on an ack */ + if (!sharp_ack_count) + { + /* We analyse the value */ + if (sharp_analyse_values (compt) == SHARP_OBSTACLE) + { + /* We set the ack counter/locker */ + sharp_ack_count = sharp_ack; + /* We send an ack to the PC104 */ + ack_set (ACK_SHARP_FRONT); + } + } + else + { + /* If we have an ack locker/counter, we manage it */ + sharp_ack_count--; + } } /* Stats */ if (sharp_stat_enable[compt] && !--sharp_stat_freq[compt]) @@ -431,6 +459,7 @@ main (void) /* XXX 16 bits sucks */ proto_send2w ('H', compt, sharp_values[compt]); } + // FIXME: this is certainly useless! /* Print analysed value */ if (sharp_analyse_enable[compt] && !--sharp_analyse_freq[compt]) { diff --git a/n/es-2007/src/others.h b/n/es-2007/src/others.h index 9b9611f..cf58c78 100644 --- a/n/es-2007/src/others.h +++ b/n/es-2007/src/others.h @@ -33,7 +33,7 @@ /* pin responsible for the color mode */ #define JACK_PIN 0 #define SELECT_COLOR_PIN 1 -#define CONTACT_PIN 2 +#define CONTACT_PIN 2 // XXX Disable /* (to be set 1 <-> 0) */ #define BLUE_COLOR_GAME_MODE _BV(0) /* 0000 0000 = 0 */ @@ -64,8 +64,10 @@ inline uint8_t others_contact (void) /** Update ack if some contact happened ! */ inline void others_contact_update (void) { - if (others_contact ()) - ack_set (ACK_CONTACT_FRONT); + return; + // XXX Remove useless part XXX +// if (others_contact ()) +// ack_set (ACK_CONTACT_FRONT); } /** Return the jack and the select_colour at the same time */ @@ -77,12 +79,6 @@ inline uint8_t other_jack_color (void) /** Initialisation of color button (put select color pin in mode 'IN') */ inline void others_init(void) { - /* init DDRA (0 default) */ - - /* DDR = 0 pin in mode IN */ - /* XXXX XXXX & 1111 1101 = XXXX XX0X */ - /* DDRA &= ~_BV(SELECT_COLOR_PIN); */ - /* pull up in mode in */ PORTA |= _BV(SELECT_COLOR_PIN) | _BV(JACK_PIN) | _BV(CONTACT_PIN); } -- cgit v1.2.3