Project

General

Profile

Statistics
| Branch: | Revision:

scoutece / forklift / code / forklift.c @ a52b0259

History | View | Annotate | Download (1.22 KB)

1
/*
2
 * ARM -> us
3
 * -height setpoint
4
 *
5
 * us -> ARM
6
 * -tracking ID (same for all forklifts)
7
 * -serial number (unique to each forklift)
8
 * -current height
9
 * -current height setpoint
10
 * -payload weight
11
 *
12
 */
13
 
14
#include "twi.h"
15

    
16
#define TRACKING_ID 0x41
17
#define SERIAL_NUMBER 0x12
18

    
19
// indicies for forklift internal data
20
#define FORKLIFT_TRACKING_ID     0
21
#define FORKLIFT_SERIAL_NUMBER   1
22
#define FORKLIFT_HEIGHT          2
23
#define FORKLIFT_HEIGHT_SETPOINT 3 // only one that's r/w
24
#define FORKLIFT_FORCE           4
25

    
26
#define FORKLIFT_DATA_LEN        5
27

    
28
uint8_t internal_index = 0;
29
uint8_t internal_data[] = {
30
  TRACKING_ID,
31
  SERIAL_NUMBER,
32
  0,
33
  0,
34
  0
35
};
36

    
37
void slave_rx(uint8_t* data, int len)
38
{
39
  if (len > 0 && data[0] < FORKLIFT_DATA_LEN)
40
  {
41
    internal_index = data[0];
42
    if (len > 1 && internal_index == FORKLIFT_HEIGHT_SETPOINT)
43
      internal_data[internal_index] = data[1];
44
  }
45
}
46

    
47
void slave_tx(void)
48
{
49
  twi_transmit(&internal_data[internal_index], 1);
50
  internal_index++;
51
  if (internal_index >= FORKLIFT_DATA_LEN)
52
    internal_index = 0;
53
}
54

    
55
int main()
56
{
57
  twi_init();
58
  twi_setAddress(TRACKING_ID);
59
  twi_attachSlaveRxEvent(slave_rx);
60
  twi_attachSlaveTxEvent(slave_tx);
61
  while (1)
62
  {
63
    // do motor stuff
64
  }
65
  return 0;
66
}