Skip to content
Snippets Groups Projects
Commit c0baa7cd authored by John Hodge's avatar John Hodge
Browse files

coke - Added a delay to coke dispense

parent 43d8a3ef
No related merge requests found
...@@ -53,6 +53,7 @@ char *gsCoke_SerialPort = "/dev/ttyS0"; ...@@ -53,6 +53,7 @@ char *gsCoke_SerialPort = "/dev/ttyS0";
regex_t gCoke_StatusRegex; regex_t gCoke_StatusRegex;
int gaCoke_CachedStatus[7]; int gaCoke_CachedStatus[7];
pthread_mutex_t gCoke_Mutex = PTHREAD_MUTEX_INITIALIZER; pthread_mutex_t gCoke_Mutex = PTHREAD_MUTEX_INITIALIZER;
time_t gtCoke_LastDispenseTime;
// == CODE === // == CODE ===
int Coke_InitHandler() int Coke_InitHandler()
...@@ -199,6 +200,12 @@ int Coke_DoDispense(int UNUSED(User), int Item) ...@@ -199,6 +200,12 @@ int Coke_DoDispense(int UNUSED(User), int Item)
// Can't dispense if the machine is not connected // Can't dispense if the machine is not connected
if( giCoke_SerialFD == -1 ) if( giCoke_SerialFD == -1 )
return -2; return -2;
// Make sure there are not two dispenses within n seconds
if( time(NULL) - gtCoke_LastDispenseTime < 10 )
{
sleep( 10 - time(NULL) - gtCoke_LastDispenseTime );
}
// LOCK // LOCK
pthread_mutex_lock(&gCoke_Mutex); pthread_mutex_lock(&gCoke_Mutex);
...@@ -266,6 +273,8 @@ int Coke_DoDispense(int UNUSED(User), int Item) ...@@ -266,6 +273,8 @@ int Coke_DoDispense(int UNUSED(User), int Item)
char buf[512]; char buf[512];
read(giCoke_SerialFD, buf, 512); // Flush read(giCoke_SerialFD, buf, 512); // Flush
} }
gtCoke_LastDispenseTime = time(NULL);
// Release and return // Release and return
pthread_mutex_unlock(&gCoke_Mutex); pthread_mutex_unlock(&gCoke_Mutex);
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment