
lab 5a
Dependencies: mbed mbed-rtos tsi_sensor SLCD
VT100.h@2:cad0ec8e29a5, 2020-05-03 (annotated)
- Committer:
- teajaypierce
- Date:
- Sun May 03 12:55:12 2020 +0000
- Revision:
- 2:cad0ec8e29a5
- Parent:
- 0:78b84e1ce9df
lab 5a
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wstapleton | 0:78b84e1ce9df | 1 | #ifndef VT100_H |
wstapleton | 0:78b84e1ce9df | 2 | #define VT100_H |
wstapleton | 0:78b84e1ce9df | 3 | |
wstapleton | 0:78b84e1ce9df | 4 | #include "ASCII.h" |
wstapleton | 0:78b84e1ce9df | 5 | |
wstapleton | 0:78b84e1ce9df | 6 | void vt100_home() |
wstapleton | 0:78b84e1ce9df | 7 | { |
wstapleton | 0:78b84e1ce9df | 8 | pc.printf("\x1b[H"); |
wstapleton | 0:78b84e1ce9df | 9 | } |
wstapleton | 0:78b84e1ce9df | 10 | |
wstapleton | 0:78b84e1ce9df | 11 | void vt100_move_cursor(int row, int column) |
wstapleton | 0:78b84e1ce9df | 12 | { |
wstapleton | 0:78b84e1ce9df | 13 | pc.printf("\x1b[%i;%iH",row,column); |
wstapleton | 0:78b84e1ce9df | 14 | } |
wstapleton | 0:78b84e1ce9df | 15 | |
wstapleton | 0:78b84e1ce9df | 16 | void vt100_save_cursor() |
wstapleton | 0:78b84e1ce9df | 17 | { |
wstapleton | 0:78b84e1ce9df | 18 | pc.printf("\x1b[s"); |
wstapleton | 0:78b84e1ce9df | 19 | } |
wstapleton | 0:78b84e1ce9df | 20 | |
wstapleton | 0:78b84e1ce9df | 21 | void vt100_unsave_cursor() |
wstapleton | 0:78b84e1ce9df | 22 | { |
wstapleton | 0:78b84e1ce9df | 23 | pc.printf("\x1b[u"); |
wstapleton | 0:78b84e1ce9df | 24 | } |
wstapleton | 0:78b84e1ce9df | 25 | |
wstapleton | 0:78b84e1ce9df | 26 | void vt100_up() |
wstapleton | 0:78b84e1ce9df | 27 | { |
wstapleton | 0:78b84e1ce9df | 28 | pc.printf("\x1b[A"); |
wstapleton | 0:78b84e1ce9df | 29 | } |
wstapleton | 0:78b84e1ce9df | 30 | |
wstapleton | 0:78b84e1ce9df | 31 | void vt100_up_by(int count) |
wstapleton | 0:78b84e1ce9df | 32 | { |
wstapleton | 0:78b84e1ce9df | 33 | pc.printf("\x1b[%iA",count); |
wstapleton | 0:78b84e1ce9df | 34 | } |
wstapleton | 0:78b84e1ce9df | 35 | |
wstapleton | 0:78b84e1ce9df | 36 | void vt100_down() |
wstapleton | 0:78b84e1ce9df | 37 | { |
wstapleton | 0:78b84e1ce9df | 38 | pc.printf("\x1b[B"); |
wstapleton | 0:78b84e1ce9df | 39 | } |
wstapleton | 0:78b84e1ce9df | 40 | |
wstapleton | 0:78b84e1ce9df | 41 | void vt100_down_by(int count) |
wstapleton | 0:78b84e1ce9df | 42 | { |
wstapleton | 0:78b84e1ce9df | 43 | pc.printf("\x1b[%iB",count); |
wstapleton | 0:78b84e1ce9df | 44 | } |
wstapleton | 0:78b84e1ce9df | 45 | |
wstapleton | 0:78b84e1ce9df | 46 | void vt100_right() |
wstapleton | 0:78b84e1ce9df | 47 | { |
wstapleton | 0:78b84e1ce9df | 48 | pc.printf("\x1b[C"); |
wstapleton | 0:78b84e1ce9df | 49 | } |
wstapleton | 0:78b84e1ce9df | 50 | |
wstapleton | 0:78b84e1ce9df | 51 | void vt100_right_by(int count) |
wstapleton | 0:78b84e1ce9df | 52 | { |
wstapleton | 0:78b84e1ce9df | 53 | pc.printf("\x1b[%iC",count); |
wstapleton | 0:78b84e1ce9df | 54 | } |
wstapleton | 0:78b84e1ce9df | 55 | |
wstapleton | 0:78b84e1ce9df | 56 | void vt100_left() |
wstapleton | 0:78b84e1ce9df | 57 | { |
wstapleton | 0:78b84e1ce9df | 58 | pc.printf("\x1b[D"); |
wstapleton | 0:78b84e1ce9df | 59 | } |
wstapleton | 0:78b84e1ce9df | 60 | |
wstapleton | 0:78b84e1ce9df | 61 | void vt100_left_by(int count) |
wstapleton | 0:78b84e1ce9df | 62 | { |
wstapleton | 0:78b84e1ce9df | 63 | pc.printf("\x1b[%iD",count); |
wstapleton | 0:78b84e1ce9df | 64 | } |
wstapleton | 0:78b84e1ce9df | 65 | |
wstapleton | 0:78b84e1ce9df | 66 | void vt100_erase_right() |
wstapleton | 0:78b84e1ce9df | 67 | { |
wstapleton | 0:78b84e1ce9df | 68 | pc.printf("\x1b[K"); |
wstapleton | 0:78b84e1ce9df | 69 | } |
wstapleton | 0:78b84e1ce9df | 70 | |
wstapleton | 0:78b84e1ce9df | 71 | void vt100_erase_left() |
wstapleton | 0:78b84e1ce9df | 72 | { |
wstapleton | 0:78b84e1ce9df | 73 | pc.printf("\x1b[1K"); |
wstapleton | 0:78b84e1ce9df | 74 | } |
wstapleton | 0:78b84e1ce9df | 75 | |
wstapleton | 0:78b84e1ce9df | 76 | void vt100_erase_line() |
wstapleton | 0:78b84e1ce9df | 77 | { |
wstapleton | 0:78b84e1ce9df | 78 | pc.printf("\x1b[2K"); |
wstapleton | 0:78b84e1ce9df | 79 | } |
wstapleton | 0:78b84e1ce9df | 80 | |
wstapleton | 0:78b84e1ce9df | 81 | void vt100_erase_above() |
wstapleton | 0:78b84e1ce9df | 82 | { |
wstapleton | 0:78b84e1ce9df | 83 | pc.printf("\x1b[J"); |
wstapleton | 0:78b84e1ce9df | 84 | } |
wstapleton | 0:78b84e1ce9df | 85 | |
wstapleton | 0:78b84e1ce9df | 86 | void vt100_erase_below() |
wstapleton | 0:78b84e1ce9df | 87 | { |
wstapleton | 0:78b84e1ce9df | 88 | pc.printf("\x1b[1J"); |
wstapleton | 0:78b84e1ce9df | 89 | } |
wstapleton | 0:78b84e1ce9df | 90 | |
wstapleton | 0:78b84e1ce9df | 91 | void vt100_erase_screen() |
wstapleton | 0:78b84e1ce9df | 92 | { |
wstapleton | 0:78b84e1ce9df | 93 | pc.printf("\x1b[2J"); |
wstapleton | 0:78b84e1ce9df | 94 | } |
wstapleton | 0:78b84e1ce9df | 95 | |
wstapleton | 0:78b84e1ce9df | 96 | void vt100_set_attribute(int attrib) |
wstapleton | 0:78b84e1ce9df | 97 | { |
wstapleton | 0:78b84e1ce9df | 98 | pc.printf("\x1b[%xm",attrib); |
wstapleton | 0:78b84e1ce9df | 99 | } |
wstapleton | 0:78b84e1ce9df | 100 | |
wstapleton | 0:78b84e1ce9df | 101 | enum vt100_colors |
wstapleton | 0:78b84e1ce9df | 102 | { |
wstapleton | 0:78b84e1ce9df | 103 | black=0, |
wstapleton | 0:78b84e1ce9df | 104 | red=1, |
wstapleton | 0:78b84e1ce9df | 105 | green=2, |
wstapleton | 0:78b84e1ce9df | 106 | yellow=3, |
wstapleton | 0:78b84e1ce9df | 107 | blue=4, |
wstapleton | 0:78b84e1ce9df | 108 | magenta=5, |
wstapleton | 0:78b84e1ce9df | 109 | cyan=6, |
wstapleton | 0:78b84e1ce9df | 110 | white=7 |
wstapleton | 0:78b84e1ce9df | 111 | }; |
wstapleton | 0:78b84e1ce9df | 112 | |
wstapleton | 0:78b84e1ce9df | 113 | void vt100_text_default() |
wstapleton | 0:78b84e1ce9df | 114 | { |
wstapleton | 0:78b84e1ce9df | 115 | vt100_set_attribute(0); |
wstapleton | 0:78b84e1ce9df | 116 | } |
wstapleton | 0:78b84e1ce9df | 117 | |
wstapleton | 0:78b84e1ce9df | 118 | void vt100_text_bright() |
wstapleton | 0:78b84e1ce9df | 119 | { |
wstapleton | 0:78b84e1ce9df | 120 | vt100_set_attribute(1); |
wstapleton | 0:78b84e1ce9df | 121 | } |
wstapleton | 0:78b84e1ce9df | 122 | |
wstapleton | 0:78b84e1ce9df | 123 | void vt100_text_dim() |
wstapleton | 0:78b84e1ce9df | 124 | { |
wstapleton | 0:78b84e1ce9df | 125 | vt100_set_attribute(2); |
wstapleton | 0:78b84e1ce9df | 126 | } |
wstapleton | 0:78b84e1ce9df | 127 | |
wstapleton | 0:78b84e1ce9df | 128 | void vt100_text_underscore() |
wstapleton | 0:78b84e1ce9df | 129 | { |
wstapleton | 0:78b84e1ce9df | 130 | vt100_set_attribute(4); |
wstapleton | 0:78b84e1ce9df | 131 | } |
wstapleton | 0:78b84e1ce9df | 132 | |
wstapleton | 0:78b84e1ce9df | 133 | void vt100_text_blink() |
wstapleton | 0:78b84e1ce9df | 134 | { |
wstapleton | 0:78b84e1ce9df | 135 | vt100_set_attribute(5); |
wstapleton | 0:78b84e1ce9df | 136 | } |
wstapleton | 0:78b84e1ce9df | 137 | |
wstapleton | 0:78b84e1ce9df | 138 | void vt100_text_reverse() |
wstapleton | 0:78b84e1ce9df | 139 | { |
wstapleton | 0:78b84e1ce9df | 140 | vt100_set_attribute(7); |
wstapleton | 0:78b84e1ce9df | 141 | } |
wstapleton | 0:78b84e1ce9df | 142 | |
wstapleton | 0:78b84e1ce9df | 143 | void vt100_text_hidden() |
wstapleton | 0:78b84e1ce9df | 144 | { |
wstapleton | 0:78b84e1ce9df | 145 | vt100_set_attribute(8); |
wstapleton | 0:78b84e1ce9df | 146 | } |
wstapleton | 0:78b84e1ce9df | 147 | |
wstapleton | 0:78b84e1ce9df | 148 | void vt100_set_foreground(int color) |
wstapleton | 0:78b84e1ce9df | 149 | { |
wstapleton | 0:78b84e1ce9df | 150 | if(color<0 || color > 7) |
wstapleton | 0:78b84e1ce9df | 151 | { |
wstapleton | 0:78b84e1ce9df | 152 | printf("\ncolor must be in the range 0-7\n"); |
wstapleton | 0:78b84e1ce9df | 153 | return; |
wstapleton | 0:78b84e1ce9df | 154 | } |
wstapleton | 0:78b84e1ce9df | 155 | vt100_set_attribute(0x30+color); |
wstapleton | 0:78b84e1ce9df | 156 | } |
wstapleton | 0:78b84e1ce9df | 157 | |
wstapleton | 0:78b84e1ce9df | 158 | void vt100_set_background(int color) |
wstapleton | 0:78b84e1ce9df | 159 | { |
wstapleton | 0:78b84e1ce9df | 160 | if(color<0 || color > 7) |
wstapleton | 0:78b84e1ce9df | 161 | { |
wstapleton | 0:78b84e1ce9df | 162 | printf("\ncolor must be in the range 0-7\n"); |
wstapleton | 0:78b84e1ce9df | 163 | return; |
wstapleton | 0:78b84e1ce9df | 164 | } |
wstapleton | 0:78b84e1ce9df | 165 | vt100_set_attribute(0x40+color); |
wstapleton | 0:78b84e1ce9df | 166 | } |
wstapleton | 0:78b84e1ce9df | 167 | |
wstapleton | 0:78b84e1ce9df | 168 | #endif //VT100_H |