return 0;
}
-int Coke_CanDispense(int User, int Item)
+int Coke_CanDispense(int UNUSED(User), int Item)
{
char tmp[40], *status;
regmatch_t matches[4];
// Sanity please
if( Item < 0 || Item > 6 ) return -1; // -EYOURBAD
+ // Can't dispense if the machine is not connected
+ if( giCoke_SerialFD == -1 )
+ return -2;
+
+ // Flush the input buffer
+ {
+ char tmpbuf[512];
+ read(giCoke_SerialFD, tmpbuf, sizeof(tmpbuf));
+ }
+
+ // Wait for a prompt
ret = 0;
do {
write(giCoke_SerialFD, "d7\r\n", 4);
/**
* \brief Actually do a dispense from the coke machine
*/
-int Coke_DoDispense(int User, int Item)
+int Coke_DoDispense(int UNUSED(User), int Item)
{
char tmp[32];
int i, ret;
// Sanity please
if( Item < 0 || Item > 6 ) return -1;
+ // Can't dispense if the machine is not connected
+ if( giCoke_SerialFD == -1 )
+ return -2;
+
+ // Flush the input buffer
+ {
+ char tmpbuf[512];
+ read(giCoke_SerialFD, tmpbuf, sizeof(tmpbuf));
+ }
+
// Wait for prompt
i = 0;
do {