def start_write(): if oledExp.driverInit() != 0: print 'ERROR: Could not initialize the OLED Expansion' return False # this clears the screen oledExp.clear() # this sets the colour oledExp.setDisplayMode(0) #this sets it to receive text oledExp.setTextColumns() #this places the cursor on the second row, first column oledExp.setCursor(1, 0) oledExp.write('Welcome.') oledExp.setCursor(3, 0) oledExp.write('Loading ticker..') oledExp.setCursor(5, 0) oledExp.write('Prices in EUR.')
def setDoneScreen(): # clear the screen oledExp.clear() # set the cursor the middle line oledExp.setTextColumns() oledExp.setCursor(3,0) # write out the text oledExp.write( "TEMP SENSOR OFFLINE" )
def init(dirName): oledExp.setVerbosity(-1) status = oledExp.driverInit() if status != 0: print 'ERROR initializing OLED Expansion' ## setup the display # draw the plant image to the screen imgFile = dirName + "/thermometer.oled" if os.path.exists(imgFile): status = oledExp.drawFromFile(imgFile) ## write the default text # write the first word on the second line and the right side of the screen oledExp.setTextColumns() oledExp.setCursor(1,12) oledExp.write('Temp:')
def writeMeasurements(value): # set the cursor the fifth line and the right side of the screen oledExp.setTextColumns() oledExp.setCursor(3,12) # write out the text oledExp.write( str(value) + " C" )
USB_MOUNT = '/mnt/torrent' SLEEP = 2 import os import time import transmissionrpc from OmegaExpansion import oledExp status = oledExp.driverInit() oledExp.setTextColumns() while True: # find size of free space on USB statvfs = os.statvfs(USB_MOUNT) total = float(statvfs.f_blocks) * statvfs.f_frsize / 1000000000 free = float(statvfs.f_bfree) * statvfs.f_frsize / 1000000000 # find transmission info tc = transmissionrpc.Client('localhost', port=9091) torrents = tc.get_torrents() download = False rateDownload = 0 rateUpload = 0 for t in torrents: if t.status == 'downloading': download = True filename = t.name percentDone = t.percentDone rateUpload += t.rateUpload rateDownload += t.rateDownload oledExp.setCursor(0, 0) oledExp.write('Date: ' + time.strftime("%d %b %y %H:%M"))
def writeMeasurements(value): # set the cursor the fifth line and the right side of the screen oledExp.setTextColumns() oledExp.setCursor(line - 1, 1) # write out the text oledExp.write('%s: %.3f C' % (label[-6:-2], value))
def write(): ### this gets the date and time date = time.strftime("%d %b %Y %H:%M") #time_now = time.strftime("%X") ### these are the API calls for the four currencies response_1 = urllib2.urlopen( 'https://api.coinmarketcap.com/v1/ticker/bitcoin/?convert=EUR') r_1 = json.load(response_1) response_2 = urllib2.urlopen( 'https://api.coinmarketcap.com/v1/ticker/monero/?convert=EUR') r_2 = json.load(response_2) response_3 = urllib2.urlopen( 'https://api.coinmarketcap.com/v1/ticker/iconomi/?convert=EUR') r_3 = json.load(response_3) response_4 = urllib2.urlopen( 'https://api.coinmarketcap.com/v1/ticker/siacoin/?convert=EUR') r_4 = json.load(response_4) ### this sets a place value for the Decimal round up cents = Decimal('0.001') #cents2 = Decimal('0.0001') ### these set the JSON resturns to variables c_1 = r_1[0] c_2 = r_2[0] c_3 = r_3[0] c_4 = r_4[0] ### this grabs info from the dictionaries, and makes them variables c_1_sym = c_1['symbol'] #c_1_price = round(float(c_1['price_eur']), 2) c_1_price = c_1['price_eur'] c_1_price = Decimal(c_1_price).quantize(cents, ROUND_HALF_UP) c_1_per = c_1['percent_change_24h'] c_2_sym = c_2['symbol'] #c_2_price = round(float(c_2['price_eur']), 2) c_2_price = c_2['price_eur'] c_2_price = Decimal(c_2_price).quantize(cents, ROUND_HALF_UP) c_2_per = c_2['percent_change_24h'] c_3_sym = c_3['symbol'] #c_3_price = round(float(c_3['price_eur']), 2) c_3_price = c_3['price_eur'] c_3_price = Decimal(c_3_price).quantize(cents, ROUND_HALF_UP) c_3_per = c_3['percent_change_24h'] c_4_sym = c_4['symbol'] #c_3_price = round(float(c_3['price_eur']), 2) c_4_price = c_4['price_eur'] c_4_price = Decimal(c_4_price).quantize(cents, ROUND_HALF_UP) c_4_per = c_4['percent_change_24h'] ### this is the write to screen process if oledExp.driverInit() != 0: print 'ERROR: Could not initialize the OLED Expansion' return False ### this clears the screen oledExp.clear() ### this sets the colour oledExp.setDisplayMode(0) ### this sets it to receive text oledExp.setTextColumns() ### this places the cursor on the second row, first column oledExp.setCursor(1, 0) ### oledExp.write(' '+date+' '+time_now) oledExp.write(date) oledExp.setCursor(3, 0) oledExp.write(c_1_sym + ': ' + str(c_1_price) + ' ' + c_1_per + '%') oledExp.setCursor(4, 0) oledExp.write(c_2_sym + ': ' + str(c_2_price) + ' ' + c_2_per + '%') oledExp.setCursor(5, 0) oledExp.write(c_3_sym + ': ' + str(c_3_price) + ' ' + c_3_per + '%') oledExp.setCursor(6, 0) oledExp.write(c_4_sym + ': ' + str(c_4_price) + ' ' + c_4_per + '%') ### this sets the scroll type, speed, etc oledExp.scroll(0, 0, 0, 8 - 1)