Changeset 501b629 for src


Ignore:
Timestamp:
Jul 21, 2016, 4:25:18 PM (10 years ago)
Author:
Joachim Langenbach <joachim.langenbach@…>
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.
Message:

Merge remote-tracking branch 'origin/master' into debian/jessie

Location:
src/daemon
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • src/daemon/gnuboat

    rf0d4b56 r501b629  
    5353
    5454shutdownRequested = None
     55latitude = None
     56longitude = None
     57speedThroughWater = None
     58speedOverGround = None
     59waterDepth = None
     60waterTemperature = None
     61gpsFix = None
    5562
    5663# Copied from https://gist.github.com/wolfg1969/4653340
    … …  
    8693      pass
    8794
     95"""@class DisplayHandler
     96"""
     97class 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
    88178def createDatabase(databaseFile):
    89179  rrdDataSources = [ 'DS:latitude:GAUGE:15:-90:90',
    … …  
    109199                   rrdDataSources,
    110200                   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()
    160201
    161202def checkShutdownRequest(shutdownFile):
    … …  
    189230  global logperiod
    190231  global displayperiod
     232  global latitude
     233  global longitude
     234  global speedThroughWater
     235  global speedOverGround
     236  global waterDepth
     237  global waterTemperature
     238  global gpsFix
    191239
    192240  try:                               
    … …  
    237285  createDatabase(rrdfile)
    238286
     287  displayHandler = None
    239288  if epdEnabled:
    240     epd = EPD()
    241     epd.clear()
     289    displayHandler = DisplayHandler(displayperiod)
    242290
    243291  gpsp = GpsdPoller()
    … …  
    258306      # update rrd database for the webservice
    259307      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)
    263308      #check for shutdown request
    264309      checkShutdownRequest(shutdownfile)
    … …  
    267312    gpsp.stop()
    268313    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
    269317
    270318if __name__ == "__main__":
Note: See TracChangeset for help on using the changeset viewer.