-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPAJ7620U2.cpp
94 lines (77 loc) · 2.25 KB
/
PAJ7620U2.cpp
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
/*
Project : LaLiMat project (https://www.youtube.com/playlist?list=PLJBKmE2nNweRXOebZjydkMEiq2pHtBMOS in Chinese)
file : PAJ7620U2.cpp
Author : ykchau
youtube : youtube.com/ykchau888
Licenese : GPL-3.0
Please let me know if you use it commercial project.
*/
#include "PAJ7620U2.h"
byte PAJ7620::Init(void) {
//Near_normal_mode_V5_6.15mm_121017 for 940nm
int i = 0;
byte data0 = 0, data1 = 0;
//wakeup the sensor
Wire.begin();
Serial.println("INIT SENSOR...");
SelectBank(BANK0);
SelectBank(BANK0);
ReadReg(0, 1, &data0);
ReadReg(1, 1, &data1);
Serial.print("Addr0 =");
Serial.print(data0, HEX);
Serial.print(", Addr1 =");
Serial.println(data1, HEX);
if ((data0 != 0x20) || (data1 != 0x76)) {
return 0xff;
}
if (data0 == 0x20) {
Serial.println("wake-up finish.");
}
for (i = 0; i < INIT_REG_ARRAY_SIZE; i++) {
WriteReg(initRegisterArray[i][0], initRegisterArray[i][1]);
}
SelectBank(BANK0); //gesture flage reg in Bank0
Serial.println("Paj7620 initialize register finished.");
return 0;
}
byte PAJ7620::WriteReg(byte addr, byte cmd) {
char i = 1;
Wire.beginTransmission(PAJ7620_ID); // start transmission to device
//write cmd
Wire.write(addr); // send register address
Wire.write(cmd); // send value to write
i = Wire.endTransmission(); // end transmission
if (0 != i) {
Serial.print("Transmission error!!!\n");
}
return i;
}
byte PAJ7620::ReadReg(byte addr, byte qty, byte data[]) {
byte error;
Wire.beginTransmission(PAJ7620_ID);
Wire.write(addr);
error = Wire.endTransmission();
if (0 != error) {
Serial.print("Transmission error!!!\n");
return error; //return error code
}
Wire.requestFrom((int)PAJ7620_ID, (int)qty);
while (Wire.available()) {
*data = Wire.read();
data++;
}
return 0;
}
void PAJ7620::SelectBank(bank_e bank) {
switch (bank) {
case BANK0:
WriteReg(PAJ7620_REGITER_BANK_SEL, PAJ7620_BANK0);
break;
case BANK1:
WriteReg(PAJ7620_REGITER_BANK_SEL, PAJ7620_BANK1);
break;
default:
break;
}
}