git.ucc.asn.au
/
tpg
/
opendispense2.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
coke - Added a delay to coke dispense
[tpg/opendispense2.git]
/
src
/
server
/
handler_coke.c
diff --git
a/src/server/handler_coke.c
b/src/server/handler_coke.c
index
a34d88b
..
8c82a07
100644
(file)
--- a/
src/server/handler_coke.c
+++ b/
src/server/handler_coke.c
@@
-53,6
+53,7
@@
char *gsCoke_SerialPort = "/dev/ttyS0";
regex_t gCoke_StatusRegex;
int gaCoke_CachedStatus[7];
pthread_mutex_t gCoke_Mutex = PTHREAD_MUTEX_INITIALIZER;
regex_t gCoke_StatusRegex;
int gaCoke_CachedStatus[7];
pthread_mutex_t gCoke_Mutex = PTHREAD_MUTEX_INITIALIZER;
+time_t gtCoke_LastDispenseTime;
// == CODE ===
int Coke_InitHandler()
// == CODE ===
int Coke_InitHandler()
@@
-199,6
+200,12
@@
int Coke_DoDispense(int UNUSED(User), int Item)
// Can't dispense if the machine is not connected
if( giCoke_SerialFD == -1 )
return -2;
// Can't dispense if the machine is not connected
if( giCoke_SerialFD == -1 )
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
pthread_mutex_lock(&gCoke_Mutex);
// LOCK
pthread_mutex_lock(&gCoke_Mutex);
@@
-206,11
+213,6
@@
int Coke_DoDispense(int UNUSED(User), int Item)
TRACE("flushing input\n");
TRACE("flushing input\n");
- {
- char buf[512];
- while( ReadLine(512, buf) != -1 );
- }
-
// Wait for prompt
ret = 0;
while( WaitForColon() && ret < 3 )
// Wait for prompt
ret = 0;
while( WaitForColon() && ret < 3 )
@@
-262,6
+264,7
@@
int Coke_DoDispense(int UNUSED(User), int Item)
TRACE("Updating slot status\n");
// Update status
TRACE("Updating slot status\n");
// Update status
+ WaitForColon();
Writef("s%i\r\n", Item);
len = ReadLine(sizeof tmp, tmp);
if(len == -1) gaCoke_CachedStatus[Item] = -1;
Writef("s%i\r\n", Item);
len = ReadLine(sizeof tmp, tmp);
if(len == -1) gaCoke_CachedStatus[Item] = -1;
@@
-270,6
+273,8
@@
int Coke_DoDispense(int UNUSED(User), int Item)
char buf[512];
read(giCoke_SerialFD, buf, 512); // Flush
}
char buf[512];
read(giCoke_SerialFD, buf, 512); // Flush
}
+
+ gtCoke_LastDispenseTime = time(NULL);
// Release and return
pthread_mutex_unlock(&gCoke_Mutex);
// Release and return
pthread_mutex_unlock(&gCoke_Mutex);
UCC
git Repository :: git.ucc.asn.au