@@ -27,114 +27,126 @@ use core::fmt;
27
27
use hal:: blocking:: delay:: DelayMs ;
28
28
use hal:: digital:: OutputPin ;
29
29
30
+ /// A bitmap-display character, which is either an 8x8 bitmap or a special character
31
+ #[ derive( Clone , Copy ) ]
32
+ pub enum BitmapCharacter {
33
+ /// An 8x8 bitmap character
34
+ Bitmapped ( [ u8 ; 8 ] ) ,
35
+ /// A newline character which causes the cursor to jump to the next line
36
+ Newline ,
37
+ }
38
+
30
39
/// A trait to convert from a character to 8x8 bitmap
31
40
pub trait CharacterBitmap < T > {
32
- /// Turn input of type T into a displayable 8x8 bitmap
33
- fn to_bitmap ( input : T ) -> [ u8 ; 8 ] ;
41
+ /// Turn input of type T into a displayable 8x8 bitmap or special character
42
+ fn to_bitmap ( input : T ) -> BitmapCharacter ;
34
43
}
35
44
36
45
/// A 7x7 font shamelessly borrowed from https://github.com/techninja/MarioChron/
37
46
impl < DI > CharacterBitmap < char > for TerminalMode < DI >
38
47
where
39
48
DI : DisplayInterface ,
40
49
{
41
- fn to_bitmap ( input : char ) -> [ u8 ; 8 ] {
50
+ fn to_bitmap ( input : char ) -> BitmapCharacter {
51
+ use BitmapCharacter :: { Bitmapped , Newline } ;
52
+
42
53
// Populate the array with the data from the character array at the right index
43
54
match input {
44
- '!' => [ 0x00 , 0x00 , 0x5F , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
45
- '"' => [ 0x00 , 0x07 , 0x00 , 0x07 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
46
- '#' => [ 0x14 , 0x7F , 0x14 , 0x7F , 0x14 , 0x00 , 0x00 , 0x00 ] ,
47
- '$' => [ 0x24 , 0x2A , 0x7F , 0x2A , 0x12 , 0x00 , 0x00 , 0x00 ] ,
48
- '%' => [ 0x23 , 0x13 , 0x08 , 0x64 , 0x62 , 0x00 , 0x00 , 0x00 ] ,
49
- '&' => [ 0x36 , 0x49 , 0x55 , 0x22 , 0x50 , 0x00 , 0x00 , 0x00 ] ,
50
- '\'' => [ 0x00 , 0x05 , 0x03 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
51
- '(' => [ 0x00 , 0x1C , 0x22 , 0x41 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
52
- ')' => [ 0x00 , 0x41 , 0x22 , 0x1C , 0x00 , 0x00 , 0x00 , 0x00 ] ,
53
- '*' => [ 0x08 , 0x2A , 0x1C , 0x2A , 0x08 , 0x00 , 0x00 , 0x00 ] ,
54
- '+' => [ 0x08 , 0x08 , 0x3E , 0x08 , 0x08 , 0x00 , 0x00 , 0x00 ] ,
55
- ',' => [ 0x00 , 0x50 , 0x30 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
56
- '-' => [ 0x00 , 0x18 , 0x18 , 0x18 , 0x18 , 0x18 , 0x00 , 0x00 ] ,
57
- '.' => [ 0x00 , 0x60 , 0x60 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
58
- '/' => [ 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x00 , 0x00 , 0x00 ] ,
59
- '0' => [ 0x1C , 0x3E , 0x61 , 0x41 , 0x43 , 0x3E , 0x1C , 0x00 ] ,
60
- '1' => [ 0x40 , 0x42 , 0x7F , 0x7F , 0x40 , 0x40 , 0x00 , 0x00 ] ,
61
- '2' => [ 0x62 , 0x73 , 0x79 , 0x59 , 0x5D , 0x4F , 0x46 , 0x00 ] ,
62
- '3' => [ 0x20 , 0x61 , 0x49 , 0x4D , 0x4F , 0x7B , 0x31 , 0x00 ] ,
63
- '4' => [ 0x18 , 0x1C , 0x16 , 0x13 , 0x7F , 0x7F , 0x10 , 0x00 ] ,
64
- '5' => [ 0x27 , 0x67 , 0x45 , 0x45 , 0x45 , 0x7D , 0x38 , 0x00 ] ,
65
- '6' => [ 0x3C , 0x7E , 0x4B , 0x49 , 0x49 , 0x79 , 0x30 , 0x00 ] ,
66
- '7' => [ 0x03 , 0x03 , 0x71 , 0x79 , 0x0D , 0x07 , 0x03 , 0x00 ] ,
67
- '8' => [ 0x36 , 0x7F , 0x49 , 0x49 , 0x49 , 0x7F , 0x36 , 0x00 ] ,
68
- '9' => [ 0x06 , 0x4F , 0x49 , 0x49 , 0x69 , 0x3F , 0x1E , 0x00 ] ,
69
- ':' => [ 0x00 , 0x36 , 0x36 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
70
- ';' => [ 0x00 , 0x56 , 0x36 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
71
- '<' => [ 0x00 , 0x08 , 0x14 , 0x22 , 0x41 , 0x00 , 0x00 , 0x00 ] ,
72
- '=' => [ 0x14 , 0x14 , 0x14 , 0x14 , 0x14 , 0x00 , 0x00 , 0x00 ] ,
73
- '>' => [ 0x41 , 0x22 , 0x14 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
74
- '?' => [ 0x02 , 0x01 , 0x51 , 0x09 , 0x06 , 0x00 , 0x00 , 0x00 ] ,
75
- '@' => [ 0x32 , 0x49 , 0x79 , 0x41 , 0x3E , 0x00 , 0x00 , 0x00 ] ,
76
- 'A' => [ 0x7E , 0x11 , 0x11 , 0x11 , 0x7E , 0x00 , 0x00 , 0x00 ] ,
77
- 'B' => [ 0x7F , 0x49 , 0x49 , 0x49 , 0x36 , 0x00 , 0x00 , 0x00 ] ,
78
- 'C' => [ 0x3E , 0x41 , 0x41 , 0x41 , 0x22 , 0x00 , 0x00 , 0x00 ] ,
79
- 'D' => [ 0x7F , 0x7F , 0x41 , 0x41 , 0x63 , 0x3E , 0x1C , 0x00 ] ,
80
- 'E' => [ 0x7F , 0x49 , 0x49 , 0x49 , 0x41 , 0x00 , 0x00 , 0x00 ] ,
81
- 'F' => [ 0x7F , 0x09 , 0x09 , 0x01 , 0x01 , 0x00 , 0x00 , 0x00 ] ,
82
- 'G' => [ 0x3E , 0x41 , 0x41 , 0x51 , 0x32 , 0x00 , 0x00 , 0x00 ] ,
83
- 'H' => [ 0x7F , 0x08 , 0x08 , 0x08 , 0x7F , 0x00 , 0x00 , 0x00 ] ,
84
- 'I' => [ 0x00 , 0x41 , 0x7F , 0x41 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
85
- 'J' => [ 0x20 , 0x40 , 0x41 , 0x3F , 0x01 , 0x00 , 0x00 , 0x00 ] ,
86
- 'K' => [ 0x7F , 0x08 , 0x14 , 0x22 , 0x41 , 0x00 , 0x00 , 0x00 ] ,
87
- 'L' => [ 0x7F , 0x7F , 0x40 , 0x40 , 0x40 , 0x40 , 0x00 , 0x00 ] ,
88
- 'M' => [ 0x7F , 0x02 , 0x04 , 0x02 , 0x7F , 0x00 , 0x00 , 0x00 ] ,
89
- 'N' => [ 0x7F , 0x04 , 0x08 , 0x10 , 0x7F , 0x00 , 0x00 , 0x00 ] ,
90
- 'O' => [ 0x3E , 0x7F , 0x41 , 0x41 , 0x41 , 0x7F , 0x3E , 0x00 ] ,
91
- 'P' => [ 0x7F , 0x09 , 0x09 , 0x09 , 0x06 , 0x00 , 0x00 , 0x00 ] ,
92
- 'Q' => [ 0x3E , 0x41 , 0x51 , 0x21 , 0x5E , 0x00 , 0x00 , 0x00 ] ,
93
- 'R' => [ 0x7F , 0x7F , 0x11 , 0x31 , 0x79 , 0x6F , 0x4E , 0x00 ] ,
94
- 'S' => [ 0x46 , 0x49 , 0x49 , 0x49 , 0x31 , 0x00 , 0x00 , 0x00 ] ,
95
- 'T' => [ 0x01 , 0x01 , 0x7F , 0x01 , 0x01 , 0x00 , 0x00 , 0x00 ] ,
96
- 'U' => [ 0x3F , 0x40 , 0x40 , 0x40 , 0x3F , 0x00 , 0x00 , 0x00 ] ,
97
- 'V' => [ 0x1F , 0x20 , 0x40 , 0x20 , 0x1F , 0x00 , 0x00 , 0x00 ] ,
98
- 'W' => [ 0x7F , 0x7F , 0x38 , 0x1C , 0x38 , 0x7F , 0x7F , 0x00 ] ,
99
- 'X' => [ 0x63 , 0x14 , 0x08 , 0x14 , 0x63 , 0x00 , 0x00 , 0x00 ] ,
100
- 'Y' => [ 0x03 , 0x04 , 0x78 , 0x04 , 0x03 , 0x00 , 0x00 , 0x00 ] ,
101
- 'Z' => [ 0x61 , 0x51 , 0x49 , 0x45 , 0x43 , 0x00 , 0x00 , 0x00 ] ,
102
- '[' => [ 0x00 , 0x00 , 0x7F , 0x41 , 0x41 , 0x00 , 0x00 , 0x00 ] ,
103
- '\\' => [ 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x00 , 0x00 , 0x00 ] ,
104
- ']' => [ 0x41 , 0x41 , 0x7F , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
105
- '^' => [ 0x04 , 0x02 , 0x01 , 0x02 , 0x04 , 0x00 , 0x00 , 0x00 ] ,
106
- '_' => [ 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , 0x00 , 0x00 , 0x00 ] ,
107
- '`' => [ 0x00 , 0x01 , 0x02 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
108
- 'a' => [ 0x20 , 0x54 , 0x54 , 0x54 , 0x78 , 0x00 , 0x00 , 0x00 ] ,
109
- 'b' => [ 0x7F , 0x48 , 0x44 , 0x44 , 0x38 , 0x00 , 0x00 , 0x00 ] ,
110
- 'c' => [ 0x38 , 0x44 , 0x44 , 0x44 , 0x20 , 0x00 , 0x00 , 0x00 ] ,
111
- 'd' => [ 0x38 , 0x44 , 0x44 , 0x48 , 0x7F , 0x00 , 0x00 , 0x00 ] ,
112
- 'e' => [ 0x38 , 0x54 , 0x54 , 0x54 , 0x18 , 0x00 , 0x00 , 0x00 ] ,
113
- 'f' => [ 0x08 , 0x7E , 0x09 , 0x01 , 0x02 , 0x00 , 0x00 , 0x00 ] ,
114
- 'g' => [ 0x08 , 0x14 , 0x54 , 0x54 , 0x3C , 0x00 , 0x00 , 0x00 ] ,
115
- 'h' => [ 0x7F , 0x08 , 0x04 , 0x04 , 0x78 , 0x00 , 0x00 , 0x00 ] ,
116
- 'i' => [ 0x00 , 0x44 , 0x7D , 0x40 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
117
- 'j' => [ 0x20 , 0x40 , 0x44 , 0x3D , 0x00 , 0x00 , 0x00 , 0x00 ] ,
118
- 'k' => [ 0x00 , 0x7F , 0x10 , 0x28 , 0x44 , 0x00 , 0x00 , 0x00 ] ,
119
- 'l' => [ 0x00 , 0x41 , 0x7F , 0x40 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
120
- 'm' => [ 0x7C , 0x04 , 0x18 , 0x04 , 0x78 , 0x00 , 0x00 , 0x00 ] ,
121
- 'n' => [ 0x7C , 0x08 , 0x04 , 0x04 , 0x78 , 0x00 , 0x00 , 0x00 ] ,
122
- 'o' => [ 0x38 , 0x44 , 0x44 , 0x44 , 0x38 , 0x00 , 0x00 , 0x00 ] ,
123
- 'p' => [ 0x7C , 0x14 , 0x14 , 0x14 , 0x08 , 0x00 , 0x00 , 0x00 ] ,
124
- 'q' => [ 0x08 , 0x14 , 0x14 , 0x18 , 0x7C , 0x00 , 0x00 , 0x00 ] ,
125
- 'r' => [ 0x7C , 0x08 , 0x04 , 0x04 , 0x08 , 0x00 , 0x00 , 0x00 ] ,
126
- 's' => [ 0x48 , 0x54 , 0x54 , 0x54 , 0x20 , 0x00 , 0x00 , 0x00 ] ,
127
- 't' => [ 0x04 , 0x3F , 0x44 , 0x40 , 0x20 , 0x00 , 0x00 , 0x00 ] ,
128
- 'u' => [ 0x3C , 0x40 , 0x40 , 0x20 , 0x7C , 0x00 , 0x00 , 0x00 ] ,
129
- 'v' => [ 0x1C , 0x20 , 0x40 , 0x20 , 0x1C , 0x00 , 0x00 , 0x00 ] ,
130
- 'w' => [ 0x3C , 0x40 , 0x30 , 0x40 , 0x3C , 0x00 , 0x00 , 0x00 ] ,
131
- 'x' => [ 0x00 , 0x44 , 0x28 , 0x10 , 0x28 , 0x44 , 0x00 , 0x00 ] ,
132
- 'y' => [ 0x0C , 0x50 , 0x50 , 0x50 , 0x3C , 0x00 , 0x00 , 0x00 ] ,
133
- 'z' => [ 0x44 , 0x64 , 0x54 , 0x4C , 0x44 , 0x00 , 0x00 , 0x00 ] ,
134
- '{' => [ 0x00 , 0x08 , 0x36 , 0x41 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
135
- '|' => [ 0x00 , 0x00 , 0x7F , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
136
- '}' => [ 0x00 , 0x41 , 0x36 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
137
- _ => [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ,
55
+ '\n' => Newline ,
56
+ '!' => Bitmapped ( [ 0x00 , 0x00 , 0x5F , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
57
+ '"' => Bitmapped ( [ 0x00 , 0x07 , 0x00 , 0x07 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
58
+ '#' => Bitmapped ( [ 0x14 , 0x7F , 0x14 , 0x7F , 0x14 , 0x00 , 0x00 , 0x00 ] ) ,
59
+ '$' => Bitmapped ( [ 0x24 , 0x2A , 0x7F , 0x2A , 0x12 , 0x00 , 0x00 , 0x00 ] ) ,
60
+ '%' => Bitmapped ( [ 0x23 , 0x13 , 0x08 , 0x64 , 0x62 , 0x00 , 0x00 , 0x00 ] ) ,
61
+ '&' => Bitmapped ( [ 0x36 , 0x49 , 0x55 , 0x22 , 0x50 , 0x00 , 0x00 , 0x00 ] ) ,
62
+ '\'' => Bitmapped ( [ 0x00 , 0x05 , 0x03 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
63
+ '(' => Bitmapped ( [ 0x00 , 0x1C , 0x22 , 0x41 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
64
+ ')' => Bitmapped ( [ 0x00 , 0x41 , 0x22 , 0x1C , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
65
+ '*' => Bitmapped ( [ 0x08 , 0x2A , 0x1C , 0x2A , 0x08 , 0x00 , 0x00 , 0x00 ] ) ,
66
+ '+' => Bitmapped ( [ 0x08 , 0x08 , 0x3E , 0x08 , 0x08 , 0x00 , 0x00 , 0x00 ] ) ,
67
+ ',' => Bitmapped ( [ 0x00 , 0x50 , 0x30 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
68
+ '-' => Bitmapped ( [ 0x00 , 0x18 , 0x18 , 0x18 , 0x18 , 0x18 , 0x00 , 0x00 ] ) ,
69
+ '.' => Bitmapped ( [ 0x00 , 0x60 , 0x60 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
70
+ '/' => Bitmapped ( [ 0x20 , 0x10 , 0x08 , 0x04 , 0x02 , 0x00 , 0x00 , 0x00 ] ) ,
71
+ '0' => Bitmapped ( [ 0x1C , 0x3E , 0x61 , 0x41 , 0x43 , 0x3E , 0x1C , 0x00 ] ) ,
72
+ '1' => Bitmapped ( [ 0x40 , 0x42 , 0x7F , 0x7F , 0x40 , 0x40 , 0x00 , 0x00 ] ) ,
73
+ '2' => Bitmapped ( [ 0x62 , 0x73 , 0x79 , 0x59 , 0x5D , 0x4F , 0x46 , 0x00 ] ) ,
74
+ '3' => Bitmapped ( [ 0x20 , 0x61 , 0x49 , 0x4D , 0x4F , 0x7B , 0x31 , 0x00 ] ) ,
75
+ '4' => Bitmapped ( [ 0x18 , 0x1C , 0x16 , 0x13 , 0x7F , 0x7F , 0x10 , 0x00 ] ) ,
76
+ '5' => Bitmapped ( [ 0x27 , 0x67 , 0x45 , 0x45 , 0x45 , 0x7D , 0x38 , 0x00 ] ) ,
77
+ '6' => Bitmapped ( [ 0x3C , 0x7E , 0x4B , 0x49 , 0x49 , 0x79 , 0x30 , 0x00 ] ) ,
78
+ '7' => Bitmapped ( [ 0x03 , 0x03 , 0x71 , 0x79 , 0x0D , 0x07 , 0x03 , 0x00 ] ) ,
79
+ '8' => Bitmapped ( [ 0x36 , 0x7F , 0x49 , 0x49 , 0x49 , 0x7F , 0x36 , 0x00 ] ) ,
80
+ '9' => Bitmapped ( [ 0x06 , 0x4F , 0x49 , 0x49 , 0x69 , 0x3F , 0x1E , 0x00 ] ) ,
81
+ ':' => Bitmapped ( [ 0x00 , 0x36 , 0x36 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
82
+ ';' => Bitmapped ( [ 0x00 , 0x56 , 0x36 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
83
+ '<' => Bitmapped ( [ 0x00 , 0x08 , 0x14 , 0x22 , 0x41 , 0x00 , 0x00 , 0x00 ] ) ,
84
+ '=' => Bitmapped ( [ 0x14 , 0x14 , 0x14 , 0x14 , 0x14 , 0x00 , 0x00 , 0x00 ] ) ,
85
+ '>' => Bitmapped ( [ 0x41 , 0x22 , 0x14 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
86
+ '?' => Bitmapped ( [ 0x02 , 0x01 , 0x51 , 0x09 , 0x06 , 0x00 , 0x00 , 0x00 ] ) ,
87
+ '@' => Bitmapped ( [ 0x32 , 0x49 , 0x79 , 0x41 , 0x3E , 0x00 , 0x00 , 0x00 ] ) ,
88
+ 'A' => Bitmapped ( [ 0x7E , 0x11 , 0x11 , 0x11 , 0x7E , 0x00 , 0x00 , 0x00 ] ) ,
89
+ 'B' => Bitmapped ( [ 0x7F , 0x49 , 0x49 , 0x49 , 0x36 , 0x00 , 0x00 , 0x00 ] ) ,
90
+ 'C' => Bitmapped ( [ 0x3E , 0x41 , 0x41 , 0x41 , 0x22 , 0x00 , 0x00 , 0x00 ] ) ,
91
+ 'D' => Bitmapped ( [ 0x7F , 0x7F , 0x41 , 0x41 , 0x63 , 0x3E , 0x1C , 0x00 ] ) ,
92
+ 'E' => Bitmapped ( [ 0x7F , 0x49 , 0x49 , 0x49 , 0x41 , 0x00 , 0x00 , 0x00 ] ) ,
93
+ 'F' => Bitmapped ( [ 0x7F , 0x09 , 0x09 , 0x01 , 0x01 , 0x00 , 0x00 , 0x00 ] ) ,
94
+ 'G' => Bitmapped ( [ 0x3E , 0x41 , 0x41 , 0x51 , 0x32 , 0x00 , 0x00 , 0x00 ] ) ,
95
+ 'H' => Bitmapped ( [ 0x7F , 0x08 , 0x08 , 0x08 , 0x7F , 0x00 , 0x00 , 0x00 ] ) ,
96
+ 'I' => Bitmapped ( [ 0x00 , 0x41 , 0x7F , 0x41 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
97
+ 'J' => Bitmapped ( [ 0x20 , 0x40 , 0x41 , 0x3F , 0x01 , 0x00 , 0x00 , 0x00 ] ) ,
98
+ 'K' => Bitmapped ( [ 0x7F , 0x08 , 0x14 , 0x22 , 0x41 , 0x00 , 0x00 , 0x00 ] ) ,
99
+ 'L' => Bitmapped ( [ 0x7F , 0x7F , 0x40 , 0x40 , 0x40 , 0x40 , 0x00 , 0x00 ] ) ,
100
+ 'M' => Bitmapped ( [ 0x7F , 0x02 , 0x04 , 0x02 , 0x7F , 0x00 , 0x00 , 0x00 ] ) ,
101
+ 'N' => Bitmapped ( [ 0x7F , 0x04 , 0x08 , 0x10 , 0x7F , 0x00 , 0x00 , 0x00 ] ) ,
102
+ 'O' => Bitmapped ( [ 0x3E , 0x7F , 0x41 , 0x41 , 0x41 , 0x7F , 0x3E , 0x00 ] ) ,
103
+ 'P' => Bitmapped ( [ 0x7F , 0x09 , 0x09 , 0x09 , 0x06 , 0x00 , 0x00 , 0x00 ] ) ,
104
+ 'Q' => Bitmapped ( [ 0x3E , 0x41 , 0x51 , 0x21 , 0x5E , 0x00 , 0x00 , 0x00 ] ) ,
105
+ 'R' => Bitmapped ( [ 0x7F , 0x7F , 0x11 , 0x31 , 0x79 , 0x6F , 0x4E , 0x00 ] ) ,
106
+ 'S' => Bitmapped ( [ 0x46 , 0x49 , 0x49 , 0x49 , 0x31 , 0x00 , 0x00 , 0x00 ] ) ,
107
+ 'T' => Bitmapped ( [ 0x01 , 0x01 , 0x7F , 0x01 , 0x01 , 0x00 , 0x00 , 0x00 ] ) ,
108
+ 'U' => Bitmapped ( [ 0x3F , 0x40 , 0x40 , 0x40 , 0x3F , 0x00 , 0x00 , 0x00 ] ) ,
109
+ 'V' => Bitmapped ( [ 0x1F , 0x20 , 0x40 , 0x20 , 0x1F , 0x00 , 0x00 , 0x00 ] ) ,
110
+ 'W' => Bitmapped ( [ 0x7F , 0x7F , 0x38 , 0x1C , 0x38 , 0x7F , 0x7F , 0x00 ] ) ,
111
+ 'X' => Bitmapped ( [ 0x63 , 0x14 , 0x08 , 0x14 , 0x63 , 0x00 , 0x00 , 0x00 ] ) ,
112
+ 'Y' => Bitmapped ( [ 0x03 , 0x04 , 0x78 , 0x04 , 0x03 , 0x00 , 0x00 , 0x00 ] ) ,
113
+ 'Z' => Bitmapped ( [ 0x61 , 0x51 , 0x49 , 0x45 , 0x43 , 0x00 , 0x00 , 0x00 ] ) ,
114
+ '[' => Bitmapped ( [ 0x00 , 0x00 , 0x7F , 0x41 , 0x41 , 0x00 , 0x00 , 0x00 ] ) ,
115
+ '\\' => Bitmapped ( [ 0x02 , 0x04 , 0x08 , 0x10 , 0x20 , 0x00 , 0x00 , 0x00 ] ) ,
116
+ ']' => Bitmapped ( [ 0x41 , 0x41 , 0x7F , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
117
+ '^' => Bitmapped ( [ 0x04 , 0x02 , 0x01 , 0x02 , 0x04 , 0x00 , 0x00 , 0x00 ] ) ,
118
+ '_' => Bitmapped ( [ 0x40 , 0x40 , 0x40 , 0x40 , 0x40 , 0x00 , 0x00 , 0x00 ] ) ,
119
+ '`' => Bitmapped ( [ 0x00 , 0x01 , 0x02 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
120
+ 'a' => Bitmapped ( [ 0x20 , 0x54 , 0x54 , 0x54 , 0x78 , 0x00 , 0x00 , 0x00 ] ) ,
121
+ 'b' => Bitmapped ( [ 0x7F , 0x48 , 0x44 , 0x44 , 0x38 , 0x00 , 0x00 , 0x00 ] ) ,
122
+ 'c' => Bitmapped ( [ 0x38 , 0x44 , 0x44 , 0x44 , 0x20 , 0x00 , 0x00 , 0x00 ] ) ,
123
+ 'd' => Bitmapped ( [ 0x38 , 0x44 , 0x44 , 0x48 , 0x7F , 0x00 , 0x00 , 0x00 ] ) ,
124
+ 'e' => Bitmapped ( [ 0x38 , 0x54 , 0x54 , 0x54 , 0x18 , 0x00 , 0x00 , 0x00 ] ) ,
125
+ 'f' => Bitmapped ( [ 0x08 , 0x7E , 0x09 , 0x01 , 0x02 , 0x00 , 0x00 , 0x00 ] ) ,
126
+ 'g' => Bitmapped ( [ 0x08 , 0x14 , 0x54 , 0x54 , 0x3C , 0x00 , 0x00 , 0x00 ] ) ,
127
+ 'h' => Bitmapped ( [ 0x7F , 0x08 , 0x04 , 0x04 , 0x78 , 0x00 , 0x00 , 0x00 ] ) ,
128
+ 'i' => Bitmapped ( [ 0x00 , 0x44 , 0x7D , 0x40 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
129
+ 'j' => Bitmapped ( [ 0x20 , 0x40 , 0x44 , 0x3D , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
130
+ 'k' => Bitmapped ( [ 0x00 , 0x7F , 0x10 , 0x28 , 0x44 , 0x00 , 0x00 , 0x00 ] ) ,
131
+ 'l' => Bitmapped ( [ 0x00 , 0x41 , 0x7F , 0x40 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
132
+ 'm' => Bitmapped ( [ 0x7C , 0x04 , 0x18 , 0x04 , 0x78 , 0x00 , 0x00 , 0x00 ] ) ,
133
+ 'n' => Bitmapped ( [ 0x7C , 0x08 , 0x04 , 0x04 , 0x78 , 0x00 , 0x00 , 0x00 ] ) ,
134
+ 'o' => Bitmapped ( [ 0x38 , 0x44 , 0x44 , 0x44 , 0x38 , 0x00 , 0x00 , 0x00 ] ) ,
135
+ 'p' => Bitmapped ( [ 0x7C , 0x14 , 0x14 , 0x14 , 0x08 , 0x00 , 0x00 , 0x00 ] ) ,
136
+ 'q' => Bitmapped ( [ 0x08 , 0x14 , 0x14 , 0x18 , 0x7C , 0x00 , 0x00 , 0x00 ] ) ,
137
+ 'r' => Bitmapped ( [ 0x7C , 0x08 , 0x04 , 0x04 , 0x08 , 0x00 , 0x00 , 0x00 ] ) ,
138
+ 's' => Bitmapped ( [ 0x48 , 0x54 , 0x54 , 0x54 , 0x20 , 0x00 , 0x00 , 0x00 ] ) ,
139
+ 't' => Bitmapped ( [ 0x04 , 0x3F , 0x44 , 0x40 , 0x20 , 0x00 , 0x00 , 0x00 ] ) ,
140
+ 'u' => Bitmapped ( [ 0x3C , 0x40 , 0x40 , 0x20 , 0x7C , 0x00 , 0x00 , 0x00 ] ) ,
141
+ 'v' => Bitmapped ( [ 0x1C , 0x20 , 0x40 , 0x20 , 0x1C , 0x00 , 0x00 , 0x00 ] ) ,
142
+ 'w' => Bitmapped ( [ 0x3C , 0x40 , 0x30 , 0x40 , 0x3C , 0x00 , 0x00 , 0x00 ] ) ,
143
+ 'x' => Bitmapped ( [ 0x00 , 0x44 , 0x28 , 0x10 , 0x28 , 0x44 , 0x00 , 0x00 ] ) ,
144
+ 'y' => Bitmapped ( [ 0x0C , 0x50 , 0x50 , 0x50 , 0x3C , 0x00 , 0x00 , 0x00 ] ) ,
145
+ 'z' => Bitmapped ( [ 0x44 , 0x64 , 0x54 , 0x4C , 0x44 , 0x00 , 0x00 , 0x00 ] ) ,
146
+ '{' => Bitmapped ( [ 0x00 , 0x08 , 0x36 , 0x41 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
147
+ '|' => Bitmapped ( [ 0x00 , 0x00 , 0x7F , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
148
+ '}' => Bitmapped ( [ 0x00 , 0x41 , 0x36 , 0x08 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
149
+ _ => Bitmapped ( [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ,
138
150
}
139
151
}
140
152
}
@@ -143,6 +155,7 @@ where
143
155
/// Terminal mode handler
144
156
pub struct TerminalMode < DI > {
145
157
properties : DisplayProperties < DI > ,
158
+ character_no : Option < u8 > ,
146
159
}
147
160
148
161
impl < DI > DisplayModeTrait < DI > for TerminalMode < DI >
@@ -151,7 +164,10 @@ where
151
164
{
152
165
/// Create new TerminalMode instance
153
166
fn new ( properties : DisplayProperties < DI > ) -> Self {
154
- TerminalMode { properties }
167
+ TerminalMode {
168
+ properties,
169
+ character_no : None ,
170
+ }
155
171
}
156
172
157
173
/// Release all resources used by TerminalMode
@@ -175,9 +191,7 @@ where
175
191
} ;
176
192
177
193
// Reset position so we don't end up in some random place of our cleared screen
178
- let ( display_width, display_height) = self . properties . get_size ( ) . dimensions ( ) ;
179
- self . properties
180
- . set_draw_area ( ( 0 , 0 ) , ( display_width, display_height) ) ?;
194
+ self . reset_pos ( ) ?;
181
195
182
196
for _ in 0 ..numchars {
183
197
self . properties . draw ( & [ 0 ; 8 ] ) ?;
@@ -209,22 +223,60 @@ where
209
223
where
210
224
TerminalMode < DI > : CharacterBitmap < T > ,
211
225
{
212
- // Send the pixel data to the display
213
- self . properties . draw ( & Self :: to_bitmap ( c) ) ?;
226
+ match Self :: to_bitmap ( c) {
227
+ BitmapCharacter :: Bitmapped ( ref buffer) => {
228
+ // Increment character counter
229
+ self . increment_character ( ) ?;
230
+ // Send the pixel data to the display
231
+ self . properties . draw ( buffer) ?;
232
+ }
233
+ BitmapCharacter :: Newline => {
234
+ let counter = self . character_no . ok_or ( ( ) ) ?;
235
+ let num_spaces = self . chars_per_line ( ) - counter;
236
+ for _ in 0 ..num_spaces {
237
+ self . increment_character ( ) ?;
238
+ self . properties
239
+ . draw ( & [ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ] ) ?;
240
+ }
241
+ }
242
+ }
243
+
214
244
Ok ( ( ) )
215
245
}
216
246
217
247
/// Initialise the display in column mode (i.e. a byte walks down a column of 8 pixels) with
218
248
/// column 0 on the left and column _(display_width - 1)_ on the right.
219
249
pub fn init ( & mut self ) -> Result < ( ) , ( ) > {
220
250
self . properties . init_column_mode ( ) ?;
251
+ self . reset_pos ( ) ?;
221
252
Ok ( ( ) )
222
253
}
223
254
224
255
/// Set the display rotation
225
256
pub fn set_rotation ( & mut self , rot : DisplayRotation ) -> Result < ( ) , ( ) > {
226
257
self . properties . set_rotation ( rot)
227
258
}
259
+
260
+ /// Reset the draw area and move pointer to the top left corner
261
+ fn reset_pos ( & mut self ) -> Result < ( ) , ( ) > {
262
+ let ( display_width, display_height) = self . properties . get_dimensions ( ) ;
263
+ // Initialise the counter when we know it's valid
264
+ self . character_no = Some ( 0 ) ;
265
+ self . properties
266
+ . set_draw_area ( ( 0 , 0 ) , ( display_width, display_height) )
267
+ }
268
+
269
+ /// Increment character counter, resetting if we've reached the end of the line
270
+ fn increment_character ( & mut self ) -> Result < ( ) , ( ) > {
271
+ self . character_no = self . character_no . map ( |n| ( n + 1 ) % self . chars_per_line ( ) ) ;
272
+ self . character_no . map ( |_| ( ) ) . ok_or ( ( ) )
273
+ }
274
+
275
+ /// Get the number of characters in a line
276
+ fn chars_per_line ( & self ) -> u8 {
277
+ let ( line_width, _) = self . properties . get_dimensions ( ) ;
278
+ line_width / 8
279
+ }
228
280
}
229
281
230
282
impl < DI > fmt:: Write for TerminalMode < DI >
0 commit comments