-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_wait.cpp
46 lines (38 loc) · 1.3 KB
/
main_wait.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
// ==========================================================================
//
// File : wiwire.cpp
// Part of : C++ libary WiWire, used for wireless transmission
// Copyright : [email protected] 2019
//
// Distributed under the GNU GENERAL PUBLIC LICENSE, version 3
// (See accompanying file LICENSE file, or look at https://fsf.org/
//
// ==========================================================================
#include "wiwire.hpp"
// Example code for testing and demo purposes
// this code recieves a hello world message at adress 0x0F. When it recieves an
// valid message it will send an ack. The recieved message including its size
// will be printed to the serial port.
int main() {
namespace target = hwlib::target;
auto tx = target::pin_out(target::pins::d50);
auto rx = target::pin_in(target::pins::d51);
auto led = target::pin_out(target::pins::d40);
hwlib::wait_ms(1000);
wiwire wire(tx, rx, 0x0C);
hwlib::cout << "init"
<< "\n";
while (true) {
char msg[256] = {};
char sizeMsg = wire.blockRead(msg);
hwlib::cout << "sizeMsg: " << (int)sizeMsg << '\n';
for (int i = 0; i < sizeMsg; i++) {
hwlib::cout << msg[i];
}
hwlib::cout << "\n";
led.write(1); led.flush();
hwlib::wait_ms(1000);
led.write(0); led.flush();
}
return 0;
}