Closed RengaPD closed 9 years ago
It would be better to make use of the C++ interface...
libxbee::Con
has the operator <<
setup for you:
EXPORT unsigned char operator<< (std::vector<unsigned char> data);
You'd do something like this:
std::string command;
std::vector<unsigned char> data;
// AT command D4 - targeting Digital Pin 4
command = "D4";
std::copy(command.begin(), command.end(), std::back_inserter(data));
// Parameter 0x05, means 'output high'
data.push_back(0x05);
mycon << data
I admit that it's a little unwieldy, but you would wrap this into a function, and call that instead... leaving you with a nice clean interface like this:
mycon << build_io_command(4, OUTPUT_HIGH);
PS: I've had a think about this some more, and my previous example can be significantly simplified...
Something like this would be much better, and I'll add a comment to the sample:
mycon << "D4" + std::string(1, char(0x05))
see ff3b1ba4115952841a6bf3c114336c71255f0a24
hi attie, even if it's quite simple i spent much time first to understand the proper way to do that, so i propose you to add this little comment if i wrote it correctly.