Changes in / [7549de9:0c7eb83]
- Location:
- src/daemon
- Files:
-
- 1 deleted
- 1 edited
-
gnuboat (modified) (5 diffs)
-
gnuboat-splashscreen (deleted)
Legend:
- Unmodified
- Added
- Removed
-
src/daemon/gnuboat
r7549de9 r0c7eb83 1 1 #!/usr/bin/python 2 # -*- coding: utf-8 -*-3 2 ''' 4 3 Copyright (C) 2016 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved. … … 23 22 import time 24 23 import threading 25 import re 26 import os 27 import dateutil 28 from EPD import EPD 29 from PIL import Image 30 from PIL import ImageDraw 31 from PIL import ImageFont 24 import os.path 32 25 33 WHITE=1 34 BLACK=0 35 marginVertical = 10 36 marginHorizontal = marginVertical 37 rrdFile = "/home/joachim/public_html/gnuboat/webservice/data/log-webservice.rrd" 38 shutdownFile = "/var/spool/gnuboat/shutdown.request" 26 rrdFile = "/home/jlan11/public_html/gnuboat/webservice/data/log-webservice.rrd" 39 27 logPeriod = 1 40 displayPeriod = 541 42 shutdownRequested = None43 28 44 29 # Copied from https://gist.github.com/wolfg1969/4653340 … … 73 58 pass 74 59 75 def createDatabase(databaseFile) :60 def createDatabase(databaseFile) 76 61 rrdDataSources = [ 'DS:latitude:GAUGE:15:-90:90', 77 62 'DS:longitude:GAUGE:15:-180:180', … … 97 82 rrdArchives) 98 83 99 def displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix):100 # requires dejavu package!!!!101 fontValues = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf', 34)102 fontTitles = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 24)103 104 # initially set all white background105 image = Image.new('1', epd.size, WHITE)106 width, height = image.size107 108 rowHeightTitles = 25109 rowHeightValues = float(height - 2 * rowHeightTitles - 3 * marginVertical) / 2.0110 columnWidthUnit = 30111 columnWidthValues = int(float(width - 3 * marginHorizontal - 2 * columnWidthUnit) / 2.0)112 113 draw = ImageDraw.Draw(image)114 # draw.rectangle((0, 0, width, height), fill=WHITE, outline=WHITE)115 116 x = marginHorizontal117 y = marginVertical118 draw.text((x, y), "STW", fill=BLACK, font=fontTitles)119 draw.text((x, y + rowHeightTitles), str(speedThroughWater), fill=BLACK, font=fontValues)120 draw.text((x + columnWidthValues, y + rowHeightTitles * 1.4), "kts", fill=BLACK, font=fontTitles)121 122 x = x + marginHorizontal + columnWidthValues + columnWidthUnit123 draw.text((x, y), "SOG", fill=BLACK, font=fontTitles)124 draw.text((x, y + rowHeightTitles), str(speedOverGround), fill=BLACK, font=fontValues)125 draw.text((x + columnWidthValues, y + rowHeightTitles * 1.4), "kts", fill=BLACK, font=fontTitles)126 127 x = marginHorizontal128 y = y + rowHeightTitles + rowHeightValues + marginVertical129 draw.text((x, y), "Depth", fill=BLACK, font=fontTitles)130 draw.text((x, y + rowHeightTitles), str(waterDepth), fill=BLACK, font=fontValues)131 draw.text((x + int(float(columnWidthValues) / 1.5), y + rowHeightTitles * 1.4), "m", fill=BLACK, font=fontTitles)132 133 x = x + marginHorizontal + columnWidthValues + columnWidthUnit134 draw.text((x, y), "Water", fill=BLACK, font=fontTitles)135 draw.text((x, y + rowHeightTitles), str(waterTemperature), fill=BLACK, font=fontValues)136 draw.text((x + int(float(columnWidthValues) / 1.5), y + rowHeightTitles * 1.4), "C", fill=BLACK, font=fontTitles)137 138 x = int((x + marginHorizontal + columnWidthValues) * 0.93)139 draw.text((x, y), "Fix", fill=BLACK, font=fontTitles)140 draw.text((x, y + rowHeightTitles), str(gpsFix), fill=BLACK, font=fontValues)141 142 epd.display(image)143 epd.update()144 145 def checkShutdownRequest():146 global shutdownRequest147 # have look for new shutdown requests148 if os.path.isfile(shutdownFile):149 with open(shutdownFile, "r") as fileHandler:150 shutdownStart = fileHandler.read().strip()151 os.remove(shutdownFile)152 shutdownRequested = dateutil.parser.parse(shutdownStart)153 # check existing shutdown requests154 if shutdownRequested is not None:155 if (datetime.now() - shutdownRequested) > timedelta(seconds = 0):156 os.system("sudo shutdown -r now")157 158 84 if __name__ == '__main__': 159 85 createDatabase(rrdFile) 160 161 epd = EPD()162 epd.clear()163 86 164 87 gpsp = GpsdPoller() 165 88 try: 166 89 gpsp.start() 90 print "Collecting data..." 167 91 # gpsp now polls every .2 seconds for new data, storing it in self.current_value 168 92 while True: 169 # In the main thread, every logPeriodseconds print the current value93 # In the main thread, every 5 seconds print the current value 170 94 time.sleep(logPeriod) 171 95 latitude = gpsp.latitude() … … 176 100 waterTemperature = random.randrange(15, 25) + 0.5; 177 101 gpsFix = gpsp.gpsFix() 178 179 # update rrd database for the webservice180 102 rrdtool.update(rrdFile, "N:%s:%s:%s:%s:%s:%s:%s" % (latitude, longitude, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix)) 181 # update display, if needed182 if time.time() % displayPeriod == 0:183 displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix)184 #check for shutdown request185 checkShutdownRequest()186 103 187 104 except (KeyboardInterrupt, SystemExit): #when you press ctrl+c 105 print "\nKilling Thread..." 188 106 gpsp.stop() 189 107 gpsp.join() # wait for the thread to finish what it's doing 108 print "Done.\nExiting."
Note:
See TracChangeset
for help on using the changeset viewer.
