Browse Source

Another part to the major refactor.

Matt Sparks 15 years ago
parent
commit
2d01edfb9f

+ 5 - 0
alphasign/__init__.py

@@ -12,3 +12,8 @@ from date import Date
 from string import String
 from packet import Packet
 from text import Text
+
+import colors
+import positions
+import modes
+import speeds

+ 20 - 0
alphasign/charsets.py

@@ -0,0 +1,20 @@
+# Character sets
+FIVE_HIGH_STD      = "\x1A1"
+FIVE_STROKE        = "\x1A2"
+SEVEN_HIGH_STD     = "\x1A3"
+SEVEN_STROKE       = "\x1A4"
+SEVEN_HIGH_FANCY   = "\x1A5"
+TEN_HIGH_STD       = "\x1A6"
+SEVEN_SHADOW       = "\x1A7"
+FULL_HEIGHT_FANCY  = "\x1A8"
+FULL_HEIGHT_STD    = "\x1A9"
+SEVEN_SHADOW_FANCY = "\x1A:"
+FIVE_WIDE          = "\x1A;"
+SEVEN_WIDE         = "\x1A<"
+SEVEN_FANCY_WIDE   = "\x1A="
+WIDE_STROKE_FIVE   = "\x1A>"
+# Alpha 2.0 and 3.0 only
+FIVE_HIGH_CUST     = "\x1AW"
+SEVEN_HIGH_CUST    = "\x1AX"
+TEN_HIGH_CUST      = "\x1AY"
+FIFTEEN_HIGH_CUST  = "\x1AZ"

+ 14 - 0
alphasign/colors.py

@@ -0,0 +1,14 @@
+# Colors
+RED       = "\x1C1"
+GREEN     = "\x1C2"
+AMBER     = "\x1C3"
+DIM_RED   = "\x1C4"
+DIM_GREEN = "\x1C5"
+BROWN     = "\x1C6"
+ORANGE    = "\x1C7"
+YELLOW    = "\x1C8"
+RAINBOW_1 = "\x1C9"
+RAINBOW_2 = "\x1CA"
+COLOR_MIX = "\x1CB"
+AUTOCOLOR = "\x1CC"
+# TODO(ms): need support for RGB colors

+ 3 - 59
alphasign/constants.py

