summaryrefslogtreecommitdiff
path: root/n/es-2006/src/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'n/es-2006/src/main.c')
-rw-r--r--n/es-2006/src/main.c128
1 files changed, 110 insertions, 18 deletions
diff --git a/n/es-2006/src/main.c b/n/es-2006/src/main.c
index ecc80f0..8320bfd 100644
--- a/n/es-2006/src/main.c
+++ b/n/es-2006/src/main.c
@@ -35,9 +35,10 @@
#include "sniff_rvb.h" /* RVB sensors analysis */
#include "timer_1.h" /* timer/counter 1 */
#include "others.h" /* define game color mode + jack + frontal sensor */
+#include "servo_motor.h"/* Servo motor module */
+#include "sharp.h" /* SHarps module */
+#include "lcd.h" /* Communication with the LCD card */
#include "barillet.h"
-#include "servo_motor.h"
-
/* Statistics for RVB sensors */
uint8_t sensor_rvb_stat_enable[RVB_MAX_SENSOR], sensor_rvb_stats[RVB_MAX_SENSOR];
@@ -47,6 +48,23 @@ uint8_t sniff_rvb_stat_enable[RVB_MAX_SENSOR], sniff_rvb_stats[RVB_MAX_SENSOR];
/* Statistics for RVB ball sensors. */
uint8_t sniff_ball_stat_enable[2], sniff_ball_stats[2];
+/* Config and statistics for SHarps */
+uint8_t sharp_stat_enable[SHARP_NUMBER], sharp_stat_freq[SHARP_NUMBER];
+uint8_t sharp_enable[SHARP_NUMBER], sharp_enable_freq[SHARP_NUMBER];
+
+/* Stats for colour selection and jack */
+uint8_t others_jackcolor_stat_enable, others_jackcolor_stats;
+
+/* XXX Debug stats */
+uint8_t main_stats[4];
+uint8_t main_stats_freq, main_stats_enable;
+
+/* Twi */
+uint8_t twi_buffer_read;
+
+/* Keyboard LCD update frequency */
+uint8_t lcd_key_enable, lcd_key_freq;
+
/** Call when we receive some data from proto (uart) */
void
proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
@@ -64,6 +82,10 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
utils_reset ();
break;
+ case c ('Z', 1):
+ main_stats_freq = main_stats_enable = args[0];
+ break;
+
/*** RVB ***/
/* RVB sensors configuration */
case c ('p', 3):
@@ -119,11 +141,42 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
case c ('k', 0 ):
proto_send1b ('k', others_selectcoul());
break;
+ /* Selection color & jack */
+ case c ('q', 1):
+ others_jackcolor_stat_enable = others_jackcolor_stats = args[0];
+ break;
+
/* Communication with the servo motor */
case c ('m', 2):
servo_motor_set_pos (args[0], args[1]);
break;
+ /* SHarps */
+ /* Update frequency */
+ case c ('h', 2):
+ for (compt = 0; compt < SHARP_NUMBER; compt++)
+ if (args[0] & _BV(compt))
+ sharp_enable[compt] = sharp_enable_freq[compt] = args[1];
+ break;
+ /* Stats frequency */
+ case c ('H', 2):
+ for (compt = 0; compt < SHARP_NUMBER; compt++)
+ if (args[0] & _BV(compt))
+ sharp_stat_enable[compt] = sharp_stat_freq[compt] = args[1];
+ break;
+
+ /* LCD */
+ case c ('L', 32):
+ lcd_print (args, 32);
+ break;
+ case c ('l', 1):
+ lcd_key_freq = lcd_key_enable = args[0];
+ break;
+
+ /* Grub ! */
+ case c ('G', 0):
+ lcd_grub_booting ();
+ break;
/* tests primaires pour le barillet */
case c('v',3):
@@ -175,7 +228,6 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
int
main (void)
{
- uint8_t init_rvb = 200;
uint8_t compt;
/* Serial port */
@@ -183,7 +235,7 @@ main (void)
/* Main timer init */
timer_main_init ();
/* Init timer/counter 1 for RVB & PWM
- * /!\ Must be called before RVB/PWM init ! */
+ * /!\ Must be called before RVB/PWM init /!\ */
timer1_init ();
/* Init RVB sensors system */
sensor_rvb_init ();
@@ -193,6 +245,11 @@ main (void)
barillet_init();
/* Servo motor init */
servo_motor_init ();
+ /* Sharp init */
+ sharp_init ();
+ /* LCD init */
+ lcd_init ();
+
/* Enable interrupts */
sei ();
@@ -206,8 +263,18 @@ main (void)
// possible.
timer_main_wait ();
+ if (main_stats_enable && !--main_stats_freq)
+ {
+ main_stats_freq = main_stats_enable;
+ proto_send4b ('Z', main_stats[0], main_stats[1], main_stats[2],
+ main_stats[3]);
+ }
+
+ main_stats[0] = TCNT0;
+
/* RVB Sensors stats */
for (compt = 0; compt < RVB_MAX_SENSOR; compt++)
+ {
if (sensor_rvb_stat_enable[compt] && !--sensor_rvb_stats[compt])
{
/* Re init stats system for this sensor */
@@ -218,15 +285,14 @@ main (void)
sensor_rvb_values[compt][2],
sensor_rvb_values[compt][3]);
}
-
- /* RVB Sensors analysis stats */
- for (compt = 0; compt < RVB_MAX_SENSOR; compt++)
+ /* RVB Sensors analysis stats */
if (sniff_rvb_stat_enable[compt] && !--sniff_rvb_stats[compt])
{
/* Re init stats system for this sensor */
sniff_rvb_stats[compt] = sniff_rvb_stat_enable[compt];
proto_send2b ('A', compt, sniff_rvb_analysis_color (compt, RVB_SNIFF_ALL_COLORS));
}
+ }
/* Print stats for ball */
for (compt = 0; compt < 2; compt++)
@@ -237,26 +303,49 @@ main (void)
proto_send2b ('B', compt, sniff_rvb_analysis_ball (compt + 7));
}
+ main_stats[1] = TCNT0;
+
/* Update all the asserv pin comunication */
sensor_rvb_update_asserv_pins ();
- // FIXME, if we can put some of this values into the eeprom, it will
- // be better...
- if (init_rvb > 0)
+ if (others_jackcolor_stat_enable && !--others_jackcolor_stats)
{
- init_rvb--;
- if ((init_rvb == 1) || (init_rvb == 2))
- {
- sniff_rvb_set_ref_color (0, 0);
- sniff_rvb_set_ref_color (1, 0);
- sniff_rvb_set_ref_color (2, 0);
- sniff_rvb_set_ref_color (3, 0);
- }
+ others_jackcolor_stats = others_jackcolor_stat_enable;
+ proto_send1b ('q', other_jack_color ());
+ }
+ /* LCD */
+ if (lcd_key_enable && !--lcd_key_freq)
+ {
+ lcd_key_freq = lcd_key_enable;
+ if ((twi_buffer_read = lcd_key ()))
+ proto_send1b ('l', twi_buffer_read);
}
/* gestion du barilet */
sequenceur_barillet ();
+ /* Sharps */
+ for (compt = 0; compt < SHARP_NUMBER; compt++)
+ {
+ /* Update */
+ if (sharp_enable[compt] && !--sharp_enable_freq[compt])
+ {
+ /* Re init update system for this sharp */
+ sharp_enable_freq[compt] = sharp_enable[compt];
+ sharp_update_values (compt);
+ }
+ /* Stats */
+ if (sharp_stat_enable[compt] && !--sharp_stat_freq[compt])
+ {
+ /* Re init stats system for this sharp */
+ sharp_stat_freq[compt] = sharp_stat_enable[compt];
+ /* XXX 16 bits sucks */
+ proto_send2w ('H', compt, sharp_values[compt]);
+ }
+ }
+
+ main_stats[2] = TCNT0;
+
/* Get data for serial port */
while (uart0_poll ())
proto_accept (uart0_getc ());
@@ -265,5 +354,8 @@ main (void)
* I want this to be done as later as possible, and espceically after
* commands has been parsed ! */
sensor_rvb_start_capture ();
+
+ main_stats[3] = TCNT0;
}
}
+