I'm quite new to Arduino, i got my first boards two months ago, and I've mostly tried the basic stuff, like led control, pwm, character displays, steppers and so on. But I've also built a "useless box" and a "spirograph", all with a good portion of help from google.
Anyway I got the idea to make a kind of cash register for the kids, with a barcode reader to scan some empty stuff from the kitchen. Kind of two birds with one stone, making something for the kids, I thought, considering the amount of time my wife claims that I have spent in "my room" the last two months. :o
And everything started out quite well, with a Uno board and a USB shield. I snatched some code from a forum somewhere, and with some tweeking i got it to work with my barcode scanner. It printed the name of the grocery (hard coded in string arrays) on a 4 row character display, together with the price and the sum. All well until my i2c display suddenly died while everything was still under construction.
Somehow a Due and a 3.5" tft touch shield ended up in my mailbox about the same time, and all of a sudden plans where changed. Every cash register needs a touch screen, of course. So I kind of started all over, with a GUI. And the GUI part of it is going quite well, with touch buttons, sums, scrolling and stuff, once again with good help from google and all the info supplied with the GFX and Touchscreen libraries.
But then I connected the barcode scanner, and everything fell apart. Well, at least my plans for the cash register.. It's very hard to find any useful info about the native USB-port on the Arduino Due. Combining that with my very limited C++ knowledge = I'm stuck.
So my hope is that someone here can point me in the right direction, to get the barcode scanner going on the Due. (Yes, if I spend some time educating myself on C++ I might figure it out myself.. maybe, but I'm far too impatient).
The code below is more or less the code I snatched for the barcode scanner, and on a UNO with the USB shield this code prints a string with the barcode to the serial monitor.
#include <usbhid.h>
#include <usbhub.h>
#include <hiduniversal.h>
#include <SPI.h>
USB Usb;
USBHub Hub(&Usb);
HIDUniversal Hid(&Usb);
MyParser Parser;
String code = "";
class MyParser : public HIDReportParser {
public:
MyParser();
void Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf);
};
MyParser::MyParser() {}
void MyParser::Parse(USBHID *hid, bool is_rpt_id, uint8_t len, uint8_t *buf) {
// If error, return
// I don't know why it starts on 2, I just following the example
if (buf[2] == 1) return;
// If empty, return
// I check on 2 because the previous if check on 2 too
if (buf[2] == 0) return;
// Like above, WHY it starts on 2 ?
// What is the purpose of bit in 0 and 1 ?
if(buf[2] == 39) {
code = code + 0;
} else if(buf[2] < 39) {
code = code + (buf[2] - 29);
} else if(buf[2] == 40) {
Serial.println(code);
code = "";
}
}
void setup() {
Serial.begin( 115200 );
Serial.println("Start");
if (Usb.Init() == -1)
Serial.println("OSC did not start.");
delay( 200 );
Hid.SetReportParser(0, &Parser);
}
void loop() {
Usb.Task();
}
The comments in the code aren't mine, and it's obvious that the guy writing the code had some issues with it also. If I've got it right I need to use the USBHost library to get the native USB port going, but because I don't really understand what's going on with the parsing part in the above code, im basically lost. (PS: I used to be a Java guy, so pointers make me dizzy)
Help, anyone...?