-
- #if TRACE_COKE
- printf("Coke_DoDispense: flushing input\n");
- #endif
-
- // Wait for prompt
- ret = 0;
- while( WaitForColon() && ret < 3 )
- {
- // Flush the input buffer
- char tmpbuf[512];
- read(giCoke_SerialFD, tmpbuf, sizeof(tmpbuf));
- #if TRACE_COKE
- printf("Coke_DoDispense: sending 'd7'\n");
- #endif
- write(Item, "d7\r\n", 4);
- }
-
- #if TRACE_COKE
- printf("Coke_DoDispense: sending 'd%i'\n", Item);
- #endif
- // Dispense
- sprintf(tmp, "d%i\r\n", Item);
- write(giCoke_SerialFD, tmp, 4);
-
- // Read empty lines
- while( (ret = ReadLine(sizeof(tmp)-1, tmp)) == -1 );
- if( ret == -1 ) return -1;
- // Read d%i
- while( tmp[0] == ':' ) {
- ret = ReadLine(sizeof(tmp)-1, tmp);
- if( ret == -1 ) return -1;
- }
- // Get status
- ret = ReadLine(sizeof(tmp)-1, tmp);
- if( ret == -1 ) return -1;
-
- WaitForColon(); // Eat up rest of response
-
- #if TRACE_COKE
- printf("Coke_DoDispense: done\n");
- #endif
-
- // 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);