#TODO: must use raw_display to have >16 colors # do we need interpolation at all? import math import time import numpy as np from scipy.interpolate import griddata #low range of the sensor (this will be blue on the scr) MINTEMP = 20 #high range of the sensor (this will be red on the scr) MAXTEMP = 32 #how many color values we can have COLORDEPTH = 256 #initialize the sensor from Adafruit_AMG88xx import Adafruit_AMG88xx sensor = Adafruit_AMG88xx() points = [(math.floor(ix / 8), (ix % 8)) for ix in range(0, 64)] grid_x, grid_y = np.mgrid[0:7:32j, 0:7:32j] #the list of colors we can choose from #from colour import Color, hsl2hex #blue = Color("indigo") #color_list = list(blue.range_to(Color("red"), COLORDEPTH)) #print map(lambda c:c.hex, color_list ) #exit(1) #create the array of colors #from urwid.display_common import AttrSpec #colors = [ ('#cf0', c.get_hex()[:4]) for c in colors ] #@@@@@ #colors = [ AttrSpec( str(MINTEMP+idx), 'white', c ) for idx,c in enumerate(color_list) ] #@@@@@ import curses #from urwid import raw_display as display from urwid import curses_display as display scr = display.Screen() #scr.colors=256 scr.set_mouse_tracking(False) #we dont want mouse events #scr.set_terminal_properties(colors=256) #scr.reset_default_terminal_palette() #some utility functions def constrain(val, min_val, max_val): return min(max_val, max(min_val, val)) def mapscale(x, in_min, in_max, out_min, out_max): return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min #let the sensor initialize time.sleep(0.1) def display_pixels(): while(1): #read the pixels pixels = sensor.readPixels() #8x8 64 elements pixels = [mapscale(p, MINTEMP, MAXTEMP, 0, COLORDEPTH - 1) for p in pixels] #print "pixels: ", len(pixels), pixels #perform interpolation bicubic = griddata(points, pixels, (grid_x, grid_y), method='cubic') #draw everything for ix, row in enumerate(bicubic): scr.s.move( ix,0 ) for jx, pixel in enumerate(row): #scr.rect( colors[constrain(int(pixel), 0, COLORDEPTH- 1)], (displayPixelHeight * ix, displayPixelWidth * jx, displayPixelHeight, displayPixelWidth)) #scr._setattr( color_list[ constrain( int(pixel), 0, COLORDEPTH-1) ] ) scr.s.addstr( chr( constrain(int(pixel),32,126) ) #, curses.color_pair( int(pixel) ) ) scr.s.refresh() time.sleep(0.03) scr.run_wrapper(display_pixels)