Browse Source

Making alphasign package.

Matt Sparks 15 years ago
parent
commit
d30dd3f11c
3 changed files with 195 additions and 207 deletions
  1. 0 0
      alphasign/__init__.py
  2. 26 207
      alphasign/alphasign.py
  3. 169 0
      alphasign/constants.py

+ 0 - 0
alphasign/__init__.py


+ 26 - 207
alphasign.py → alphasign/alphasign.py

@@ -4,179 +4,10 @@ import os
 import sys
 import serial
 
-
-class Alpha:
-  # 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",
-  }
-
-  # Character Sets
-  charsets = {
-    "five_high_std":      "1",
-    "five_stroke":        "2",
-    "seven_high_std":     "3",
-    "seven_stroke":       "4",
-    "seven_high_fancy":   "5",
-    "ten_high_std":       "6",
-    "seven_shadow":       "7",
-    "full_height_fancy":  "8",
-    "full_height_std":    "9",
-    "seven_shadow_fancy": ":",
-    "five_wide":          ";",
-    "seven_wide":         "<",
-    "seven_fancy_wide":   "=",
-    "wide_stroke_five":   ">",
-    # The following four only work on Alpha 2.0 and Alpha 3.0 protocols
-    "five_high_cust":     "W",
-    "seven_high_cust":    "X",
-    "ten_high_cust":      "Y",
-    "fifteen_high_cust":  "Z",
-  }
-
-  # Extended characters
-  extchars = {
-    "up_arrow":           "\x64",
-    "down_arrow":         "\x65",
-    "left_arrow":         "\x66",
-    "right_arrow":        "\x67",
-    "pacman":             "\x68",
-    "sail_boat":          "\x69",
-    "ball":               "\x6A",
-    "telephone":          "\x6B",
-    "heart":              "\x6C",
-    "car":                "\x6D",
-    "handicap":           "\x6E",
-    "rhino":              "\x6F",
-    "mug":                "\x70",
-    "satellite_dish":     "\x71",
-    "copyright_symbol":   "\x72",
-    "male_symbol":        "\x73",
-    "female_symbol":      "\x74",
-    "bottle":             "\x75",
-    "diskette":           "\x76",
-    "printer":            "\x77",
-    "musical_note":       "\x78",
-    "infinity_symbol":    "\x79",
-  }
-
-  # Counters
-  # We have 5 of them.
-  counters = {
-    1:                    "z",
-    2:                    "{",
-    3:                    "|",
-    4:                    "}",
-    5:                    "-",
-  }
-
-  # Colors
-  colors = {
-    "red":                "1",
-    "green":              "2",
-    "amber":              "3",
-    "dim_red":            "4",
-    "dim_green":          "5",
-    "brown":              "6",
-    "orange":             "7",
-    "yellow":             "8",
-    "rainbow_1":          "9",
-    "rainbow_2":          "A",
-    "color_mix":          "B",
-    "autocolor":          "C",
-  }
-
-  # Command Codes
-  WRITE_TEXT            = "A"  # Write TEXT file (p18)
-  READ_TEXT             = "B"  # Read TEXT file (p19)
-  WRITE_SPECIAL         = "E"  # Write SPECIAL FUNCTION commands (p21)
-  READ_SPECIAL          = "F"  # Read SPECIAL FUNCTION commands (p29)
-  WRITE_STRING          = "G"  # Write STRING (p37)
-  READ_STRING           = "H"  # Read STRING (p38)
-  WRITE_SMALL_DOTS      = "I"  # Write SMALL DOTS PICTURE file (p39)
-  READ_SMALL_DOTS       = "J"  # Read SMALL DOTS PICTURE file (p41)
-  WRITE_RGB_DOTS        = "K"  # Write RGB DOTS PICTURE file (p44)
-  READ_RGB_DOTS         = "L"  # Read RGB DOTS PICTURE file (p46)
-  WRITE_LARGE_DOTS      = "M"  # Write LARGE DOTS PICTURE file (p42)
-  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)
-
-  # Constants used in transmission packets
-  NUL                   = "\x00"  # NULL
-  SOH                   = "\x01"  # Start of Header
-  STX                   = "\x02"  # Start of TeXt (precedes a command code)
-  ETX                   = "\x03"  # End of TeXt
-  EOT                   = "\x04"  # End Of Transmission
-  #ENQ                   = "\x05"  # Enquiry
-  #ACK                   = "\x06"  # Acknowledge
-  BEL                   = "\x07"  # Bell
-  BS                    = "\x08"  # Backspace
-  HT                    = "\x09"  # Horizontal tab
-  LF                    = "\x0A"  # Line Feed
-  NL                    = "\x0A"  # New Line
-  VT                    = "\x0B"  # Vertical Tab
-  #FF                    = "\x0C"  # Form Feed
-  #NP                    = "\x0C"  # New Page
-  CR                    = "\x0D"  # Carriage Return
-  CAN                   = "\x18"  # Cancel
-  SUB                   = "\x1A"  # Substitute (select charset)
-  ESC                   = "\x1B"  # Escape character
+import constants
 
 
+class Alpha:
   def __init__(self, device="/dev/ttyS0"):
     self.device   = device
     self.type     = "Z"            # Type Code (see protocol)
