def __init__(self, usb_port=USB_PORT, max_size=10): self.messages = [] self.sign = alphasign.Serial(USB_PORT) # where in the queue are we? self.index = 0 # where do we start self.start_index = 0 self.sign.connect() self.sign.clear_memory() # how many 'live' messages do we have? self.size = 0 self.max_size = max_size label_num = 0 for i in range(self.max_size): msg = {} msg["str"] = alphasign.String(size=125, label=chr(ord('A') + label_num)) label_num = label_num + 1 msg["txt"] = alphasign.Text( "%s%s" % (alphasign.colors.GREEN, msg["str"].call()), chr(ord('A') + label_num), mode=alphasign.modes.ROTATE) label_num = label_num + 1 self.messages.append(msg) self.sign.allocate((msg["str"], msg["txt"])) self.sign.write(msg["str"]) self.sign.write(msg["txt"]) print "alloc'ed: %s string, %s text" % (msg["str"], msg["txt"])
def update_sign(): sign = alphasign.Serial(device='/dev/ttyUSB0') sign.connect() sign.clear_memory() # create an empty alphasign.String alpha_str = alphasign.String(size=64) # create a single alphasign.Text object with a placeholder for our alphasign.String alpha_txt = alphasign.Text(alpha_str.call(),mode=alphasign.modes.COMPRESSED_ROTATE) # allocate memory for these objects on the sign sign.allocate((alpha_str,alpha_txt)) # tell sign to only display the text part sign.set_run_sequence((alpha_txt,)) # write objects for obj in (alpha_str,alpha_txt): sign.write(obj) # This gives time for the serial write to complete before we issue the next write. time.sleep(5) last_payload = '' while True: try: # fetch new-line separated plain text from Interweb payload = urllib2.urlopen("https://server.appletonmakerspace.org/wiki/doku.php?id=sign_text&do=export_raw").read() except Exception as e: payload = 'net err: '+str(e) # alert bystanders with beep when we update if payload != last_payload: sign.beep(frequency=20, duration=1) last_payload = payload # loop over each line of plain text, displaying for 10 seconds for line in payload.splitlines(): alpha_str.data = line sign.write(alpha_str) time.sleep(10)
def __init__(self, channel, nickname, password=''): self.channel = channel self.nickname = nickname self.password = password self.sign = alphasign.Serial(USB_PORT) self.sign.connect() self.sign.clear_memory() self.message_str = alphasign.String(size=140, label="2") self.message_txt = alphasign.Text("%s" % self.message_str.call(), label="B", mode=alphasign.modes.TWINKLE) #message_txt = alphasign.Text("%s%s" % (alphasign.colors.GREEN,message_str.call()), label="B", mode = alphasign.modes.ROTATE) self.message_str.data = "Make me say things!" # allocate memory for these objects on the sign self.sign.allocate((self.message_str, self.message_txt)) self.sign.set_run_sequence((self.message_txt, )) self.sign.write(self.message_txt) self.sign.write(self.message_str)
def updateLED(list): sign = alphasign.Serial(0) sign.connect() print "Clearing sign memory" #sign.clear_memory() #sign.beep(frequency=0,duration=0.1,repeat=0) #create the sequence messages = [] for position, item in enumerate(list): messageData = item #cleanup the message a bit #messageData = "%s" + " " + messageData + " " messageData = "%s" + messageData label = position + 1 messageText = alphasign.Text((messageData % alphasign.charsets.TEN_HIGH_STD),label=str(label),mode=checkMode(messageData),position=checkPosition(messageData)) #messageText = alphasign.Text(messageData % alphasign.charsets.SEVEN_SHADOW,label=str(label)) #messageText = alphasign.Text((messageData % alphasign.charsets.SEVEN_HIGH_FANCY),label="A") print "Message Data: %s" % messageData print str(position) print "Position: %s" % position messages.append(messageText) # allocate memory for these objects on the sign print "Allocating sign text" sign.allocate((messages)) #print "Updating Sequence" #sign.set_run_sequence((messages)) print "Writing messages" for obj in (messages): sign.write(obj)
(at your option) any later version. SignServer is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with SignServer. If not, see <http://www.gnu.org/licenses/>. ''' import alphasign from decorators import cached, retrying sign = alphasign.Serial() sign.connect() sign_memory_timeout = 60 * 60 #How long until the memory cache dies. -1 for never. sign_retries = 3 #Default number of times to retry getting memory. 0 for forever. @cached @retrying(sign_retries) def read_raw_memory_table(): '''Caching, retrying version of sign.read_raw_memory_table. If the result is not None, preserves the result for `timeout` seconds. `timeout` is an instance variable of this function. ''' table = sign.read_raw_memory_table() return table if table is not False else None
def main(): """Main function """ parser = OptionParser("%prog") parser.add_option("-d", "--device", help="serial/USB device to use", action="store", type="string", dest="device", default=None) parser.add_option("-m", "--module", help="module to load for a sign_sequence() function", action="store", type="string", dest="module", default="sample") parser.add_option("-p", "--port", help="port to use for web service", action="store", type="string", dest="port", default="8000") parser.add_option("-v", "--verbose", help="turn on verbose messages for debugging", action="store_true", dest="verbose", default=False) (options, args) = parser.parse_args() level = logging.INFO if options.verbose: level = logging.DEBUG logging.basicConfig(format='%(asctime)s:%(levelname)s:%(message)s', level=level) os.chdir(os.path.dirname(os.path.realpath(__file__))) device = options.device if not device: device = guess_device() module = None try: results = imp.find_module(options.module) args = (options.module, ) + results module = imp.load_module(*args) LOG.info("Module '%s' loaded successfully" % (options.module, )) except ImportError as e: LOG.error("ERROR: Could not find module '%s': %s" % (options.module, str(e))) sys.exit(1) if getattr(module, 'sign_sequence', None) is None: LOG.error("ERROR: Module '%s' has no function sign_sequence()" % (options.module, )) sys.exit(1) LOG.info("Initializing sign at %s..." % (device, )) sign = alphasign.Serial(device=device) sign.connect() sign.debug = False sign.clear_memory() threading.Thread(target=start_server, args=(int(options.port), )).start() LOG.info("Starting sign loop thread...") threading.Thread(target=sign_loop, args=(sign, module)).start() try: time.sleep(2) LOG.info("Okay, everything's been started. Hit Ctrl-C to exit...") while True: time.sleep(1) except KeyboardInterrupt: pass LOG.info( "Shutting everything down, this may take a little while, hang on...") global SHUTDOWN SHUTDOWN = True
import os import json import time import datetime import alphasign sign = alphasign.Serial(device=os.environ["MZ_SIGN_PORT"]) sign.connect() sign.clear_memory() name_str = alphasign.String(size=50, label="1") time_str = alphasign.String(size=20, label="2") playing_text = alphasign.Text( "Now Playing: {} {}".format(name_str.call(), time_str.call()), label="A", mode=alphasign.mode.ROLL_LEFT ) sign_objs = (name_str, time_str, playing_text) sign.allocate(objs) sign.set_run_sequence((playing_text,)) for obj in sign_objs: sign.write(obj) redis = redis.Redis() while True: quent = redis.lindex("musicaqueue", 0) if quent is None: