6 |
|
|
7 |
|
#include <foreach.hpp> |
8 |
|
|
9 |
+ |
#include <iomanip> |
10 |
|
#include <iostream> |
11 |
|
|
12 |
|
#include <fcntl.h> |
70 |
|
crc = GetCRC(reinterpret_cast<uint8_t *>(this), length + 2); |
71 |
|
} |
72 |
|
|
73 |
< |
void operator<<(int fd, const Display::Packet::Packet &packet) |
73 |
> |
std::ostream &operator<<(std::ostream &output, const Display::Packet &packet) |
74 |
> |
{ |
75 |
> |
return output << _B("0x") << std::hex << std::setw(2) << std::setfill('0') << unsigned(packet.command) << std::dec << std::setw(0) << std::setfill(' ') << _B(" [") << packet.GetData() << ']'; |
76 |
> |
} |
77 |
> |
|
78 |
> |
void operator<<(int fd, const Display::Packet &packet) |
79 |
|
{ |
80 |
|
if (packet.length != sizeof (packet.data)) |
81 |
|
::memcpy(const_cast<uint8_t *>(packet.data) + packet.length, &packet.crc, 2); |
82 |
|
|
83 |
+ |
if (debug) |
84 |
+ |
std::cerr << _B("<< ") << packet << std::endl; |
85 |
+ |
|
86 |
|
Posix::Write(fd, &packet, packet.length + 4); |
87 |
|
} |
88 |
|
|
89 |
< |
void operator>>(int fd, Display::Packet::Packet &packet) |
89 |
> |
void operator>>(int fd, Display::Packet &packet) |
90 |
|
{ |
91 |
|
Posix::Read(fd, &packet, 2); |
92 |
|
Posix::Read(fd, packet.data, packet.length); |
93 |
|
Posix::Read(fd, &packet.crc, 2); |
94 |
|
|
95 |
|
if (debug) |
96 |
< |
{ |
97 |
< |
char *data; |
89 |
< |
|
90 |
< |
::asprintf(&data, "0x%02x %i ", packet.command, packet.length); |
91 |
< |
|
92 |
< |
std::cerr << data << '[' << packet.GetData() << ']' << std::endl; |
96 |
> |
std::cerr << _B(">> ") << packet << std::endl; |
97 |
> |
} |
98 |
|
|
99 |
< |
std::free(data); |
100 |
< |
} |
99 |
> |
void Communicate(Display *display) |
100 |
> |
{ |
101 |
|
} |
102 |
|
|
103 |
< |
Display::Display(const std::string &device) : ucom(Posix::Open(device, O_RDWR | O_NOCTTY)) |
103 |
> |
Display::Display(const std::string &device) : ucom(Posix::Open(device, O_RDWR | O_NOCTTY)), thread(reinterpret_cast<void *(*)(void *)>(::Communicate)) |
104 |
|
{ |
105 |
|
::termios state; |
106 |
|
|
157 |
|
|
158 |
|
void Display::Set(uint8_t column, uint8_t row, const std::string &data) |
159 |
|
{ |
160 |
< |
Communicate<uint8_t, uint8_t, const std::string &>(Packet::SendDataToLCD, column, row, data); |
160 |
> |
Communicate(Packet::SendDataToLCD, column, row, data); |
161 |
|
} |