+ // TODO: Regex
+ if( strcmp(tmp, "ok") == 0 ) {
+ // We think dispense worked
+ // - The machine returns 'ok' if an empty slot is dispensed, even if
+ // it doesn't actually try to dispense (no sound)
+ return 0;
+ }
+
+ printf("Machine returned unknown value '%s'\n", tmp);
+
+ return -1;
+}
+
+char ReadChar()
+{
+ fd_set readfs;
+ char ch = 0;
+ int ret;
+ struct timeval timeout;
+
+ timeout.tv_sec = READ_TIMEOUT;
+ timeout.tv_usec = 0;
+
+ FD_ZERO(&readfs);
+ FD_SET(giCoke_SerialFD, &readfs);
+
+ ret = select(giCoke_SerialFD+1, &readfs, NULL, NULL, &timeout);
+ if( ret == 0 ) return 0; // Timeout
+ if( ret != 1 ) {
+ printf("readchar return %i\n", ret);
+ return 0;
+ }
+
+ ret = read(giCoke_SerialFD, &ch, 1);
+ if( ret != 1 ) {
+ printf("ret = %i\n", ret);
+ return 0;
+ }
+
+ return ch;
+}