Statistics
| Branch: | Revision:

scoutece / paintboard / code / main.c @ 4319e0bc

History | View | Annotate | Download (1.94 KB)

1
#include "twi.h"
2
#include "motor.h"
3
#include <avr/io.h>
4
#include <avr/interrupt.h>
5

    
6
#define TRACKING_ID 0x43
7
#define SERIAL_NUMBER 0x12
8

    
9
// indicies for paintboard internal data
10
#define PAINT_TRACKING_ID       0 // ro
11
#define PAINT_SERIAL_NUMBER     1 // ro
12
#define PAINT_MOTOR_A           2 // r/w
13
#define PAINT_MOTOR_B           3 // r/w
14
#define PAINT_SERVO_A           4 // r/w
15
#define PAINT_SERVO_B           5 // r/w
16
#define PAINT_12V_1             6 // r/w
17
#define PAINT_12V_2             7 // r/w
18
#define PAINT_12V_3             8 // r/w
19
#define PAINT_12V_4             9 // r/w
20

    
21
#define PAINT_DATA_LEN         10
22

    
23
uint8_t internal_index = 0;
24
uint8_t internal_data[PAINT_DATA_LEN] = {
25
  TRACKING_ID,
26
  SERIAL_NUMBER,
27
  0,
28
  0,
29
  0,
30
  0,
31
  0,
32
  0,
33
  0,
34
  0
35
};
36

    
37
void slave_rx(uint8_t* data, int len)
38
{
39
  uint8_t value;
40
  if (len > 0 && data[0] < PAINT_DATA_LEN)
41
  {
42
    internal_index = data[0];
43
    if (len > 1 && internal_index > 1)
44
    {
45
      value = data[1];
46
      internal_data[internal_index] = value;
47
      switch (internal_index) {
48
        case PAINT_MOTOR_A:
49
          /* ...TODO... */
50
          break;
51
        case PAINT_MOTOR_B:
52
          /* ...TODO... */
53
          break;
54
        case PAINT_SERVO_A:
55
          /* ...TODO... */
56
          break;
57
        case PAINT_SERVO_B:
58
          /* ...TODO... */
59
          break;
60
        case PAINT_12V_1:
61
          /* ...TODO... */
62
          break;
63
        case PAINT_12V_2:
64
          /* ...TODO... */
65
          break;
66
        case PAINT_12V_3:
67
          /* ...TODO... */
68
          break;
69
        case PAINT_12V_4:
70
          /* ...TODO... */
71
          break;
72
      }
73
    }
74
  }
75
}
76

    
77
void slave_tx(void)
78
{
79
  twi_transmit(&internal_data[internal_index], 1);
80
  internal_index++;
81
  if (internal_index >= PAINT_DATA_LEN)
82
    internal_index = 0;
83
}
84

    
85
int main()
86
{
87
  sei();
88
  twi_attachSlaveRxEvent(slave_rx);
89
  twi_attachSlaveTxEvent(slave_tx);
90
  twi_setAddress(TRACKING_ID);
91
  twi_init();
92
  motor_init();
93
  while (1)
94
  {
95
  }
96
  return 0;
97
}