summaryrefslogtreecommitdiff
path: root/n/es-2006/src/sensor_eeprom.c
diff options
context:
space:
mode:
Diffstat (limited to 'n/es-2006/src/sensor_eeprom.c')
-rw-r--r--n/es-2006/src/sensor_eeprom.c89
1 files changed, 89 insertions, 0 deletions
diff --git a/n/es-2006/src/sensor_eeprom.c b/n/es-2006/src/sensor_eeprom.c
new file mode 100644
index 0000000..c9bcdc1
--- /dev/null
+++ b/n/es-2006/src/sensor_eeprom.c
@@ -0,0 +1,89 @@
+/* sniff_eeprom.c */
+/* es - Input/Output general purpose board. {{{
+ *
+ * Copyright (C) 2006 Dufour Jérémy
+ *
+ * Robot APB Team/Efrei 2004.
+ * Web: http://assos.efrei.fr/robot/
+ * Email: robot AT efrei DOT fr
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ *
+ * }}} */
+
+#include <avr/eeprom.h>
+
+/* Change the eeprom key each time you change eeprom format. */
+#define EEPROM_KEY 0x45
+#define EEPROM_START 256
+
+/* +AutoDec */
+/* -AutoDec */
+
+/* Read parameters from eeprom. */
+static void
+sensor_eeprom_read_params (void)
+{
+ uint8_t *p8 = (uint8_t *) EEPROM_START;
+ uint16_t *p16;
+ uint8_t sensor, compt, color;
+ if (eeprom_read_byte (p8++) != EEPROM_KEY)
+ return;
+ p16 = (uint16_t *) p8;
+ for (sensor = 0; sensor < RVB_MAX_SENSOR; sensor++)
+ for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
+ sniff_rvb_reference_color[sensor][compt] = eeprom_read_word (p16++);
+ for (color = 0; color < 2; color++)
+ for (sensor = 0; sensor < RVB_MAX_SENSOR; sensor++)
+ for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
+ sniff_rvb_threshold[color][sensor][compt] = eeprom_read_word (p16++);
+ p8 = (uint8_t *) p16;
+ for (color = 0; color < 2; color++)
+ for (sensor = 0; sensor < RVB_MAX_SENSOR; sensor++)
+ for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
+ sniff_rvb_sign[color][sensor][compt] = eeprom_read_byte (p8++);
+}
+
+/* Write parameters to eeprom. */
+static void
+sensor_eeprom_write_params (void)
+{
+ uint8_t *p8 = (uint8_t *) EEPROM_START;
+ uint16_t *p16;
+ uint8_t sensor, compt, color;
+ eeprom_write_byte (p8++, EEPROM_KEY);
+ p16 = (uint16_t *) p8;
+ for (sensor = 0; sensor < RVB_MAX_SENSOR; sensor++)
+ for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
+ eeprom_write_word (p16++, sniff_rvb_reference_color[sensor][compt]);
+ for (color = 0; color < 2; color++)
+ for (sensor = 0; sensor < RVB_MAX_SENSOR; sensor++)
+ for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
+ eeprom_write_word (p16++, sniff_rvb_threshold[color][sensor][compt]);
+ p8 = (uint8_t *) p16;
+ for (color = 0; color < 2; color++)
+ for (sensor = 0; sensor < RVB_MAX_SENSOR; sensor++)
+ for (compt = 0; compt < RVB_SNIFF_MAX_INDEX; compt++)
+ eeprom_write_byte (p8++, sniff_rvb_sign[color][sensor][compt]);
+}
+
+/* Clear eeprom parameters. */
+// static void
+// sensor_eeprom_clear_params (void)
+// {
+// uint8_t *p = (uint8_t *) EEPROM_START;
+// eeprom_write_byte (p, 0xff);
+// }
+