@@ -1,62 +1,3 @@
-# Display Modes (p89)
-modes = {
-  "rotate":             "a",
-  "hold":               "b",
-  "flash":              "c",
-  "roll_up":            "e",
-  "roll_down":          "f",
-  "roll_left":          "g",
-  "roll_right":         "h",
-  "wipe_up":            "i",
-  "wipe_down":          "j",
-  "wipe_left":          "k",
-  "wipe_right":         "l",
-  "scroll":             "m",
-  "automode":           "o",
-  "roll_in":            "p",
-  "roll_out":           "q",
-  "wipe_in":            "r",
-  "wipe_out":           "s",
-  "compressed_rotate":  "t",  # only available on certain sign models
-  "explode":            "u",  # alpha 3.0 protocol
-  "clock":              "v",  # alpha 3.0 protocol
-  # Special Modes
-  "twinkle":            "n0",
-  "sparkle":            "n1",
-  "snow":               "n2",
-  "interlock":          "n3",
-  "switch":             "n4",
-  "slide":              "n5",  # only Betabrite 1036 (same as CYCLE_COLORS?)
-  "spray":              "n6",
-  "starburst":          "n7",
-  "welcome":            "n8",
-  "slot_machine":       "n9",
-  "news_flash":         "nA",  # only Betabrite 1036
-  "trumpet_animation":  "nb",  # only betabrite 1036
-  "cycle_colors":       "nC",  # only AlphaEclipse 3600
-  # Special Graphics (these display before the message)
-  "thank_you":          "nS",
-  "no_smoking":         "nU",
-  "dont_drive_drive":   "nV",
-  "running_animal":     "nW",
-  "fish_animation":     "nW",
-  "fireworks":          "nX",
-  "turbo_car":          "nY",
-  "balloon_animation":  "nY",
-  "cherry_bomb":        "nZ",
-}
-
-# Display Positions
-positions = {
-  "middle_line":        "\x20",
-  "top_line":           "\x22",
-  "bottom_line":        "\x26",
-  "fill":               "\x30",
-  "left":               "\x31",
-  "right":              "\x32",
-}
-
-
 # Counters
 # We have 5 of them.
 counters = {
@@ -84,6 +25,9 @@ READ_LARGE_DOTS       = "N"  # Read LARGE DOTS PICTURE file (p43)
 WRITE_ALPHAVISION     = "O"  # Write ALPHAVISION BULLETIN (p48)
 SET_TIMEOUT           = "T"  # Set Timeout Message (p118) (Alpha 2.0/3.0)
 
+UNLOCKED              = "U"
+LOCKED                = "L"
+
 # Constants used in transmission packets
 NUL                   = "\x00"  # NULL
 SOH                   = "\x01"  # Start of Header

+ 23 - 0
alphasign/extchars.py

@@ -0,0 +1,23 @@
+# Extended characters
+UP_ARROW         = "\x08\x64"
+DOWN_ARROW       = "\x08\x65"
+LEFT_ARROW       = "\x08\x66"
+RIGHT_ARROW      = "\x08\x67"
+PACMAN           = "\x08\x68"
+SAIL_BOAT        = "\x08\x69"
+BALL             = "\x08\x6A"
+TELEPHONE        = "\x08\x6B"
+HEART            = "\x08\x6C"
+CAR              = "\x08\x6D"
+HANDICAP         = "\x08\x6E"
+RHINO            = "\x08\x6F"
+MUG              = "\x08\x70"
+SATELLITE_DISH   = "\x08\x71"
+COPYRIGHT_SYMBOL = "\x08\x72"
+MALE_SYMBOL      = "\x08\x73"
+FEMALE_SYMBOL    = "\x08\x74"
+BOTTLE           = "\x08\x75"
+DISKETTE         = "\x08\x76"
+PRINTER          = "\x08\x77"
+MUSICAL_NOTE     = "\x08\x78"
+INFINITY_SYMBOL  = "\x08\x79"

+ 63 - 0
alphasign/interfaces/base.py

@@ -1,6 +1,11 @@
+import time
+
 from alphasign import constants
 from alphasign import packet
 
+import alphasign.string
+import alphasign.text
+
 
 class BaseInterface(object):
   def write(self, data):
@@ -11,6 +16,7 @@ class BaseInterface(object):
     """
     pkt = packet.Packet("%s%s" % (constants.WRITE_SPECIAL, "$"))
     self.write(pkt)
+    time.sleep(1)
 
   def beep(self, frequency=0, duration=0.1, repeat=0):
     """Make the sign beep.
@@ -47,3 +53,60 @@ class BaseInterface(object):
     """
     pkt = packet.Packet("%s%s" % (constants.WRITE_SPECIAL, ","))
     self.write(pkt)
+
+  def allocate(self, files):
+    """Allocate a set of files on the device.
+
+    Args:
+      files: list of file objects (Text, String, ...)
+    """
+    seq = ""
+    for obj in files:
+      size_hex = "%04x" % obj.size
+      # format: FTPSIZEQQQQ
+
+      if type(obj) == alphasign.string.String:
+        file_type = "B"
+        qqqq = "0000"  # unused for strings
+        lock = constants.LOCKED
+      else: # if type(obj) == alphasign.text.Text:
+        file_type = "A"
+        qqqq = "FFFF"  # TODO(ms): start/end times
+        lock = constants.UNLOCKED
+
+      alloc_str = ("%s%s%s%s%s" %
+                   (obj.label,   # file label to allocate
+                   file_type,    # file type
+                   lock,
+                   size_hex,     # size in hex
+                   qqqq))
+      seq += alloc_str
+
+    # allocate special TARGET TEXT files 1 through 5
+    for i in range(5):
+      alloc_str = ("%s%s%s%s%s" %
+                   ("%d" % (i + 1),
+                   "A",    # file type
+                   constants.UNLOCKED,
+                   "%04x" % 100,
+                   "FEFE"))
+      seq += alloc_str
+
+    pkt = packet.Packet("%s%s%s" % (constants.WRITE_SPECIAL, "$", seq))
+    self.write(pkt)
+
+  def set_run_sequence(self, files, locked=False):
+    """Set the run sequence on the device.
+
+    This determines the order in which the files are displayed on the device.
+
+    Args:
+      files: ordered list of file objects (Text, String, ...)
+      locked: allow sequence to be changed with IR keyboard
+    """
+    seq_str = ".T"
+    seq_str += locked and "L" or "U"
+    for obj in files:
+      seq_str += obj.label
+    pkt = packet.Packet("%s%s" % (constants.WRITE_SPECIAL, seq_str))
+    self.write(pkt)

+ 47 - 0
alphasign/modes.py

@@ -0,0 +1,47 @@
+# Display Modes (p89)
+ROTATE            = "a"
+HOLD              = "b"
+FLASH             = "c"
+ROLL_UP           = "e"
+ROLL_DOWN         = "f"
+ROLL_LEFT         = "g"
+ROLL_RIGHT        = "h"
+WIPE_UP           = "i"
+WIPE_DOWN         = "j"
+WIPE_LEFT         = "k"
+WIPE_RIGHT        = "l"
+SCROLL            = "m"
+AUTOMODE          = "o"
+ROLL_IN           = "p"
+ROLL_OUT          = "q"
+WIPE_IN           = "r"
+WIPE_OUT          = "s"
+COMPRESSED_ROTATE = "t"  # only available on certain sign models
+EXPLODE           = "u"  # alpha 3.0 protocol
+CLOCK             = "v"  # alpha 3.0 protocol
+
+# Special modes
+TWINKLE           = "n0"
+SPARKLE           = "n1"
+SNOW              = "n2"
+INTERLOCK         = "n3"
+SWITCH            = "n4"
+SLIDE             = "n5"  # only Betabrite 1036
+SPRAY             = "n6"
+STARBURST         = "n7"
+WELCOME           = "n8"
+SLOT_MACHINE      = "n9"
+NEWS_FLASH        = "nA"  # only Betabrite 1036
+TRUMPET_ANIMATION = "nB"  # only Betabrite 1036
+CYCLE_COLORS      = "nC"  # only AlphaEclipse 3600
+
+# Special graphics (these display before the message)
+THANK_YOU         = "nS"
+NO_SMOKING        = "nU"
+DONT_DRINK_DRIVE  = "nV"
+RUNNING_ANIMAL    = "nW"
+FISH_ANIMATION    = "nW"
+FIREWORKS         = "nX"
+TURBO_CAR         = "nY"
+BALLOON_ANIMATION = "nY"
+CHERRY_BOMB       = "nZ"

+ 0 - 1
alphasign/packet.py

@@ -15,4 +15,3 @@ class Packet(object):
 
   def __repr__(self):
     return repr(self._pkt)
-

+ 7 - 0
alphasign/positions.py

@@ -0,0 +1,7 @@
+# Display positions
+MIDDLE_LINE = "\x20"
+TOP_LINE    = "\x22"
+BOTTOM_LINE = "\x26"
+FILL        = "\x30"
+LEFT        = "\x31"
+RIGHT       = "\x32"

+ 6 - 0
alphasign/speeds.py

@@ -0,0 +1,6 @@
+# Display speeds
+SPEED_1 = "\x15"
+SPEED_2 = "\x16"
+SPEED_3 = "\x17"
+SPEED_4 = "\x18"
+SPEED_5 = "\x19"

+ 0 - 25
alphasign/string.py

@@ -18,31 +18,6 @@ class String(object):
     self.size = size
     self.data = data
 
-  def allocate(self):
-    """Create a STRING.
-
-    This is necessary to allocate memory for the STRING on the sign
-
-    Args:
-      label: label of the STRING to create
-      size: size of the STRING to create, in bytes. 125 max.
-    """
-    size_hex = "%04x" % self.size
-    packet = Packet("%s%s%s%s%s%s%s%s%s%s%s%s%s" %
-                    (constants.WRITE_SPECIAL, "\$",
-                     "A",          # call label.. why does this matter?
-                     "A",          # text file type
-                     "U",          # this TEXT file is unlocked
-                     "0100",       # text file size in hex
-                     "FF",         # text file's start time (FF = always)
-                     "00",         # text file's stop time
-                     self.label,
-                     "B",          # string file type
-                     "L",          # this string file is locked
-                     size_hex,
-                     "0000"))      # padding
-    return packet
-
   def call(self):
     """Call a STRING.
 

+ 21 - 72
alphasign/text.py

@@ -1,90 +1,39 @@
 import constants
+import modes
+import positions
 from packet import Packet
 
 
-# Colors
-RED       = "\x1C1"
-GREEN     = "\x1C2"
-AMBER     = "\x1C3"
-DIM_RED   = "\x1C4"
-DIM_GREEN = "\x1C5"
-BROWN     = "\x1C6"
-ORANGE    = "\x1C7"
-YELLOW    = "\x1C8"
-RAINBOW_1 = "\x1C9"
-RAINBOW_2 = "\x1CA"
-COLOR_MIX = "\x1CB"
-AUTOCOLOR = "\x1CC"
-# TODO(ms): need support for RGB colors
-
-# Character sets
-FIVE_HIGH_STD      = "\x1A1"
-FIVE_STROKE        = "\x1A2"
-SEVEN_HIGH_STD     = "\x1A3"
-SEVEN_STROKE       = "\x1A4"
-SEVEN_HIGH_FANCY   = "\x1A5"
-TEN_HIGH_STD       = "\x1A6"
-SEVEN_SHADOW       = "\x1A7"
-FULL_HEIGHT_FANCY  = "\x1A8"
-FULL_HEIGHT_STD    = "\x1A9"
-SEVEN_SHADOW_FANCY = "\x1A:"
-FIVE_WIDE          = "\x1A;"
-SEVEN_WIDE         = "\x1A<"
-SEVEN_FANCY_WIDE   = "\x1A="
-WIDE_STROKE_FIVE   = "\x1A>"
-# Alpha 2.0 and 3.0 only
-FIVE_HIGH_CUST     = "\x1AW"
-SEVEN_HIGH_CUST    = "\x1AX"
-TEN_HIGH_CUST      = "\x1AY"
-FIFTEEN_HIGH_CUST  = "\x1AZ"
-
-# Extended characters
-UP_ARROW         = "\x08\x64"
-DOWN_ARROW       = "\x08\x65"
-LEFT_ARROW       = "\x08\x66"
-RIGHT_ARROW      = "\x08\x67"
-PACMAN           = "\x08\x68"
-SAIL_BOAT        = "\x08\x69"
-BALL             = "\x08\x6A"
-TELEPHONE        = "\x08\x6B"
-HEART            = "\x08\x6C"
-CAR              = "\x08\x6D"
-HANDICAP         = "\x08\x6E"
-RHINO            = "\x08\x6F"
-MUG              = "\x08\x70"
-SATELLITE_DISH   = "\x08\x71"
-COPYRIGHT_SYMBOL = "\x08\x72"
-MALE_SYMBOL      = "\x08\x73"
-FEMALE_SYMBOL    = "\x08\x74"
-BOTTLE           = "\x08\x75"
-DISKETTE         = "\x08\x76"
-PRINTER          = "\x08\x77"
-MUSICAL_NOTE     = "\x08\x78"
-INFINITY_SYMBOL  = "\x08\x79"
-
-# Display speeds
-SPEED_1 = "\x15"
-SPEED_2 = "\x16"
-SPEED_3 = "\x17"
-SPEED_4 = "\x18"
-SPEED_5 = "\x19"
-
-
 class Text(object):
-  def __init__(self, msg=None, label=None, position=None, mode=None):
+  def __init__(self, msg=None, label=None, size=None, position=None, mode=None):
     if label is None:
       label = "A"
+    if size is None:
+      size = 64
+    if len(msg) > size:
+      size = len(msg)
+    if size > 125:
+      size = 125
+    if size < 1:
+      size = 1
+    if position is None:
+      position = positions.MIDDLE_LINE
+    if mode is None:
+      mode = modes.ROTATE
+
     self.label = label
+    self.size = size
     self.msg = msg
-    # TODO(ms): need support for position and mode
+    self.position = position
+    self.mode = mode
 
   def __str__(self):
     # [WRITE_TEXT][File Label][ESC][Display Position][Mode Code]
     #   [Special Specifier][ASCII Message]
     packet = Packet("%s%s%s%s%s%s" % (constants.WRITE_TEXT, self.label,
                                       constants.ESC,
-                                      constants.positions["middle_line"],
-                                      constants.modes["rotate"],
+                                      self.position,
+                                      self.mode,
                                       self.msg))
     return str(packet)
 

+ 0 - 1
alphasign/time.py

@@ -48,4 +48,3 @@ class Time(object):
     byte = (format == 0) and "S" or "M"
     packet = Packet("%s%s%s" % (constants.WRITE_SPECIAL, "\x27", byte))
     return packet
-