if 'TPV' in current: gpsData=current['TPV'] conn = sqlite3.connect(filename) c = conn.cursor() ts = datetime.datetime.now() if gpsData != None and set(gpsData.keys()).issuperset(['lat','lon','speed','time']): c.execute(withGPS, (dataset, ts, ch[0],ch[1],ch[2],ch[3],gpsData['lat'],gpsData['lon'],gpsData['speed'],gpsData['time'])) else: c.execute(withoutGPS, (dataset, ts, ch[0],ch[1],ch[2],ch[3])) conn.commit() conn.close() if hasGrid and grid.clear() == -1: hasGrid = False if hasGrid: steps=[None]*displayChannels for i in range(displayChannels): steps[i] = int(math.floor(ch[i] / 5000 * 64 / displayChannels)) fullrows = int(math.floor(steps[i]/8)) partrows = int(steps[i] % 8) for x in range(fullrows): for y in range(8): grid.setPixel(x+i*8/displayChannels,y) for y in range(partrows): grid.setPixel(fullrows+i*8/displayChannels,y)
from adafruit.Adafruit_LEDBackpack.Adafruit_8x8 import EightByEight import time PATTERN_N = [0x81, 0x83, 0x85, 0x89, 0x91, 0xA1, 0xC1, 0x81] PATTERN_A = [0x81, 0x81, 0x81, 0x81, 0xFF, 0x42, 0x24, 0x18] def writePattern(pattern): for row in range(8): grid.writeRowRaw(row, pattern[row]) grid = EightByEight(address=0x70) grid.clear() while True: writePattern( PATTERN_A ) time.sleep(0.5) writePattern( PATTERN_N ) time.sleep(0.5)
print "" gpsData = gps.GPS.read() conn = sqlite3.connect(filename) c = conn.cursor() ts = datetime.datetime.now() if gpsData: c.execute(withGPS, (dataset, ts, ch[0], ch[1], ch[2], ch[3], gpsData['lat'], gpsData['lng'], gpsData['speed'])) else: c.execute(withoutGPS, (dataset, ts, ch[0], ch[1], ch[2], ch[3])) conn.commit() conn.close() if hasGrid and grid.clear() == -1: hasGrid = False if hasGrid: for i in range(displayChannels): steps[i] = math.floor(ch[i] / 5000 * 64 / displayChannels) fullrows = math.floor(steps[i] / 8 * displayChannels) partrows = steps[i] * displayChannels % 8 for x in range(fullrows): for y in range(0, 8): grid.setPixel(x + 8 * i, y) for y in range(0, partrows): grid.setPixel(fullrows, y) # print "Channels: %.3f, %.3f, %.3f, %.3f V" % (ch[0],ch[1],ch[2],ch[3]) # print "Steps = %d" % (steps) # i=0