}
// Subtract the balance
- reason = mkstr("Dispense - %s:%i %s", handler->Name, Item->ID, Item->Name);
- if( !reason ) reason = Item->Name; // TODO: Should I instead return an error?
- ret = _Transfer( User, Bank_GetAcctByName(COKEBANK_SALES_ACCT), Item->Price, reason);
- free(reason);
- if(ret) return 2; // 2: No balance
+ if( Item->Price )
+ {
+ reason = mkstr("Dispense - %s:%i %s", handler->Name, Item->ID, Item->Name);
+ if( !reason ) reason = Item->Name; // TODO: Should I instead return an error?
+ ret = _Transfer( User, Bank_GetAcctByName(COKEBANK_SALES_ACCT), Item->Price, reason);
+ free(reason);
+ if(ret) return 2; // 2: No balance
+ }
// Get username for debugging
username = Bank_GetAcctName(User);
if(ret) {
Log_Error("Dispense failed after deducting cost (%s dispensing %s - %ic)",
username, Item->Name, Item->Price);
- _Transfer( Bank_GetAcctByName(COKEBANK_SALES_ACCT), User, Item->Price, "rollback" );
+ if( Item->Price )
+ _Transfer( Bank_GetAcctByName(COKEBANK_SALES_ACCT), User, Item->Price, "rollback" );
free( username );
return -1; // 1: Unkown Error again
}
// Admin to -$10
if( flags & USER_FLAG_ADMIN ) return -1000;
- // Coke to -$10
+ // Coke to -$5
if( flags & USER_FLAG_COKE ) return -500;
// Anyone else, non-negative
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 {
// 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;
Door_CanDispense,
Door_DoDispense
};
-//char *gsDoor_SerialPort = "/dev/ttyS0";
+char *gsDoor_Password;
+char *gsDoor_Command;
// int giDoor_SerialFD;
// == CODE ===
-int Door_InitHandler()
+int Door_InitHandler(void)
{
// printf("connecting to door...\n");
// giDoor_SerialFD = open(gsDoor_SerialPort, O_RDWR);
if( !(Bank_GetFlags(User) & USER_FLAG_DOORGROUP) )
return 1;
+
+ gsDoor_Command = malloc(sizeof("llogin door -w ")+strlen(gsDoor_Password));
+ sprintf(gsDoor_Command, "llogin door -w %s", gsDoor_Password);
return 0;
}
*/
int Door_DoDispense(int User, int Item)
{
+ FILE *pipe;
// Sanity please
if( Item != 0 ) return -1;
return 1;
// llogin or other
+ pipe = popen(gsDoor_Command, "w");
+ if( !pipe || pipe == (void*)-1 )
+ return -1;
+
+ fputs("ATH1F", pipe);
+ sleep(1);
+ fputs("ATH10", pipe);
+
+ pclose(pipe);
return 0;
}