1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
use enum_map::{enum_map, Enum, EnumMap};

pub type SymbolIndex = u8;

#[derive(Debug, Enum)]
pub enum Symbol {
    Space,
    Antenna,
    Battery,
    BoxDrawningLightUp,
    Degree,
    CrossHair,
    VeclocityVector,
    Alpha,
    Square,
    LineTop,
    LineUpper1,
    LineUpper2,
    LineCenter,
    LineLower1,
    LineLower2,
    LineBottom,
    SmallBlackSquare,
    VerticalLine,
    ZeroWithTraillingDot,
}

pub fn to_number_with_dot(byte: u8, zero_with_trailling_dot: SymbolIndex) -> u8 {
    if '0' as u8 <= byte && byte <= '9' as u8 {
        if zero_with_trailling_dot > '0' as u8 {
            byte + (zero_with_trailling_dot - '0' as u8)
        } else {
            byte - ('0' as u8 - zero_with_trailling_dot)
        }
    } else if byte == 0 {
        zero_with_trailling_dot
    } else {
        byte
    }
}

pub type SymbolTable = EnumMap<Symbol, SymbolIndex>;

pub fn default_symbol_table() -> SymbolTable {
    enum_map! {
        Symbol::Space => 0, // duplicate of ASCII 32 space
        Symbol::Antenna => 1,
        Symbol::Battery => 2,
        Symbol::Degree => 3,
        Symbol::CrossHair => 4,
        Symbol::VeclocityVector => 5,
        Symbol::Alpha => 6,
        Symbol::Square => 7,
        Symbol::LineTop => 8, // ▔
        Symbol::LineUpper1 => 9, // ⎺
        Symbol::LineUpper2 => 10, // ⎻
        Symbol::LineCenter => 11, // ⎯ or ASCII dash
        Symbol::LineLower1 => 12, // ⎼
        Symbol::LineLower2 => 13, // ⎽
        Symbol::LineBottom => 14, // ▁ or ASCII underscore
        Symbol::BoxDrawningLightUp => 15, // ╵ or ASCII |
        Symbol::ZeroWithTraillingDot => 16,
        // 17~25 number with trailling dot
        Symbol::SmallBlackSquare => 26, // ▪
        Symbol::VerticalLine => 27, // ⎪
        // 32-33 ASCII
        // 40-62 ASCII 48-57 0-9
        // 64-95 ASCII
    }
}