@@ -206,8 +37,9 @@ class Alpha:
       self._conn.close()
 
   def _packet(self, contents):
-    pkt = ("%s%s%s%s%s%s%s" % (self.NUL * 5, self.SOH, self.type, self.address,
-                               self.STX, contents, self.EOT))
+    pkt = ("%s%s%s%s%s%s%s" % (constants.NUL * 5, constants.SOH, self.type,
+                               self.address, constants.STX, contents,
+                               constants.EOT))
     return pkt
 
   def _write(self, packet):
@@ -220,9 +52,10 @@ class Alpha:
   def write_text(self, msg, label="A"):
     # [WRITE_TEXT][File Label][ESC][Display Position][Mode Code]
     #   [Special Specifier][ASCII Message]
-    packet = self._packet("%s%s%s%s%s%s" % (self.WRITE_TEXT, label, self.ESC,
-                                            self.positions[self.position],
-                                            self.modes[self.mode],
+    packet = self._packet("%s%s%s%s%s%s" % (constants.WRITE_TEXT, label,
+                                            constants.ESC,
+                                            constants.positions[self.position],
+                                            constants.modes[self.mode],
                                             msg))
     self._write(packet)
 
@@ -240,7 +73,7 @@ class Alpha:
       string_size = 125
     size_hex = "%04x" % string_size
     packet = self._packet("%s%s%s%s%s%s%s%s%s%s%s%s%s" %
-                          (self.WRITE_SPECIAL, "\$",
+                          (constants.WRITE_SPECIAL, "\$",
                            "A",          # call label.. why does this matter?
                            "A",          # text file type
                            "U",          # this TEXT file is unlocked
@@ -261,7 +94,7 @@ class Alpha:
       data: data to write
       label: STRING label to write
     """
-    packet = self._packet("%s%s%s" % (self.WRITE_STRING, label, data))
+    packet = self._packet("%s%s%s" % (constants.WRITE_STRING, label, data))
     self._write(packet)
 
   def call_string(self, string_label="1"):
@@ -325,7 +158,7 @@ class Alpha:
   def clear_memory(self):
     """Clear the sign's memory.
     """
-    packet = self._packet("%s%s" % (self.WRITE_SPECIAL, "$"))
+    packet = self._packet("%s%s" % (constants.WRITE_SPECIAL, "$"))
     self._write(packet)
 
   def beep(self, frequency=0, duration=0.1, repeat=0):
@@ -352,7 +185,7 @@ class Alpha:
     elif repeat > 15:
       repeat = 15
 
-    packet = self._packet("%s%s%02X%X%X" % (self.WRITE_SPECIAL, "(2",
+    packet = self._packet("%s%s%02X%X%X" % (constants.WRITE_SPECIAL, "(2",
                                             frequency, duration, repeat))
     self._write(packet)
 
@@ -361,7 +194,7 @@ class Alpha:
 
     This is non-destructive and does not clear the sign's memory.
     """
-    packet = self._packet("%s%s" % (self.WRITE_SPECIAL, ","))
+    packet = self._packet("%s%s" % (constants.WRITE_SPECIAL, ","))
     self._write(packet)
 
   def set_day(self, day=None):
@@ -374,7 +207,7 @@ class Alpha:
     """
     if day is None or day < 1 or day > 7:
       day = datetime.datetime.today().weekday() + 1
-    packet = self._packet("%s%s%s" % (self.WRITE_SPECIAL, "&", day))
+    packet = self._packet("%s%s%s" % (constants.WRITE_SPECIAL, "&", day))
     self._write(packet)
 
   def set_date(self, year=None, month=None, day=None):
@@ -397,8 +230,8 @@ class Alpha:
     if day is None:
       day = today.day
 
-    packet = self._packet("%s%s%02d%02d%02d" % (self.WRITE_SPECIAL, ";",
-                                                 year, month, day))
+    packet = self._packet("%s%s%02d%02d%02d" % (constants.WRITE_SPECIAL, ";",
+                                                year, month, day))
     self._write(packet)
 
   def set_time(self, hour=None, minute=None):
@@ -416,8 +249,8 @@ class Alpha:
     if minute is None:
       minute = now.minute
 
-    packet = self._packet("%s%s%02d%02d" % (self.WRITE_SPECIAL, "\x20",
-                                             hour, minute))
+    packet = self._packet("%s%s%02d%02d" % (constants.WRITE_SPECIAL, "\x20",
+                                            hour, minute))
     self._write(packet)
 
   def set_time_format(self, format=1):
@@ -430,7 +263,7 @@ class Alpha:
     if format < 0 or format > 1:
       format = 1
     byte = (format == 0) and "S" or "M"
-    packet = this._packet("%s%s%s" % (self.WRITE_SPECIAL, "\x27", byte))
+    packet = this._packet("%s%s%s" % (constants.WRITE_SPECIAL, "\x27", byte))
     self._write(packet)
 
   def color(self, color="autocolor"):
@@ -442,9 +275,9 @@ class Alpha:
     Returns:
       FIXME
     """
-    if color not in self.colors:
+    if color not in constants.colors:
       color = "autocolor"
-    return "%s%s" % ("\x1C", self.colors[color])
+    return "%s%s" % ("\x1C", constants.colors[color])
 
   def charset(self, charset="five_high_std"):
     """Returns control code for a specified character set.
@@ -455,9 +288,9 @@ class Alpha:
     Returns:
       FIXME
     """
-    if charset not in self.charsets:
+    if charset not in constants.charsets:
       charset = "five_high_std"
-    return "%s%s" % ("\x1A", self.charsets[charset])
+    return "%s%s" % ("\x1A", constants.charsets[charset])
 
   def extchar(self, extchar="left_arrow"):
     """Returns control code for a specified extended character.
@@ -468,9 +301,9 @@ class Alpha:
     Returns:
       FIXME
     """
-    if extchar not in self.extchars:
+    if extchar not in constants.extchars:
       extchar = "left_arrow"
-    return "%s%s" % ("\x08", self.extchars[extchar])
+    return "%s%s" % ("\x08", constants.extchars[extchar])
 
   def spacing(self, option=0):
     """Returns control code to set the character spacing.
@@ -502,17 +335,3 @@ class Alpha:
     n = 20 + speed
     return chr(n)
 
-
-def main():
-  sign = Alpha("/dev/rfcomm0")
-  sign.debug = True
-  sign.connect()
-
-  sign.clear_memory()
-  sign.soft_reset()
-
-  sign.disconnect()
-
-
-if __name__ == "__main__":
-  main()

+ 169 - 0
alphasign/constants.py

@@ -0,0 +1,169 @@
+# 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",
+}
+
+# Character Sets
+charsets = {
+  "five_high_std":      "1",
+  "five_stroke":        "2",
+  "seven_high_std":     "3",
+  "seven_stroke":       "4",
+  "seven_high_fancy":   "5",
+  "ten_high_std":       "6",
+  "seven_shadow":       "7",
+  "full_height_fancy":  "8",
+  "full_height_std":    "9",
+  "seven_shadow_fancy": ":",
+  "five_wide":          ";",
+  "seven_wide":         "<",
+  "seven_fancy_wide":   "=",
+  "wide_stroke_five":   ">",
+  # The following four only work on Alpha 2.0 and Alpha 3.0 protocols
+  "five_high_cust":     "W",
+  "seven_high_cust":    "X",
+  "ten_high_cust":      "Y",
+  "fifteen_high_cust":  "Z",
+}
+
+# Extended characters
+extchars = {
+  "up_arrow":           "\x64",
+  "down_arrow":         "\x65",
+  "left_arrow":         "\x66",
+  "right_arrow":        "\x67",
+  "pacman":             "\x68",
+  "sail_boat":          "\x69",
+  "ball":               "\x6A",
+  "telephone":          "\x6B",
+  "heart":              "\x6C",
+  "car":                "\x6D",
+  "handicap":           "\x6E",
+  "rhino":              "\x6F",
+  "mug":                "\x70",
+  "satellite_dish":     "\x71",
+  "copyright_symbol":   "\x72",
+  "male_symbol":        "\x73",
+  "female_symbol":      "\x74",
+  "bottle":             "\x75",
+  "diskette":           "\x76",
+  "printer":            "\x77",
+  "musical_note":       "\x78",
+  "infinity_symbol":    "\x79",
+}
+
+# Counters
+# We have 5 of them.
+counters = {
+  1:                    "z",
+  2:                    "{",
+  3:                    "|",
+  4:                    "}",
+  5:                    "-",
+}
+
+# Colors
+colors = {
+  "red":                "1",
+  "green":              "2",
+  "amber":              "3",
+  "dim_red":            "4",
+  "dim_green":          "5",
+  "brown":              "6",
+  "orange":             "7",
+  "yellow":             "8",
+  "rainbow_1":          "9",
+  "rainbow_2":          "A",
+  "color_mix":          "B",
+  "autocolor":          "C",
+}
+
+# Command Codes
+WRITE_TEXT            = "A"  # Write TEXT file (p18)
+READ_TEXT             = "B"  # Read TEXT file (p19)
+WRITE_SPECIAL         = "E"  # Write SPECIAL FUNCTION commands (p21)
+READ_SPECIAL          = "F"  # Read SPECIAL FUNCTION commands (p29)
+WRITE_STRING          = "G"  # Write STRING (p37)
+READ_STRING           = "H"  # Read STRING (p38)
+WRITE_SMALL_DOTS      = "I"  # Write SMALL DOTS PICTURE file (p39)
+READ_SMALL_DOTS       = "J"  # Read SMALL DOTS PICTURE file (p41)
+WRITE_RGB_DOTS        = "K"  # Write RGB DOTS PICTURE file (p44)
+READ_RGB_DOTS         = "L"  # Read RGB DOTS PICTURE file (p46)
+WRITE_LARGE_DOTS      = "M"  # Write LARGE DOTS PICTURE file (p42)
+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)
+
+# Constants used in transmission packets
+NUL                   = "\x00"  # NULL
+SOH                   = "\x01"  # Start of Header
+STX                   = "\x02"  # Start of TeXt (precedes a command code)
+ETX                   = "\x03"  # End of TeXt
+EOT                   = "\x04"  # End Of Transmission
+#ENQ                   = "\x05"  # Enquiry
+#ACK                   = "\x06"  # Acknowledge
+BEL                   = "\x07"  # Bell
+BS                    = "\x08"  # Backspace
+HT                    = "\x09"  # Horizontal tab
+LF                    = "\x0A"  # Line Feed
+NL                    = "\x0A"  # New Line
+VT                    = "\x0B"  # Vertical Tab
+#FF                    = "\x0C"  # Form Feed
+#NP                    = "\x0C"  # New Page
+CR                    = "\x0D"  # Carriage Return
+CAN                   = "\x18"  # Cancel
+SUB                   = "\x1A"  # Substitute (select charset)
+ESC                   = "\x1B"  # Escape character