' Quakes32 V1.0 ' AndyGadget - 2021 wlog can.stop ' Kill CanBus as not required OPTION.NTPSYNC ' Sync to internet time (Mage sure Timezone is correct on Config screen TFT.INIT 1 ' May need TFT.INIT 3, depending on screen orientation. ' Various variable definitions. FName$ = "/history.txt" OldRef$ = "" dim Hist(100,3) PLat = 0 : PLon = 0 : PMag = 0 EOL$ = chr$(10) tft.text.align 4 TFT.TEXT.COL Yellow TFT.TEXT.FONT 4 ' Display bare map on screen. TFT.JPG "/map-l.jpg" if file.exists(FName$) = 1 then ' Read event history from file into array. for FCnt = 1 to 100 FLine$ = file.read$(FName$,FCnt) Hist(FCnt,0) = val(word$(FLine$,1,"|")) Hist(FCnt,1) = val(word$(FLine$,2,"|")) Hist(FCnt,2) = val(word$(FLine$,3,"|")) next FCnt end if ONWGETASYNC MsgReceived gosub QueryServer timer0 500, Blink timer1 30000, QueryServer wait QueryServer: ' Request data from SeismicPortal API - No key needed. ' JSON is an option but chose simple delimited text string output. ' Requesting only most recent event. ' Green dot in top centre of screen - Clears when data received. TFT.CIRCLE 224, 10, 3,green,1 wgetasync("seismicportal.eu/fdsnws/event/1/query?limit=1&format=text",443,0,1) return MsgReceived: 'Option.WDTReset TFT.CIRCLE 224, 10, 3,&H3475,1 Line$ = WORD$( WGETRESULT$, 2, chr$(10)) Ref$ = word$(Line$,1,"|") ' Only process result if it is a new event. if (Ref$ <> OldRef$) and (val(Ref$) <> 0) then wlog line$ OldRef$ = Ref$ TD$ = word$(Line$,2,"|") EDate$ = left$(TD$,10) ETime$ = left$(time$,5) EMag$ = word$(Line$,11,"|") ELoc$ = word$(Line$,13,"|") Lat = val(word$(Line$,3,"|")) Lon = val(word$(Line$,4,"|")) ' Load map to clear display, then print text info about event. TFT.JPG "/map-l.jpg" tft.text.draw string$(96," "),240,30 tft.text.draw EMag$,40,30 tft.text.draw ETime$,420,30 tft.text.draw ELoc$, 240,300 ' Shift array. For Cnt = 0 to 99 Hist(Cnt,0) = Hist(Cnt+1,0) Hist(Cnt,1) = Hist(Cnt+1,1) Hist(Cnt,2) = Hist(Cnt+1,2) next Cnt ' Convert longitude and latitude of event to screen co-ordinates. ' Size of plotted circle is proportional to quake magnitude. PLon = (225 + (1.34 * Lon)) mod 480 Plat = 225 - (1.47*((0.74 * Lat) + (Lat * 0.0474)^3)) PMag = cint(val(EMag$) * 1) + 1 if PMag <= 1 then PMag = 1 ' Write new event to array. Hist(100,0) = PLon Hist(100,1) = PLat Hist(100,2) = PMag ' Plot event history from array. for HCnt = 0 to 100 RedVal = 155 + HCnt GrnVal = 55 + (HCnt * 2) BluVal = 0 ' Colour of plotted point fades from bright yellow through orange to dull red with age. TFT.CIRCLE Hist(HCnt,0),Hist(HCnt,1),Hist(HCnt,2),TFT.RGB(RedVal,GrnVal,BluVal),1 next HCnt ' Plot most recent event. TFT.CIRCLE PLon,Plat,PMag,&HF800,1 ' Store array to file. TFT.CIRCLE 224, 10, 3,red,1 x = file.delete(FName$) for FCnt = 1 to 100 FLine$ = str$(Hist(FCnt,0)) + "|" + str$(Hist(FCnt,1)) + "|" + str$(Hist(FCnt,2)) + EOL$ file.append FName$,FLine$ next FCnt TFT.CIRCLE 224, 10, 3,&H3475,1 endif return Blink: ' Flashing red / yellow dot to mark most recent event. Flsh = (Flsh + 1) mod 2 if Flsh = 0 then TFT.CIRCLE PLon,PLat,PMag,Yellow,1 else TFT.CIRCLE PLon,PLat,PMag,Red,1 endif return