_ Text::7Segment - Display characters in | segment style. |
This documentation refers to Text::7Segment version 0.0.1_0. This is alpha version, interface is likely to change slightly.
use Text::7Segment; my $seg7 = Text::7Segment->new(); $seg7->disp_str(':0123456789 abcdef ABCDEJ'); # all hex digits available in both upper and lower case $seg7->fancy_segments(1); $seg7->disp_str(':0123456789 abcdef ABCDEF'); # start display at 5th row from top and # 10th character from left my $seg7 = Text::7Segment->new( x_init => 10, y_init => 5); # 7-segment led clock my $seg7 = Text::7Segment->new( ); while (1) { chomp(my $time = qx/date '+%T'/); $seg7->x_curr(0); $seg7->y_curr(0); $seg7->disp_str($time); sleep 1; }
This module will display strings in 7 segment style. This is the common display style used in lcd calculators, digital watches etc.
The module takes only the hex digits([0-9A-Fa-f]), colon (:) and space characters (at present).
The intended application of this module is to emulate a seven segment clock or calculator display just for fun.
If you are still in the dark or need more info please refer to http://en.wikipedia.org/wiki/Seven-segment_display for lots of details on this display technology.
A Text::7Segment object is an instance of a 7-segment display. The following methods can be called on the object:
new()
Any getter or setter method names (see next item below) can be passed as hash keys with value to new
my $s = Text::7Segment->new(string => 'ffff', x_init => 5);
disp_str($str)
Display the string in 7 segment style. Each character in this implementation spans three text lines and 3 text columns, i.e a 3 x 3 grid on the text terminal. When all seven segments are on, we get the digit 8. By turning on only a subset of the seven segments, all the hex digits can be displayed (more or less - see fancy_segments below). The character used in the default mode are the ascii pipe(|) and under-score(_). In the fancy_segments mode, some other ascii characters are used to increase the expressiveness of the scheme - e.g by including the closing parens, a uppercase B can be distinguished from the digit 8. There are other possibilities as well - for example by replacing the pipes with forward slash(/) or back slash (\) can give the appearance of an italics font. But at this point we start encroaching on the ascii art domain, so it is better to stop while we can.
_ _ _ _ _ _ _ _ _ |_| |_) /_/ I_I [_] |_] !_! :_: |_; {_} |_| |_) /_/ I_I [_] |_] ! :_: |_; {_}
getter/setter methods
The getter/setter methods if called with an argument will set the value in the object, without an argument they will return the current value. The following methods can be used to change the state of the Text::7Segment object:
string - string to be displayed. Legal characters in the string are the character class [a..fA..F0..9: ] - i.e., hex digits, colon and space.
x_init - column number to start displaying from. The left x_init characters in a line of display will be blank for _all_ line (not just the first).
y_init - row number to start displaying from. The top y_init lines of display will be blank.
fancy_segments - Normally the 7 segment display can show the letters b and d in lowercase only because they can not be distinguished from the digits 8 and 0 respectively. This is a limitation of the hardware/design. However, since we are just emulating the 7-segment display, we are able to cheat by using extra characters. By default the 7 segment display in this module uses only the following characters: underscore(_), pipe(|) to diplay hex digits*. When set to a true value, the slash(/) and parens(\))are also used so the display can support displaying the letters [a-f] in both upper and lower case..
When fancy_segments is not set, uppercase b and d in string will be silently displayed in lowercase.
TODO: allow user to override any of the 7 segments or supply the whole %segments hash
If the string contains a character outside of the character class [a..fA..F0..9: ], it will not be displayed and a warning will be given. It will be a good idea to redirect the error output to somewhere other than the terminal if this is likely.
Warning: Code not defined for $chr
Any output to the terminal can wreak havoc with the curses display. If the string to be displayed can have an unsupported character, it would be better to redirect STDOUT to a file or another place away from STDOUT. E.g.,
perl seg7-disp.pl 2>/dev/null perl seg7-disp.pl 2>error.out
This module depends on the Curses module for displaying the output. It could be done without curses in a text terminal but then the input will have to be line bufferred. i.e the module should get the whole line of string at a time because it couldn't go back to top row after moving to the 2nd or 3rd.
It seems to get stuck at end of screen. Need to handle y_curr when it reaches max value.
Sometimes the terminal needs to be reset after a script using the module terminates. The terminal is still usable but the prompt gets shifted to the right. Just typing reset at the prompt and hitting enter seems to fix the issue for me.
Please report problems to manigrew (Manish.Grewal@gmail.com). Patches are welcome.
Following is a quick List of future enhancements off the top of my head based on what i have seen around the web for similar functionality.
- support different size of character - not just 3x3, e.g like bsd banner command - allow lookup func override if not already available and also good to have an example of how it should be subclassed. - use standard conventional letters for segments (a..g) in var names/comments - use colors
Immediate todo:
- mention defaults - say char class once and ref from there
manigrew (Manish.Grewal@gmail.com)
Copyright (c) 2013 manigre (Manish.Grewal@gmail.com). All rights reserved.
This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic. This program 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.
To install Text::7Segment, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Text::7Segment
CPAN shell
perl -MCPAN -e shell install Text::7Segment
For more information on module installation, please visit the detailed CPAN module installation guide.