This is a *VERY* Rough library for translating binary representations of grade 1 braille into ASCII strings.

Committer:
aganger3
Date:
Fri Oct 12 05:03:56 2012 +0000
Revision:
1:d79dbb617533
Parent:
0:22ca5452cf10
Child:
2:4cd96cdca95a
Draft 1;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
aganger3 0:22ca5452cf10 1 #include "Braille_In.h"
aganger3 0:22ca5452cf10 2
aganger3 0:22ca5452cf10 3
aganger3 0:22ca5452cf10 4
aganger3 0:22ca5452cf10 5 char* BrailleInput::translateBraille(char* input, int numChars)
aganger3 0:22ca5452cf10 6 {
aganger3 0:22ca5452cf10 7 char output[numChars+1];
aganger3 0:22ca5452cf10 8 bool NextCaps=false;
aganger3 0:22ca5452cf10 9 for (int i=0;i<numChars;i++)
aganger3 0:22ca5452cf10 10 {
aganger3 0:22ca5452cf10 11 output[i]=translateBrailleChar(input[i],NextCaps);
aganger3 0:22ca5452cf10 12 }
aganger3 0:22ca5452cf10 13 return input;
aganger3 0:22ca5452cf10 14 }
aganger3 0:22ca5452cf10 15
aganger3 0:22ca5452cf10 16
aganger3 0:22ca5452cf10 17 char BrailleInput::translateBrailleChar(char input, bool& NextCaps)
aganger3 0:22ca5452cf10 18 {
aganger3 0:22ca5452cf10 19 NextCaps=false;
aganger3 0:22ca5452cf10 20 char out;
aganger3 0:22ca5452cf10 21 bool undefined=false;
aganger3 0:22ca5452cf10 22
aganger3 0:22ca5452cf10 23
aganger3 1:d79dbb617533 24
aganger3 0:22ca5452cf10 25 if (!(input & 0x4)) {
aganger3 0:22ca5452cf10 26 switch(input) {
aganger3 0:22ca5452cf10 27 case 0x1:
aganger3 0:22ca5452cf10 28 out= 'a';
aganger3 0:22ca5452cf10 29 break;
aganger3 0:22ca5452cf10 30 case 0x3:
aganger3 0:22ca5452cf10 31 out= 'b';
aganger3 0:22ca5452cf10 32 break;
aganger3 0:22ca5452cf10 33 case 0x9:
aganger3 0:22ca5452cf10 34 out= 'c';
aganger3 0:22ca5452cf10 35 break;
aganger3 0:22ca5452cf10 36 case 0x25:
aganger3 0:22ca5452cf10 37 out= 'd';
aganger3 0:22ca5452cf10 38 break;
aganger3 0:22ca5452cf10 39 case 0x17:
aganger3 0:22ca5452cf10 40 out= 'e';
aganger3 0:22ca5452cf10 41 break;
aganger3 0:22ca5452cf10 42 case 0x11:
aganger3 0:22ca5452cf10 43 out='f';
aganger3 0:22ca5452cf10 44 break;
aganger3 0:22ca5452cf10 45 case 0x27:
aganger3 0:22ca5452cf10 46 out='g';
aganger3 0:22ca5452cf10 47 break;
aganger3 0:22ca5452cf10 48 case 0x19:
aganger3 0:22ca5452cf10 49 out='h';
aganger3 0:22ca5452cf10 50 break;
aganger3 0:22ca5452cf10 51 case 0x18:
aganger3 0:22ca5452cf10 52 out='i';
aganger3 0:22ca5452cf10 53 break;
aganger3 0:22ca5452cf10 54 case 0x26:
aganger3 0:22ca5452cf10 55 out='j';
aganger3 0:22ca5452cf10 56 break;
aganger3 1:d79dbb617533 57 case 0x12:
aganger3 1:d79dbb617533 58 out=':';
aganger3 1:d79dbb617533 59 break;
aganger3 0:22ca5452cf10 60 default:
aganger3 1:d79dbb617533 61 if (input == 0x58){ out = 'w'; } else if (input==0x32){out ='.';} else{ out ='a'; undefined=true; }
aganger3 0:22ca5452cf10 62
aganger3 0:22ca5452cf10 63
aganger3 0:22ca5452cf10 64 }}
aganger3 0:22ca5452cf10 65 else if (input & 0x36){
aganger3 0:22ca5452cf10 66 switch (input)
aganger3 0:22ca5452cf10 67 {
aganger3 0:22ca5452cf10 68 case 0x37:
aganger3 0:22ca5452cf10 69 out='u';
aganger3 0:22ca5452cf10 70 break;
aganger3 0:22ca5452cf10 71 case 0x39:
aganger3 0:22ca5452cf10 72 out='v';
aganger3 0:22ca5452cf10 73 break;
aganger3 0:22ca5452cf10 74 case 0x45:
aganger3 0:22ca5452cf10 75 out='x';
aganger3 0:22ca5452cf10 76 break;
aganger3 0:22ca5452cf10 77 case 0x61:
aganger3 0:22ca5452cf10 78 out='y';
aganger3 0:22ca5452cf10 79 break;
aganger3 0:22ca5452cf10 80 case 0x53:
aganger3 0:22ca5452cf10 81 out='z';
aganger3 0:22ca5452cf10 82 break;
aganger3 0:22ca5452cf10 83 default:
aganger3 0:22ca5452cf10 84 out='u'; undefined=true;
aganger3 0:22ca5452cf10 85 }} else{
aganger3 0:22ca5452cf10 86 switch(input){
aganger3 0:22ca5452cf10 87 case 0x5:
aganger3 0:22ca5452cf10 88 out='k';
aganger3 0:22ca5452cf10 89 break;
aganger3 0:22ca5452cf10 90 case 0x7:
aganger3 0:22ca5452cf10 91 out='l';
aganger3 0:22ca5452cf10 92 break;
aganger3 0:22ca5452cf10 93 case 0x13:
aganger3 0:22ca5452cf10 94 out='m';
aganger3 0:22ca5452cf10 95 break;
aganger3 0:22ca5452cf10 96 case 0x29:
aganger3 0:22ca5452cf10 97 out='n';
aganger3 0:22ca5452cf10 98 break;
aganger3 0:22ca5452cf10 99 case 0x21:
aganger3 0:22ca5452cf10 100 out='o';
aganger3 0:22ca5452cf10 101 break;
aganger3 0:22ca5452cf10 102 case 0x15:
aganger3 0:22ca5452cf10 103 out='p';
aganger3 0:22ca5452cf10 104 break;
aganger3 0:22ca5452cf10 105 case 0x31:
aganger3 0:22ca5452cf10 106 out='q';
aganger3 0:22ca5452cf10 107 break;
aganger3 0:22ca5452cf10 108 case 0x23:
aganger3 0:22ca5452cf10 109 out='r';
aganger3 0:22ca5452cf10 110 break;
aganger3 0:22ca5452cf10 111 case 0x14:
aganger3 0:22ca5452cf10 112 out='s';
aganger3 0:22ca5452cf10 113 break;
aganger3 0:22ca5452cf10 114 case 0x30:
aganger3 0:22ca5452cf10 115 out='t';
aganger3 0:22ca5452cf10 116 break;
aganger3 1:d79dbb617533 117 case 0x32:
aganger3 1:d79dbb617533 118 out='?';
aganger3 1:d79dbb617533 119 break;
aganger3 1:d79dbb617533 120 case 0x16:
aganger3 1:d79dbb617533 121 out='!';
aganger3 1:d79dbb617533 122 break;
aganger3 1:d79dbb617533 123 case 0x6:
aganger3 1:d79dbb617533 124 out=';';
aganger3 1:d79dbb617533 125 break;
aganger3 1:d79dbb617533 126
aganger3 0:22ca5452cf10 127 default:
aganger3 0:22ca5452cf10 128 out='k'; undefined=true;
aganger3 0:22ca5452cf10 129 }}
aganger3 1:d79dbb617533 130
aganger3 1:d79dbb617533 131 switch(input)
aganger3 1:d79dbb617533 132 {
aganger3 1:d79dbb617533 133 case 0x26:
aganger3 1:d79dbb617533 134 out='?';
aganger3 1:d79dbb617533 135 break;
aganger3 1:d79dbb617533 136 case 0x32:
aganger3 1:d79dbb617533 137 out='.';
aganger3 1:d79dbb617533 138 break;
aganger3 1:d79dbb617533 139 }
aganger3 1:d79dbb617533 140
aganger3 1:d79dbb617533 141
aganger3 1:d79dbb617533 142 if (NextCaps)
aganger3 1:d79dbb617533 143 {
aganger3 1:d79dbb617533 144 out=out-0x20;
aganger3 1:d79dbb617533 145 NextCaps=false;
aganger3 1:d79dbb617533 146 }
aganger3 0:22ca5452cf10 147
aganger3 1:d79dbb617533 148 if (input & 0x20)
aganger3 1:d79dbb617533 149 {
aganger3 1:d79dbb617533 150 NextCaps=true;
aganger3 1:d79dbb617533 151 out=' ';
aganger3 1:d79dbb617533 152 }
aganger3 0:22ca5452cf10 153
aganger3 0:22ca5452cf10 154
aganger3 0:22ca5452cf10 155 return out;
aganger3 0:22ca5452cf10 156 }
aganger3 0:22ca5452cf10 157
aganger3 0:22ca5452cf10 158
aganger3 0:22ca5452cf10 159
aganger3 0:22ca5452cf10 160
aganger3 0:22ca5452cf10 161
aganger3 0:22ca5452cf10 162
aganger3 0:22ca5452cf10 163
aganger3 0:22ca5452cf10 164
aganger3 0:22ca5452cf10 165
aganger3 0:22ca5452cf10 166
aganger3 0:22ca5452cf10 167
aganger3 0:22ca5452cf10 168
aganger3 0:22ca5452cf10 169
aganger3 0:22ca5452cf10 170
aganger3 0:22ca5452cf10 171
aganger3 0:22ca5452cf10 172