ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/truck/DashInterface/Display.cpp
(Generate patch)

Comparing DashInterface/Display.cpp (file contents):
Revision 29 by douglas, 2008-02-27T16:09:18-08:00 vs.
Revision 30 by douglas, 2008-02-28T17:01:10-08:00

# Line 6 | Line 6
6  
7   #include <foreach.hpp>
8  
9 + #include <iomanip>
10   #include <iostream>
11  
12   #include <fcntl.h>
# Line 69 | Line 70 | Display::Packet::Packet(Display::Packet:
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 <        {
88 <                char *data;
89 <
90 <                ::asprintf(&data, "0x%02x %i ", packet.command, packet.length);
91 <
92 <                std::cerr << data << '[' << packet.GetData() << ']' << std::endl;
93 <
94 <                std::free(data);
95 <        }
96 >                std::cerr << _B(">> ") << packet << std::endl;
97   }
98  
99   Display::Display(const std::string &device) : ucom(Posix::Open(device, O_RDWR | O_NOCTTY))
# Line 152 | Line 153 | std::string Display::Version()
153  
154   void Display::Set(uint8_t column, uint8_t row, const std::string &data)
155   {
156 <        Communicate<uint8_t, uint8_t, const std::string &>(Packet::SendDataToLCD, column, row, data);
156 >        Communicate(Packet::SendDataToLCD, column, row, data);
157   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines