aboutsummaryrefslogtreecommitdiff
path: root/desktop/serial_utils.h
diff options
context:
space:
mode:
author3gg <3gg@shellblade.net>2021-12-04 22:22:47 -0800
committer3gg <3gg@shellblade.net>2021-12-04 22:22:47 -0800
commite62be3b12d3c94d709a77d89f52c31f7c4ac475d (patch)
treebb351f85960443086730f0354f829958b2d03190 /desktop/serial_utils.h
parent48481ba9032689e1bceba05c98bc69972e1a2d3b (diff)
Initial commit.
Diffstat (limited to 'desktop/serial_utils.h')
-rwxr-xr-xdesktop/serial_utils.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/desktop/serial_utils.h b/desktop/serial_utils.h
new file mode 100755
index 0000000..8c351e4
--- /dev/null
+++ b/desktop/serial_utils.h
@@ -0,0 +1,33 @@
1#pragma once
2
3#include "types.h"
4
5#include <SerialStream.h>
6
7template <typename T>
8T read (LibSerial::SerialStream& serial)
9{
10 T x;
11 serial.read((char*) &x, sizeof(T));
12 return x;
13}
14
15template <>
16U32 read<U32> (LibSerial::SerialStream& serial)
17{
18 U32 x = 0;
19 for (int i = 0; i < 4; ++i)
20 {
21 U8 b;
22 serial.read((char*)&b, 1);
23 x = x >> 8;
24 x |= (b << 24);
25 }
26 return x;
27}
28
29template <typename T>
30void write (LibSerial::SerialStream& serial, const T& val)
31{
32 serial.write((const char*) &val, sizeof(T));
33}