-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLS7366R.cpp
More file actions
executable file
·43 lines (37 loc) · 969 Bytes
/
Copy pathLS7366R.cpp
File metadata and controls
executable file
·43 lines (37 loc) · 969 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include "LS7366R.h"
void LS7366R::begin(const unsigned char* _qei_cs, int _num_of_qei, Resolution _resolution)
{
MDR0_CONF = _resolution;
num_of_qei = _num_of_qei;
qei_cs = new unsigned char[_num_of_qei];
pulse = new long int[_num_of_qei];
memset(pulse, 0, sizeof(long) * _num_of_qei);
memcpy(qei_cs, _qei_cs, _num_of_qei);
for (int i = 0; i < _num_of_qei; i++)
{
pinMode(qei_cs[i], OUTPUT);
digitalWrite(qei_cs[i], HIGH);
}
delay(1000);
// Begin SPI
SPI.begin();
//
for (int i = 0; i < _num_of_qei; i++)
{
init_one_spi_device(qei_cs[i]);
reset_one_spi_device(qei_cs[i]);
}
}
void LS7366R::reset_one_spi_device(const unsigned char& qei_cs)
{
digitalWrite(qei_cs, LOW);
SPI.transfer(CLR | CNTR);
digitalWrite(qei_cs, HIGH);
}
void LS7366R::read()
{
for (int i = 0; i < num_of_qei; i++)
{
pulse[i] = read_one_spi_device(qei_cs[i]);
}
}