#include <aversive.h>
#include <aversive/pgmspace.h>
+#include <aversive/error.h>
#include <ax12.h>
#include <uart.h>
#include "main.h"
#include "strat.h"
#include "strat_base.h"
+#include "strat_avoid.h"
#include "strat_corn.h"
#include "strat_db.h"
#include "strat_utils.h"
8, 9, 6, 7, 3, 4, 5, 0, 1, 2
};
-#if 0 /* XXX maybe useless */
+#ifdef HOST_VERSION
+#define SIDE_CONF 0
+#define CENTER_CONF 0
/* the 10 possible configurations for corn on the side */
static const uint8_t corn_side_confs[9][2] = {
{ 1, 4 },
if (i >= WAYPOINTS_NBX && j >= WAYPOINTS_NBY)
return -1;
*x = (OFFSET_CORN_X + i*STEP_CORN_X);
- *y = COLOR_Y(OFFSET_CORN_Y + j*STEP_CORN_Y);
+ if (i&1)
+ *y = COLOR_Y(OFFSET_CORN_Y + j*STEP_CORN_Y + STEP_CORN_Y/2);
+ else
+ *y = COLOR_Y(OFFSET_CORN_Y + j*STEP_CORN_Y);
+ return 0;
+}
+
+/* return the nearest waypoint (any type) */
+int8_t xycoord_to_ijcoord(int16_t *xp, int16_t *yp, uint8_t *ip, uint8_t *jp)
+{
+ int16_t x, y;
+ uint8_t i, j;
+
+ x = *xp;
+ y = *yp;
+
+ x -= OFFSET_CORN_X;
+ x += (STEP_CORN_X/2);
+ i = x / STEP_CORN_X;
+
+ y = COLOR_Y(y); /* Y depends on color */
+ y -= OFFSET_CORN_Y;
+ y += STEP_CORN_Y/2;
+
+ if ((i & 1) == 1)
+ y -= STEP_CORN_Y/2;
+ j = y / STEP_CORN_Y;
+
+ if (ijcoord_to_xycoord(i, j, &x, &y) < 0)
+ return -1;
+
+ *xp = x;
+ *yp = y;
+ *ip = i;
+ *jp = j;
+
return 0;
}
/* return the nearest waypoint that is not a corn: xp and yp contains
* the input and output, and ip, jp are only outputs. return 0 on
* success. */
-int8_t xycoord_to_ijcoord(int16_t *xp, int16_t *yp, uint8_t *ip, uint8_t *jp)
+int8_t xycoord_to_ijcoord_not_corn(int16_t *xp, int16_t *yp, uint8_t *ip, uint8_t *jp)
{
int16_t x, y;
uint8_t i, j;
x += (STEP_CORN_X/2);
i = x / STEP_CORN_X;
- y = COLOR_Y(y);
+ y = COLOR_Y(y); /* Y depends on color */
y -= OFFSET_CORN_Y;
if ((i & 1) == 1) {
j = y / STEP_CORN_Y;
}
+ else if ((i & 3) == 0) {
+ j = y / (STEP_CORN_Y*2);
+ j = j*2 + 1;
+ }
else {
- y += (STEP_CORN_Y/2);
- y /= (STEP_CORN_Y*2);
- j = (y * 2) + 1;
+ y += (STEP_CORN_Y);
+ j = y / (STEP_CORN_Y*2);
+ j = j*2;
}
if (ijcoord_to_xycoord(i, j, &x, &y) < 0)
return 0;
}
-
/******** CORN */
-/* return the index of a corn given its i,j coords. */
-int8_t ijcoord_to_corn_idx(uint8_t i, uint8_t j)
+static int8_t early_ijcoord_to_corn_idx(uint8_t i, uint8_t j)
{
uint8_t n;
for (n = 0; n < CORN_NB; n ++) {
return -1;
}
+/* return the index of a corn given its i,j coords. */
+int8_t ijcoord_to_corn_idx(uint8_t i, uint8_t j)
+{
+ if (strat_db.wp_table[i][j].type != WP_TYPE_CORN)
+ return -1;
+ return strat_db.wp_table[i][j].corn.idx;
+}
+
/* return the i,j coords of a corn given its index */
int8_t corn_idx_to_ijcoord(uint8_t idx, uint8_t *i, uint8_t *j)
{
/* default type */
wp->type = WP_TYPE_WAYPOINT;
+ /* */
+ wp->time_removed = -1;
+
/* mark dangerous points */
if (i == 0 || i == (WAYPOINTS_NBX-1))
wp->dangerous = 1;
}
/* corn */
- idx = ijcoord_to_corn_idx(i, j);
+ idx = early_ijcoord_to_corn_idx(i, j);
if (idx >= 0) {
wp->type = WP_TYPE_CORN;
wp->present = 1;
wp->corn.idx = idx;
+#ifdef HOST_VERSION
+ if (idx == corn_side_confs[SIDE_CONF][0] ||
+ idx == corn_side_confs[SIDE_CONF][1] ||
+ corn_get_sym_idx(idx) == corn_side_confs[SIDE_CONF][0] ||
+ corn_get_sym_idx(idx) == corn_side_confs[SIDE_CONF][1] ||
+ idx == corn_center_confs[CENTER_CONF][0] ||
+ idx == corn_center_confs[CENTER_CONF][1] ||
+ corn_get_sym_idx(idx) == corn_center_confs[CENTER_CONF][0] ||
+ corn_get_sym_idx(idx) == corn_center_confs[CENTER_CONF][1])
+ wp->corn.color = I2C_COB_BLACK;
+ else
+ wp->corn.color = I2C_COB_WHITE;
+#else
wp->corn.color = I2C_COB_UNKNOWN;
+#endif
continue;
}
/* tomato */
idx = ijcoord_to_tomato_idx(i, j);
if (idx >= 0) {
- printf("%d %d\n", i, j);
wp->type = WP_TYPE_TOMATO;
wp->present = 1;
wp->tomato.idx = idx;
printf_P(PSTR("tomato%d: present=%d opp=%d\r\n"),
i, wp->present, wp->opp_visited);
}
+
+ /* fill circuit infos */
+ strat_avoid_init();
}