22 #AutoIt3Wrapper_Icon= Icon.ico
33 #AutoIt3Wrapper_UseX64= n
44 #AutoIt3Wrapper_Res_Description= A simple discrete glucose tooltip for Nightscout under Windows
5- #AutoIt3Wrapper_Res_Fileversion= 2.9.9.8
5+ #AutoIt3Wrapper_Res_Fileversion= 2.9.9.9
66 #AutoIt3Wrapper_Res_LegalCopyright= Mathias Noack
77 #AutoIt3Wrapper_Res_Language= 1031
88 #AutoIt3Wrapper_Run_Tidy= y
3737
3838; Check internet connection on Start/Loop - Return 1 for ON | Return 0 for OFF
3939Func _CheckConnection()
40- Local $isReturn = DllCall (" wininet.dll" , " int" , " InternetGetConnectedState" , " int" , 0 , " int" , 0 )
41- If (@error ) Or ($isReturn [0 ] = 0 ) Then Return SetError (1 , 0 , 0 )
40+ Local $iReturn = DllCall (" wininet.dll" , " int" , " InternetGetConnectedState" , " int" , 0 , " int" , 0 )
41+ If (@error ) Or ($iReturn [0 ] = 0 ) Then Return SetError (1 , 0 , 0 )
4242 Return 1
4343EndFunc
4444
@@ -173,33 +173,35 @@ Func _Tooltip()
173173 If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : Last glucose : " & $iLastGlucose & @CRLF )
174174
175175 ; Check time readings
176- Local $sDate = _ArrayToString(StringRegExp ($sReturnedPageJsonEntries , ' "dateString":"(.{28})"' , 1 ))
177- If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : DateString : " & $sDate & @CRLF )
178-
179- Local $iYear = Int (StringLeft ($sDate , 4 ))
180- Local $iMonth = Int (StringMid ($sDate , 6 , 2 ))
181- Local $iDay = Int (StringMid ($sDate , 9 , 2 ))
182- Local $iHour = Int (StringMid ($sDate , 12 , 2 ))
183- Local $iMin = Int (StringMid ($sDate , 15 , 2 ))
184- Local $iSec = Int (StringMid ($sDate , 18 , 2 ))
185- Local $sLastYearMonthDayHourMinSec = $iYear & " /" & $iMonth & " /" & $iDay & " " & $iHour & " :" & $iMin & " :" & $iSec
186- If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : Last time on server: " & $sLastYearMonthDayHourMinSec & @CRLF )
187- Local $sCurrentYearMonthDayHourMinSec = @YEAR & " /" & @MON & " /" & @MDAY & " " & @HOUR & " :" & @MIN & " :" & @SEC
188- If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : Local time: " & $sCurrentYearMonthDayHourMinSec & @CRLF )
189- Local $bMod = Mod (@SEC , $iSec ) = @SEC
176+ Local $iDate = Int (_ArrayToString(StringRegExp ($sReturnedPageJsonEntries , ' "date":([0-9]{13}),"' , 1 )))
177+ If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : Date : " & $iDate & @CRLF )
178+ Local $sLastDates = _ArrayToString(StringRegExp ($sReturnedPageJsonEntries , ' "date":([0-9]{13}),"' , 3 )) ; Save all array results
179+ If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : Last dates : " & $sLastDates & @CRLF )
180+ Local $iLastDate = Int (StringRegExpReplace ($sLastDates , ' .*\|(.*)' , ' \1' )) ; Save 2nd array result
181+ If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : 2nd date : " & $iLastDate & @CRLF )
182+ Local $iServerTimeEpoch = Int (_ArrayToString(StringRegExp ($sReturnedPageJsonState , ' "serverTimeEpoch":([0-9]{13}),"' , 1 )))
183+ If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : Server time epoch : " & $iServerTimeEpoch & @CRLF )
184+ Local $iMsServerTimeEpochDate = $iServerTimeEpoch - $iDate
185+ If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : Server time epoch date (ms) : " & $iMsServerTimeEpochDate & @CRLF )
186+ Local $iMin = Round ($iMsServerTimeEpochDate / 60000 , 0 )
187+ If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : Minute : " & $iMin & @CRLF )
188+
189+ ; bMod for alarm and speech - modulus operation
190+ Local $bMod = Mod ($iServerTimeEpoch , $iDate )
191+
192+ ; Calculate ms for sleep
193+ Local $iMsWait
194+ If $iMin == 0 Then
195+ $iMsWait = Round (60000 - $iMsServerTimeEpochDate , 0 )
196+ Else
197+ $iMsWait = Round ($iMsServerTimeEpochDate / $iMin , 0 )
198+ EndIf
199+ If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : Sleep : " & $iMsWait & @CRLF )
190200
191201 ; Check Nightscout version
192202 Global $sNightscoutVersion = StringRegExpReplace ($sReturnedPageJsonState , ' .*"version":("|)([^"]+)("|),.*' , ' \2' )
193203 If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : Nightscout version : " & $sNightscoutVersion & @CRLF )
194204
195- ; Reading last glucose (min)
196- Local $iLastReadingGlucoseMin = _DateDiff(' n' , $sLastYearMonthDayHourMinSec , $sCurrentYearMonthDayHourMinSec )
197- If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : Last reading glucose (min) : " & $iLastReadingGlucoseMin & @CRLF )
198-
199- ; Interval for loop interval to read glucose
200- Local $iReadInterval = 60000
201- If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : Read interval (ms) : " & $iReadInterval & @CRLF )
202-
203205 ; Settings check for json: status
204206 Local $sStatus = StringRegExpReplace ($sReturnedPageJsonState , ' .*"status":("|)([^"]+)("|),.*' , ' \2' )
205207 If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : status : " & $sStatus & @CRLF )
@@ -286,9 +288,9 @@ Func _Tooltip()
286288 If $iGlucose < = $iAlertLow Or $iGlucose > = $iAlertHigh Or $iGlucose < = $iAlertLowUrgent Or $iGlucose > = $iAlertHighUrgent Then
287289 $iAlarm = 2 ; =Warning icon
288290 ; Play alarm from windows media folder (tada.wav)
289- If $iCheckboxPlayAlarm = 1 And $bMod = True Then
290- If @MIN = @MIN + $iLastReadingGlucoseMin And $bMod = True Then
291- SoundPlay (@WindowsDir & " \media\tada.wav " , 0 )
291+ If $iCheckboxPlayAlarm = 1 Then
292+ If $iMin == 0 And $bMod = True Then
293+ SoundPlay ($sInputDomain & " /audio/alarm.mp3 " , 0 )
292294 EndIf
293295 EndIf
294296 Else
@@ -307,35 +309,27 @@ Func _Tooltip()
307309 If $iCheckReadOptionValues <> 1 Or $iCheckGlucose <> 1 Or $iCheckInet <> 1 Then
308310 ToolTip ($sWrongMsg , @DesktopWidth - $sInputDesktopWidth , @DesktopHeight - $sInputDesktophHeight , $sWrongMsg , 3 , 2 )
309311 Else
310- ToolTip (" " & $s_fDelta & " " & @CR & " " & $iLastReadingGlucoseMin & " min" , @DesktopWidth - $sInputDesktopWidth , @DesktopHeight - $sInputDesktophHeight , " " & $i_fGlucoseResult & " " & $sTrend & " " , $iAlarm , 2 )
312+ ToolTip (" " & $s_fDelta & " " & @CR & " " & $iMin & " min" , @DesktopWidth - $sInputDesktopWidth , @DesktopHeight - $sInputDesktophHeight , " " & $i_fGlucoseResult & " " & $sTrend & " " , $iAlarm , 2 )
311313 EndIf
312314
313315 ; Check TTS option and locals, globals
314316 Local $oSapi = _SpeechObject_Create()
315317 Local $sGlucoseTextToSpeech = StringReplace ($i_fGlucoseResult , " ." , " ," )
316318 Global $sUpdateWindowTitle = " Nightscout-Update"
317319
318- ; Check double upload method to Nightscout
319- Local $iDate = Int (_ArrayToString(StringRegExp ($sReturnedPageJsonEntries , ' "date":([0-9]{13}),' , 1 ))) ; First array result
320- If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : 1st date : " & $iDate & @CRLF )
321- Local $sLastDates = _ArrayToString(StringRegExp ($sReturnedPageJsonEntries , ' "date":([0-9]{13}),' , 3 )) ; Save all array results
322- If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : Last dates : " & $sLastDates & @CRLF )
323- Local $iLastDate = Int (StringRegExpReplace ($sLastDates , ' .*\|(.*)' , ' \1' )) ; Save 2nd array result
324- If Not @Compiled Then ConsoleWrite (" @@ Debug(" & @ScriptLineNumber & " ) : " & $sLogTime & " : 2nd date : " & $iLastDate & @CRLF )
325-
326320 ; Sleep
327321 If $bMod = True Then
328322 ; Check upload to Nightscout
329- If $iDate = $iLastDate Then
323+ If $iDate == $iLastDate Then
330324 _ExtMsgBox($MB_ICONERROR , $MB_OK , " Error" , " Please use one upload method to Nightscout!" & @CRLF & @CRLF & " Check your application settings, which transmits the values!" & @CRLF & @CRLF & " Otherwise, " & $sTitle & " does not work properly!" )
331325 EndIf
332- If $iCheckboxTextToSpeech = 1 And $bMod = True Then
333- ; Read interval (@MIN + last reading glucose)
334- If @MIN = @MIN + $iLastReadingGlucoseMin Then
326+ If $iCheckboxTextToSpeech = 1 Then
327+ ; Read every zero minutes
328+ If $iMin == 0 And $bMod = True Then
335329 _SpeechObject_Say($oSapi , $sGlucoseTextToSpeech )
336330 EndIf
337331 EndIf
338- Sleep ($iReadInterval )
332+ Sleep ($iMsWait ) ; Sleep with minus of delay
339333 ; Check for a cgm-remote-monitor update when the update window not exists (Important: API update 60 requests per hour!)
340334 If $iCheckboxCgmUpdate = 1 Then
341335 If Not WinExists ($sUpdateWindowTitle ) Then
@@ -401,7 +395,6 @@ Func _Settings()
401395 Local $hCheckboxPlayAlarm = GUICtrlCreateCheckbox ($sIniTitlePlayAlarm , 230 , 60 , 80 , 20 )
402396 GUICtrlSetState ($hCheckboxPlayAlarm , $iCheckboxPlayAlarm )
403397 $hDonate = GUICtrlCreateButton (" Donate" , 230 , 80 , 80 , 40 )
404- ; GUICtrlCreateLabel($sIniTitleGithubAccount, 10, 125, 300)
405398 Local $hCheckboxCgmUpdate = GUICtrlCreateCheckbox ($sIniTitleCgmUpdate , 10 , 120 , 300 , 20 )
406399 GUICtrlSetState ($hCheckboxCgmUpdate , $iCheckboxCgmUpdate )
407400 Local $hInputGithubAccount = GUICtrlCreateInput ($sInputGithubAccount , 10 , 140 , 300 , 20 )
0 commit comments