Changes in / [501b629:f0d4b56]


Ignore:
Location:
src/daemon
Files:
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • src/daemon/gnuboat

    r501b629 rf0d4b56  
    5353
    5454shutdownRequested = None
    55 latitude = None
    56 longitude = None
    57 speedThroughWater = None
    58 speedOverGround = None
    59 waterDepth = None
    60 waterTemperature = None
    61 gpsFix = None
    6255
    6356# Copied from https://gist.github.com/wolfg1969/4653340
    … …  
    9386      pass
    9487
    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 
    17888def createDatabase(databaseFile):
    17989  rrdDataSources = [ 'DS:latitude:GAUGE:15:-90:90',
    … …  
    199109                   rrdDataSources,
    200110                   rrdArchives)
     111
     112def 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()
    201160
    202161def checkShutdownRequest(shutdownFile):
    … …  
    230189  global logperiod
    231190  global displayperiod
    232   global latitude
    233   global longitude
    234   global speedThroughWater
    235   global speedOverGround
    236   global waterDepth
    237   global waterTemperature
    238   global gpsFix
    239191
    240192  try:                               
    … …  
    285237  createDatabase(rrdfile)
    286238
    287   displayHandler = None
    288239  if epdEnabled:
    289     displayHandler = DisplayHandler(displayperiod)
     240    epd = EPD()
     241    epd.clear()
    290242
    291243  gpsp = GpsdPoller()
    … …  
    306258      # update rrd database for the webservice
    307259      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)
    308263      #check for shutdown request
    309264      checkShutdownRequest(shutdownfile)
    … …  
    312267    gpsp.stop()
    313268    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
    317269
    318270if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.