- Timestamp:
- Jul 21, 2016, 4:25:18 PM (10 years ago)
- Branches:
- debian/bullseye, debian/jessie
- Children:
- 2f9bd3a
- Parents:
- f0d4b56 (diff), 6c57d0a (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)links above to see all the changes relative to each parent. - Location:
- src/daemon
- Files:
-
- 1 added
- 1 edited
-
gnuboat (modified) (7 diffs)
-
gnuboat.service (added)
Legend:
- Unmodified
- Added
- Removed
-
src/daemon/gnuboat
rf0d4b56 r501b629 53 53 54 54 shutdownRequested = None 55 latitude = None 56 longitude = None 57 speedThroughWater = None 58 speedOverGround = None 59 waterDepth = None 60 waterTemperature = None 61 gpsFix = None 55 62 56 63 # Copied from https://gist.github.com/wolfg1969/4653340 … … 86 93 pass 87 94 95 """@class DisplayHandler 96 """ 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 = displayperiod 103 self._running = True 104 105 def stop(self): 106 self._running = False 107 108 def run(self): 109 global latitude 110 global longitude 111 global speedThroughWater 112 global speedOverGround 113 global waterDepth 114 global waterTemperature 115 global gpsFix 116 117 try: 118 while self._running: 119 self.displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix) 120 time.sleep(self._updatePeriod) 121 except StopIteration: 122 pass 123 124 def displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix): 125 if not epdEnabled: 126 return 127 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 background 133 image = Image.new('1', epd.size, WHITE) 134 width, height = image.size 135 136 rowHeightTitles = 25 137 rowHeightValues = float(height - 2 * rowHeightTitles - 3 * marginVertical) / 2.0 138 columnWidthUnit = 30 139 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 = marginHorizontal 145 y = marginVertical 146 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 + columnWidthUnit 152 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 = marginHorizontal 158 y = y + rowHeightTitles + rowHeightValues + marginVertical 159 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 + columnWidthUnit 165 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 88 178 def createDatabase(databaseFile): 89 179 rrdDataSources = [ 'DS:latitude:GAUGE:15:-90:90', … … 109 199 rrdDataSources, 110 200 rrdArchives) 111 112 def displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix):113 if not epdEnabled:114 return115 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 background121 image = Image.new('1', epd.size, WHITE)122 width, height = image.size123 124 rowHeightTitles = 25125 rowHeightValues = float(height - 2 * rowHeightTitles - 3 * marginVertical) / 2.0126 columnWidthUnit = 30127 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 = marginHorizontal133 y = marginVertical134 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 + columnWidthUnit139 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 = marginHorizontal144 y = y + rowHeightTitles + rowHeightValues + marginVertical145 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 + columnWidthUnit150 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()160 201 161 202 def checkShutdownRequest(shutdownFile): … … 189 230 global logperiod 190 231 global displayperiod 232 global latitude 233 global longitude 234 global speedThroughWater 235 global speedOverGround 236 global waterDepth 237 global waterTemperature 238 global gpsFix 191 239 192 240 try: … … 237 285 createDatabase(rrdfile) 238 286 287 displayHandler = None 239 288 if epdEnabled: 240 epd = EPD() 241 epd.clear() 289 displayHandler = DisplayHandler(displayperiod) 242 290 243 291 gpsp = GpsdPoller() … … 258 306 # update rrd database for the webservice 259 307 rrdtool.update(rrdfile, "N:%s:%s:%s:%s:%s:%s:%s" % (latitude, longitude, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix)) 260 # update display, if needed261 if epdEnabled and round(time.time(),0) % displayperiod == 0:262 displayValues(epd, speedThroughWater, speedOverGround, waterDepth, waterTemperature, gpsFix)263 308 #check for shutdown request 264 309 checkShutdownRequest(shutdownfile) … … 267 312 gpsp.stop() 268 313 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 doing 269 317 270 318 if __name__ == "__main__":
Note:
See TracChangeset
for help on using the changeset viewer.
