summaryrefslogtreecommitdiff
path: root/digital/io/src
diff options
context:
space:
mode:
authorNicolas Schodet2008-04-29 09:42:13 +0200
committerNicolas Schodet2008-04-29 09:42:13 +0200
commit4018bef35759af836dcd87d7d1b7eee7de57dfb2 (patch)
tree5d60b653eb168c17d28287d901fdaf001471ec7f /digital/io/src
parentffe3f998b5d15133e84edac1820459af411a02ba (diff)
* digital/io/src:
- added distance sensors support for simulation. - added preliminary sharps commands.
Diffstat (limited to 'digital/io/src')
-rw-r--r--digital/io/src/main.c22
-rw-r--r--digital/io/src/sharp.h2
-rw-r--r--digital/io/src/simu.host.c15
3 files changed, 38 insertions, 1 deletions
diff --git a/digital/io/src/main.c b/digital/io/src/main.c
index d36043a9..608a0bad 100644
--- a/digital/io/src/main.c
+++ b/digital/io/src/main.c
@@ -45,6 +45,7 @@
#include "top.h" /* top_* */
#include "chrono.h" /* chrono_end_match */
#include "gutter.h" /* gutter_generate_wait_finished_event */
+#include "sharp.h"
#include "io.h"
@@ -69,6 +70,11 @@ enum team_color_e bot_color;
uint8_t main_post_event_for_top_fsm = 0xFF;
/**
+ * Sharps stats counters.
+ */
+uint8_t main_stats_sharps, main_stats_sharps_cpt;
+
+/**
* Initialize the main and all its subsystems.
*/
static void
@@ -218,6 +224,18 @@ main_loop (void)
}
/* TODO: Check other sensors */
}
+
+ /* Send Sharps stats. */
+ if (main_stats_sharps && !--main_stats_sharps_cpt)
+ {
+ main_stats_sharps_cpt = main_stats_sharps;
+ /* XXX: Temporary put here. */
+ sharp_update (0xff);
+ proto_send4w ('H', sharp_get_raw (0),
+ sharp_get_raw (1),
+ sharp_get_raw (2),
+ sharp_get_raw (3));
+ }
}
}
@@ -281,6 +299,10 @@ proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
proto_send1b ('S', switch_get_color () << 1 | switch_get_jack ());
break;
+ case c ('H', 1):
+ main_stats_sharps_cpt = main_stats_sharps = args[0];
+ break;
+
/* EEPROM command */
case c ('e', 1):
/* Save/clear config
diff --git a/digital/io/src/sharp.h b/digital/io/src/sharp.h
index 9f0abd8a..fa6682cb 100644
--- a/digital/io/src/sharp.h
+++ b/digital/io/src/sharp.h
@@ -37,7 +37,7 @@
/**
* Number of sharps.
*/
-#define SHARP_NUMBER 6
+#define SHARP_NUMBER 4
/**
* Front left sharp.
diff --git a/digital/io/src/simu.host.c b/digital/io/src/simu.host.c
index 86029139..03eed76a 100644
--- a/digital/io/src/simu.host.c
+++ b/digital/io/src/simu.host.c
@@ -26,16 +26,19 @@
#include "simu.host.h"
#include "servo.h"
+#include "sharp.h"
#include "modules/utils/utils.h"
#include "modules/host/host.h"
#include "modules/host/mex.h"
+#include "modules/adc/adc.h"
enum
{
MSG_SIMU_IO_JACK = 0xb0,
MSG_SIMU_IO_COLOR = 0xb1,
MSG_SIMU_IO_SERVO = 0xb2,
+ MSG_SIMU_IO_SHARPS = 0xb3,
};
/** Requested servo position. */
@@ -51,6 +54,7 @@ uint8_t servo_high_time_current_[SERVO_NUMBER];
/** Do not update too often, interface is too slow. */
uint8_t simu_servo_update = 10, simu_servo_update_cpt;
uint8_t simu_switch_update = 100, simu_switch_update_cpt;
+uint8_t simu_sharps_update = 100, simu_sharps_update_cpt;
/** Sampled switches. */
uint8_t simu_switches;
@@ -111,6 +115,17 @@ simu_step (void)
if (!r)
simu_switches |= 2;
}
+ /* Update sharps. */
+ if (simu_sharps_update && !--simu_sharps_update_cpt)
+ {
+ simu_sharps_update_cpt = simu_sharps_update;
+ m = mex_msg_new (MSG_SIMU_IO_SHARPS);
+ m = mex_node_request (m);
+ uint8_t i;
+ for (i = 0; i < SHARP_NUMBER; i++)
+ mex_msg_pop (m, "H", &adc_values[i]);
+ mex_msg_delete (m);
+ }
}
void