Project

General

Profile

Statistics
| Revision:

root / branches / ir_branch / code / tools / eeprom / program_eeprom.c @ 1572

History | View | Annotate | Download (1.98 KB)

1
#include <dragonfly_lib.h>
2
#include <stdlib.h>
3
#include <eeprom.h>
4

    
5
int main()
6
{
7
  char str[5];
8
  int i=0,id,ir_offset;
9
  char c;
10

    
11
  dragonfly_init(ALL_ON);
12

    
13
  usb_puts("Here is the current setup:\r\n  ID: ");
14
  itoa(get_robotid(), str, 10);
15
  usb_puts(str);
16
  
17
  usb_puts("\r\n  BOM type: ");
18
  itoa(get_bom_type(), str, 10);
19
  usb_puts(str);
20
  
21
  usb_puts("\r\n  IR Offset: ");
22
  itoa(get_ir_offset(), str, 10);
23
  usb_puts(str);
24
  
25
  
26
  usb_puts("\r\n\r\nEnter new ID:");
27

    
28
  while((c = usb_getc()) != '\n' && c != '\r')
29
    {
30
      usb_putc(c);
31
      if(i>=4)
32
        {
33
          usb_puts("ERROR: filled buffer\n");
34
          while(1);
35
        }
36
      str[i++] = c;
37
    }
38
  while(i<5)
39
    str[i++] = 0;
40

    
41
  id = atoi(str);
42

    
43
  usb_puts("\r\nsetting new id to: ");
44
  usb_puti(id);
45

    
46

    
47
  eeprom_put_byte(EEPROM_ROBOT_ID_ADDR, 'I');
48
  eeprom_put_byte(EEPROM_ROBOT_ID_ADDR+1, 'D');
49
  eeprom_put_byte(EEPROM_ROBOT_ID_ADDR+2, id);
50

    
51

    
52
  usb_puts("\r\nEnter BOM type:\r\b"
53
           "1 for BOM 1.0\r\n"
54
           "5 for BOM 1.5\r\n"
55
           "r for RBOM\r\n>");
56

    
57
  c = usb_getc();
58
  usb_putc(c);
59

    
60
  switch(c)
61
    {
62
    case '1': id = BOM10; break;
63
    case '5': id = BOM15; break;
64
    case 'r': id = RBOM; break;
65
    default:
66
      usb_puts("ERROR: invalid input");
67
      while(1);
68
    }
69

    
70
  eeprom_put_byte(EEPROM_BOM_TYPE_ADDR, 'B');
71
  eeprom_put_byte(EEPROM_BOM_TYPE_ADDR+1, 'O');
72
  eeprom_put_byte(EEPROM_BOM_TYPE_ADDR+2, 'M');
73
  eeprom_put_byte(EEPROM_BOM_TYPE_ADDR+3, id);
74

    
75
  usb_puts("\r\n\r\nEnter new IR Offset:");
76
  i = 0;
77
  while((c = usb_getc()) != '\n' && c != '\r')
78
    {
79
      usb_putc(c);
80
      if(i>=4)
81
      {
82
        usb_puts("ERROR: filled buffer\n");
83
        while(1);
84
      }
85
      str[i++] = c;
86
    }
87
  while(i<5)
88
    str[i++] = 0;
89

    
90
  ir_offset = atoi(str);
91

    
92
  usb_puts("\r\nsetting new IR_offset to: ");
93
  usb_puti(ir_offset);
94
  
95
  eeprom_put_byte(EEPROM_IR_OFFSET_ADDR, 'I');
96
  eeprom_put_byte(EEPROM_IR_OFFSET_ADDR+1, 'R');
97
  eeprom_put_byte(EEPROM_IR_OFFSET_ADDR+2, ir_offset);
98

    
99
  usb_puts("\r\ndone! have a nice day\r\n");
100

    
101

    
102
  while(1);
103

    
104
  return 0;
105
}
106