Changes in / [501b629:f0d4b56]
- Location:
- src/daemon
- Files:
-
- 1 deleted
- 1 edited
-
gnuboat (modified) (7 diffs)
-
gnuboat.service (deleted)
Legend:
- Unmodified
- Added
- Removed
-
src/daemon/gnuboat
r501b629 rf0d4b56 53 53 54 54 shutdownRequested = None 55 latitude = None56 longitude = None57 speedThroughWater = None58 speedOverGround = None59 waterDepth = None60 waterTemperature = None61 gpsFix = None62 55 63 56 # Copied from https://gist.github.com/wolfg1969/4653340 … … 93 86 pass 94 87 95 """@class DisplayHandler96 """97 class DisplayHandler(threading.Thread):98 def __init__(self, displayperiod):99 threading.Thread.__init__(self)100 self._epd = EPD()101 self._epd.clear()102 self._updatePeriod = displayperiod103 self._running = True104 105 def stop(self):106 self._running = False107 108 def run(self):109 global latitude110 global longitude111 global speedThroughWater112 global speedOverGround113 global waterDepth114 global waterTemperature115 global gpsFix116 117 try:118 while self._running:119 self.displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix)120 time.sleep(self._updatePeriod)121 except StopIteration:122 pass123 124 def displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix):125 if not epdEnabled:126 return127 128 # requires dejavu package!!!!129 fontValues = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf', 34)130 fontTitles = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 24)131 132 # initially set all white background133 image = Image.new('1', epd.size, WHITE)134 width, height = image.size135 136 rowHeightTitles = 25137 rowHeightValues = float(height - 2 * rowHeightTitles - 3 * marginVertical) / 2.0138 columnWidthUnit = 30139 columnWidthValues = int(float(width - 3 * marginHorizontal - 2 * columnWidthUnit) / 2.0)140 141 draw = ImageDraw.Draw(image)142 # draw.rectangle((0, 0, width, height), fill=WHITE, outline=WHITE)143 144 x = marginHorizontal145 y = marginVertical146 draw.text((x, y), "STW", fill=BLACK, font=fontTitles)147 if speedThroughWater is not None:148 draw.text((x, y + rowHeightTitles), str(speedThroughWater), fill=BLACK, font=fontValues)149 draw.text((x + columnWidthValues, y + rowHeightTitles * 1.4), "kts", fill=BLACK, font=fontTitles)150 151 x = x + marginHorizontal + columnWidthValues + columnWidthUnit152 draw.text((x, y), "SOG", fill=BLACK, font=fontTitles)153 if speedOverGround is not None:154 draw.text((x, y + rowHeightTitles), str(speedOverGround), fill=BLACK, font=fontValues)155 draw.text((x + columnWidthValues, y + rowHeightTitles * 1.4), "kts", fill=BLACK, font=fontTitles)156 157 x = marginHorizontal158 y = y + rowHeightTitles + rowHeightValues + marginVertical159 draw.text((x, y), "Depth", fill=BLACK, font=fontTitles)160 if waterDepth is not None:161 draw.text((x, y + rowHeightTitles), str(waterDepth), fill=BLACK, font=fontValues)162 draw.text((x + int(float(columnWidthValues) / 1.5), y + rowHeightTitles * 1.4), "m", fill=BLACK, font=fontTitles)163 164 x = x + marginHorizontal + columnWidthValues + columnWidthUnit165 draw.text((x, y), "Water", fill=BLACK, font=fontTitles)166 if waterTemperature is not None:167 draw.text((x, y + rowHeightTitles), str(waterTemperature), fill=BLACK, font=fontValues)168 draw.text((x + int(float(columnWidthValues) / 1.5), y + rowHeightTitles * 1.4), "C", fill=BLACK, font=fontTitles)169 170 x = int((x + marginHorizontal + columnWidthValues) * 0.93)171 draw.text((x, y), "Fix", fill=BLACK, font=fontTitles)172 if gpsFix is not None:173 draw.text((x, y + rowHeightTitles), str(gpsFix), fill=BLACK, font=fontValues)174 175 epd.display(image)176 epd.update()177 178 88 def createDatabase(databaseFile): 179 89 rrdDataSources = [ 'DS:latitude:GAUGE:15:-90:90', … … 199 109 rrdDataSources, 200 110 rrdArchives) 111 112 def displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix): 113 if not epdEnabled: 114 return 115 116 # requires dejavu package!!!! 117 fontValues = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans-Bold.ttf', 34) 118 fontTitles = ImageFont.truetype('/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf', 24) 119 120 # initially set all white background 121 image = Image.new('1', epd.size, WHITE) 122 width, height = image.size 123 124 rowHeightTitles = 25 125 rowHeightValues = float(height - 2 * rowHeightTitles - 3 * marginVertical) / 2.0 126 columnWidthUnit = 30 127 columnWidthValues = int(float(width - 3 * marginHorizontal - 2 * columnWidthUnit) / 2.0) 128 129 draw = ImageDraw.Draw(image) 130 # draw.rectangle((0, 0, width, height), fill=WHITE, outline=WHITE) 131 132 x = marginHorizontal 133 y = marginVertical 134 draw.text((x, y), "STW", fill=BLACK, font=fontTitles) 135 draw.text((x, y + rowHeightTitles), str(speedThroughWater), fill=BLACK, font=fontValues) 136 draw.text((x + columnWidthValues, y + rowHeightTitles * 1.4), "kts", fill=BLACK, font=fontTitles) 137 138 x = x + marginHorizontal + columnWidthValues + columnWidthUnit 139 draw.text((x, y), "SOG", fill=BLACK, font=fontTitles) 140 draw.text((x, y + rowHeightTitles), str(speedOverGround), fill=BLACK, font=fontValues) 141 draw.text((x + columnWidthValues, y + rowHeightTitles * 1.4), "kts", fill=BLACK, font=fontTitles) 142 143 x = marginHorizontal 144 y = y + rowHeightTitles + rowHeightValues + marginVertical 145 draw.text((x, y), "Depth", fill=BLACK, font=fontTitles) 146 draw.text((x, y + rowHeightTitles), str(waterDepth), fill=BLACK, font=fontValues) 147 draw.text((x + int(float(columnWidthValues) / 1.5), y + rowHeightTitles * 1.4), "m", fill=BLACK, font=fontTitles) 148 149 x = x + marginHorizontal + columnWidthValues + columnWidthUnit 150 draw.text((x, y), "Water", fill=BLACK, font=fontTitles) 151 draw.text((x, y + rowHeightTitles), str(waterTemperature), fill=BLACK, font=fontValues) 152 draw.text((x + int(float(columnWidthValues) / 1.5), y + rowHeightTitles * 1.4), "C", fill=BLACK, font=fontTitles) 153 154 x = int((x + marginHorizontal + columnWidthValues) * 0.93) 155 draw.text((x, y), "Fix", fill=BLACK, font=fontTitles) 156 draw.text((x, y + rowHeightTitles), str(gpsFix), fill=BLACK, font=fontValues) 157 158 epd.display(image) 159 epd.update() 201 160 202 161 def checkShutdownRequest(shutdownFile): … … 230 189 global logperiod 231 190 global displayperiod 232 global latitude233 global longitude234 global speedThroughWater235 global speedOverGround236 global waterDepth237 global waterTemperature238 global gpsFix239 191 240 192 try: … … 285 237 createDatabase(rrdfile) 286 238 287 displayHandler = None288 239 if epdEnabled: 289 displayHandler = DisplayHandler(displayperiod) 240 epd = EPD() 241 epd.clear() 290 242 291 243 gpsp = GpsdPoller() … … 306 258 # update rrd database for the webservice 307 259 rrdtool.update(rrdfile, "N:%s:%s:%s:%s:%s:%s:%s" % (latitude, longitude, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix)) 260 # update display, if needed 261 if epdEnabled and round(time.time(),0) % displayperiod == 0: 262 displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix) 308 263 #check for shutdown request 309 264 checkShutdownRequest(shutdownfile) … … 312 267 gpsp.stop() 313 268 gpsp.join() # wait for the thread to finish what it's doing 314 if displayHandler is not None:315 displayHandler.stop()316 displayHandler.join() # wait for the thread to finish what it's doing317 269 318 270 if __name__ == "__main__":
Note:
See TracChangeset
for help on using the changeset viewer.
