-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.cpp
59 lines (43 loc) · 1.76 KB
/
test.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
/*
This file is part of I2CC.
Copyright (C) 2021 ReimuNotMoe
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include <I2CC.hpp>
using namespace YukiWorkshop;
int main(int argc, char **argv) {
I2CC i2c_dev("/dev/i2c-1", 7, 0x68);
uint8_t buf[10];
i2c_dev.read_data(0x00, buf, 10);
puts("Register dump 0x00 - 0x09:");
for (int i=0; i<10; i++) {
printf("%02x ", buf[i]);
}
puts("");
auto u16be = i2c_dev.read_u16_be(0x00);
auto u16le = i2c_dev.read_u16_le(0x00);
auto s16be = i2c_dev.read_s16_be(0x00);
auto s16le = i2c_dev.read_s16_le(0x00);
auto u32be = i2c_dev.read_u32_be(0x00);
auto u32le = i2c_dev.read_u32_le(0x00);
auto s32be = i2c_dev.read_s32_be(0x00);
auto s32le = i2c_dev.read_s32_le(0x00);
printf("0x00 as u16be: 0x%04x %u\n", u16be, u16be);
printf("0x00 as u16le: 0x%04x %u\n", u16le, u16le);
printf("0x00 as s16be: 0x%04x %d\n", s16be, s16be);
printf("0x00 as s16le: 0x%04x %d\n", s16le, s16le);
printf("0x00 as u32be: 0x%08x %u\n", u32be, u32be);
printf("0x00 as u32le: 0x%08x %u\n", u32le, u32le);
printf("0x00 as s32be: 0x%08x %d\n", s32be, s32be);
printf("0x00 as s32le: 0x%08x %d\n", s32le, s32le);
return 0;
}