185 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			185 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| #!/usr/bin/env python
 | |
| # -*- coding: utf-8 -*-
 | |
| 
 | |
| import httplib
 | |
| import urllib
 | |
| import json
 | |
| from vestactrl import *
 | |
| import random
 | |
| import sys
 | |
| 
 | |
| real_hw = True
 | |
| 
 | |
| def adjust_blanks(s):
 | |
|     blank = '░'
 | |
|     return s.replace('░','`0')
 | |
| 
 | |
| def adjust_empty_spaces(s):
 | |
|     empty_space = ' '
 | |
|     return s.replace(' ', '`0')
 | |
| 
 | |
| def get_board_content():
 | |
|     url1 = 'https://app.vestaboard.com/api/v1/board/'
 | |
|     url2 = '/describe'
 | |
|     full_url = url1 + board_id + url2
 | |
|     page = urllib.urlopen(full_url)
 | |
|     #conn = httplib.HTTPSConnection('app.vestaboard.com')
 | |
|     #conn.request('GET', '/api/v1/board/%s/describe' % board_id)
 | |
|     #response = conn.getresponse()
 | |
|     contents = page.read()
 | |
|     #print response.status, response.reason
 | |
|     print page.getcode()
 | |
|     #retval = adjust_blanks(response.read())
 | |
|     contents2 = adjust_blanks(contents)
 | |
|     retval = adjust_empty_spaces(contents2)
 | |
|     #conn.close()
 | |
|     page.close()
 | |
|     return retval
 | |
| 
 | |
| def is_new_content(new, old):
 | |
|     retval = False
 | |
|     for v in zip(new,old):
 | |
|         if v[0] != v[1]:
 | |
|             retval = True
 | |
|             break
 | |
|     return retval
 | |
| 
 | |
| def random_colors():
 | |
|     proto = [
 | |
| 	'`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d',
 | |
| 	'`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d',
 | |
| 	'`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d',
 | |
| 	'`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d',
 | |
| 	'`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d',
 | |
| 	'`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d`%d']
 | |
|     lines = []
 | |
|     for p in proto:
 | |
| 	s = p % (random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5),
 | |
|             random.randint(1, 5))
 | |
|         lines.append(s)
 | |
|     setup_digits(lines, left_to_right_swap=False)
 | |
| 
 | |
| # VBR (23x7)
 | |
| #board_id = '700df57c-8b0a-4166-8758-b9de6e900cb8'
 | |
| # VB (22x6)
 | |
| #board_id = 'demo-a3c6ed9d-0499-4368-a3e9-b132cfc94305'
 | |
| # Testaboard
 | |
| board_id = 'demo-6a439bfd-fe37-4d82-af76-9cbf4fbd6367'
 | |
| #board_id = ' '
 | |
| board_name = 'Testaboard'
 | |
| 
 | |
| # ANDREA
 | |
| timeouts = 15
 | |
| if real_hw:
 | |
|     print 'before pause'
 | |
|     sys.stdout.flush()
 | |
|     #time.sleep(timeouts)
 | |
|     print 'after pause'
 | |
|     sys.stdout.flush()
 | |
|     print 'before init_uart'
 | |
|     sys.stdout.flush()
 | |
|     board_init_uart()
 | |
|     print 'after init_uart'
 | |
|     sys.stdout.flush()
 | |
|     print 'before blanks'
 | |
|     sys.stdout.flush()
 | |
|     # ANDREA
 | |
|     #test_check_blanks()
 | |
|     print 'after blanks'
 | |
|     sys.stdout.flush()
 | |
|     print 'before 2nd pause'
 | |
|     sys.stdout.flush()
 | |
|     #time.sleep(10)
 | |
|     print 'after 2nd pause'
 | |
|     sys.stdout.flush()
 | |
| 
 | |
| last_lines = ['', '', '', '', '', '']
 | |
| 
 | |
| data = None
 | |
| #while True:
 | |
| 
 | |
| #while board_id == ' ':
 | |
|     #time.sleep(5)
 | |
| 
 | |
| #time.sleep(3)
 | |
| 
 | |
| #print('**********')
 | |
| #print board_name
 | |
| #print('**********')
 | |
| #r = get_board_content()
 | |
| #data = json.loads(r)
 | |
| #print('DATA: %s') % data
 | |
| #ulines = data['message']['lines']
 | |
| #print('ulines: %s') % ulines
 | |
| #lines = [l.encode('ascii', 'ignore') for l in ulines]
 | |
| origlines = ['                      ', '                      ', '      WELCOME TO      ', '      PROTOSPACE      ', '                      ', '                      ']
 | |
| lines = []
 | |
| for l in origlines:
 | |
|     line = l.replace(' ', '`0')
 | |
|     lines.append(line)
 | |
| 
 | |
| test_flag = 0
 | |
| print lines
 | |
| sys.stdout.flush()
 | |
| row_num = len(lines)
 | |
| #print('Number of rows: %d') % row_num
 | |
| #for i in range(6):
 | |
| 	#print('%s || %s' %(lines[i], last_lines[i]))
 | |
| if row_num > 6:
 | |
|     print('* * * * * ')
 | |
|     print('ERROR: Too many rows; cannot send your message to the board. Sorry!')
 | |
|     print('* * * * * ')
 | |
| 
 | |
| if row_num < 7:
 | |
|     row_len_flag = 0
 | |
|     for i in range(row_num):
 | |
|         row_string = lines[i]
 | |
|         #print('CURRENT ROW STRING: %s') % row_string
 | |
|         row_len = len(row_string) - row_string.count('`')
 | |
|         #print('CURRENT ROW LENGTH: %s') % row_len
 | |
|         if row_len > 22:
 | |
|             row_len_flag = 1
 | |
|             print('* * * * * ')
 | |
|             print('ERROR: Too many characters in row %d; cannot send your message to the board. Sorry!') % i
 | |
|             print('* * * * * ')
 | |
|             #setup_digits(lines_b, left_to_right_swap=False, real_hw=real_hw)
 | |
|     if row_len_flag == 0:
 | |
|         print('*** Jolly good! Message format valid. ***')
 | |
|         sys.stdout.flush()
 | |
|         if lines and is_new_content(lines, last_lines):
 | |
|         #if lines != last_lines:
 | |
|             print 'before setup digits'
 | |
|             sys.stdout.flush()
 | |
|             # ANDREA
 | |
|             setup_digits(lines, left_to_right_swap=False, real_hw=real_hw)
 | |
|             print 'after setup digits'
 | |
|             sys.stdout.flush()
 | |
|             last_lines = lines
 | |
|             print 'Waiting for bits to change...'
 | |
|             sys.stdout.flush()
 | |
|             time.sleep(6)
 | |
|             print 'Click \"Next Flap\" to continue.'
 | |
|             sys.stdout.flush()
 | |
|             #print 'Done. Please click "Next Flap" to continue.'
 | |
|             #raw_input("Press Enter to continue...")
 |