123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554 |
- package Ezkey;
- use strict;
- use Data::Dumper;
- use IO::Handle;
- use Date::Format;
- use POSIX qw/floor/;
- require Exporter;
- our @ISA = qw/Exporter/;
- our @EXPORT = qw/%modes %graphics %positions/;
- our %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",
- "explode" => "u",
- "clock" => "v",
-
- "twinkle" => "n0",
- "sparkle" => "n1",
- "snow" => "n2",
- "interlock" => "n3",
- "switch" => "n4",
- "slide" => "n5",
- "spray" => "n6",
- "starburst" => "n7",
- "welcome" => "n8",
- "slot_machine" => "n9",
- "news_flash" => "nA",
- "trumpet_animation" => "nb",
- "cycle_colors" => "nC",
-
- "thank_you" => "nS",
- "no_smoking" => "nU",
- "dont_drive_drink" => "nV",
- "running_animal" => "nW",
- "fish_animation" => "nW",
- "fireworks" => "nX",
- "turbo_car" => "nY",
- "balloon_animation" => "nY",
- "cherry_bomb" => "nZ",
- );
- our %positions = (
- "middle_line" => "\x20",
- "top_line" => "\x22",
- "bottom_line" => "\x26",
- "fill" => "\x30",
- "left" => "\x31",
- "right" => "\x32",
- );
- our %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" => ">",
-
- "five_high_cust" => "W",
- "seven_high_cust" => "X",
- "ten_high_cust" => "Y",
- "fifteen_high_cust" => "Z",
- );
- our %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",
- );
- our %counters = (
- 1 => "z",
- 2 => "{",
- 3 => "|",
- 4 => "}",
- 5 => "-",
- );
- our %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",
- );
- use constant {
- WRITE_TEXT => "A",
- READ_TEXT => "B",
- WRITE_SPECIAL => "E",
- READ_SPECIAL => "F",
- WRITE_STRING => "G",
- READ_STRING => "H",
- WRITE_SMALL_DOTS => "I",
- READ_SMALL_DOTS => "J",
- WRITE_RGB_DOTS => "K",
- READ_RGB_DOTS => "L",
- WRITE_LARGE_DOTS => "M",
- READ_LARGE_DOTS => "N",
- WRITE_ALPHAVISION => "O",
- SET_TIMEOUT => "T",
- };
- use constant {
- NUL => "\x00",
- SOH => "\x01",
- STX => "\x02",
- ETX => "\x03",
- EOT => "\x04",
- BEL => "\x07",
- BS => "\x08",
- HT => "\x09",
- LF => "\x0A",
- NL => "\x0A",
- VT => "\x0B",
- CR => "\x0D",
- CAN => "\x18",
- SUB => "\x1A",
- ESC => "\x1B",
- };
- sub new {
- my($class,$device)=@_;
- my $self={
- "device" => $device,
- "type" => "Z",
- "address" => "00",
- "mode" => "rotate",
- "position" => "middle_line",
- "debug" => 0,
- };
- return bless $self,$class;
- }
- sub connect {
- my($this,$device)=@_;
- $device ||= $this->{device};
- if (!$device) {
- warn "No device specified. Defaulting to /dev/ttyS0.\n";
- $device = "/dev/ttyS0";
- }
-
- open(OUT,">",$device)
- or die "Could not open $device for output: $!\n";
- OUT->autoflush(1);
- open(IN,"<",$device)
- or die "Could not open $device for input: $!\n";
- IN->autoflush(1);
- }
- sub disconnect {
- my($this)=@_;
- close OUT;
- close IN;
- }
- sub _packet {
- my($this,$contents)=@_;
- return ((NUL x 5) . SOH . $this->{type} . $this->{address} . STX
- . $contents . EOT);
- }
- sub _write {
- my($this,$packet)=@_;
- die "Not connected to device. Use \$sign->connect().\n" if !OUT->opened;
- if ($this->{debug}) {
-
- my $hr = $packet;
-
-
-
-
- print "Writing packet: $hr\n";
- }
- print OUT $packet;
- }
- sub _read {
- my($this)=@_;
- my $data;
- sysread IN,$data,1024;
- return $data;
- }
- sub dec2hex {
- my($dec) = @_;
- return sprintf("%lx ", $dec );
- }
- sub hex2dec {
- return hex($_[0]);
- }
- sub set_mode {
- my($this,$mode)=@_;
- if ($modes{$mode}) {
- $this->{mode} = $mode;
- }
- else {
- warn "Warning: '$mode' is an invalid mode\n";
- }
- }
- sub get_mode {
- my($this)=@_;
- return $this->{mode};
- }
- sub set_position {
- my($this,$position)=@_;
- if ($positions{$position}) {
- $this->{position} = $position;
- }
- else {
- warn "Warning: '$position' is an invalid position\n";
- }
- }
- sub get_position {
- my($this)=@_;
- return $this->{position};
- }
- sub write_text {
- my($this,$msg,$label)=@_;
- $label ||= "A";
-
-
- my $packet = $this->_packet(WRITE_TEXT . $label . ESC
- . $positions{$this->{position}}
- . $modes{$this->{mode}} . $msg);
- $this->_write($packet);
- }
- sub read_text {
- my($this,$label)=@_;
- $label ||= "A";
- $this->_write($this->_packet(READ_TEXT . $label));
- return $this->_read();
- }
- sub create_string {
- my($this,$string_label,$string_size)=@_;
- $string_label ||= 1;
- $string_size = 125 if $string_size > 125;
- $string_size ||= 32;
- my $size_hex = hex($string_size);
- $size_hex = "0"x(4-length($size_hex)).$size_hex if length($size_hex) < 4;
- my $packet = $this->_packet(WRITE_SPECIAL . "\$"
- . "A"
- . "A"
- . "U"
- . "0100"
- . "FF"
- . "00"
- . $string_label
- . "B"
- . "L"
- . $size_hex
- . "0000"
- );
- $this->_write($packet);
- }
- sub write_string {
- my($this,$data,$label)=@_;
- $label ||= 1;
- my $packet = $this->_packet(WRITE_STRING . $label . $data);
- $this->_write($packet);
- }
- sub read_string {
- my($this,$label)=@_;
- $label ||= 1;
- my $packet = $this->_packet(READ_STRING . $label);
- $this->_write($packet);
- return $this->_read();
- }
- sub call_string {
- my($this,$string_label)=@_;
- $string_label ||= "1";
- return "\x10" . $string_label;
- }
- sub call_date {
- my($this,$format);
- $format ||= 0;
- $format = 0 if ($format < 0 || $format > 9);
- return "\x0B" . $format;
- }
- sub call_time {
- my($this)=@_;
- return "\x13";
- }
- sub clear_memory {
- my($this)=@_;
- my $packet = $this->_packet(WRITE_SPECIAL . "\$");
- $this->_write($packet);
- }
- sub beep {
- my($this,$frequency,$duration,$repeat)=@_;
- $frequency ||= "10";
- $duration ||= "2";
- $repeat ||= 0;
- my $packet = $this->_packet(WRITE_SPECIAL . "(2" . $frequency . $duration
- . $repeat);
- $this->_write($packet);
- }
- sub soft_reset {
- my($this)=@_;
- my $packet = $this->_packet(WRITE_SPECIAL . ",");
- $this->_write($packet);
- }
- sub set_day {
- my($this,$day)=@_;
- return -1 if ($day && ($day < 1 || $day > 7));
- $day ||= time2str("%w",time)+1;
- my $packet = $this->_packet(WRITE_SPECIAL . "&" . $day);
- $this->_write($packet);
- }
- sub set_date {
- my($this,$year,$month,$day)=@_;
- $year ||= time2str("%y",time);
- $month ||= time2str("%m",time);
- $day ||= time2str("%d",time);
- my $packet = $this->_packet(WRITE_SPECIAL . ";" . $month . $day . $year);
- $this->_write($packet);
- }
- sub set_time {
- my($this,$h,$m)=@_;
- $h = "" if ($h < 0 or $h > 23);
- $m = "" if ($m < 0 or $m > 59);
- $h ||= time2str("%H",time);
- $m ||= time2str("%M",time);
- my $packet = $this->_packet(WRITE_SPECIAL . "\x20" . $h . $m);
- $this->_write($packet);
- }
- sub set_time_format {
- my($this,$format)=@_;
- $format ||= 0;
- $format = 0 if ($format > 1 || $format < 0);
- my $byte = ($format == 0) ? "S" : "M";
- my $packet = $this->_packet(WRITE_SPECIAL . "\x27" . $byte);
- $this->_write($packet);
- }
- sub color {
- my($this,$color)=@_;
- $color = "autocolor" if !$colors{$color};
- return "\x1C" . $colors{$color};
- }
- sub charset {
- my($this,$charset)=@_;
- $charset = "five_high_std" if !$charsets{$charset};
- return "\x1A" . $charsets{$charset};
- }
- sub extchar {
- my($this,$extchar)=@_;
- $extchar = "left_arrow" if !$extchars{$extchar};
- return "\x08" . $extchars{$extchar};
- }
- sub spacing {
- my($this,$option)=@_;
- my $byte = ($option == 0) ? 0 : 1;
- return "\x1E" . $byte;
- }
- sub speed {
- my($this,$speed)=@_;
- $speed ||= 1;
- $speed = 1 if ($speed < 1 || $speed > 5);
- my $n = 20+$speed;
- return chr($n);
- }
- 1;
|