Browse Source

Added keyboard management

01010101 12 years ago
parent
commit
17cd764f71
3 changed files with 528 additions and 5 deletions
  1. 398 5
      Minitel.cpp
  2. 64 0
      Minitel.h
  3. 66 0
      examples/MinitelAsKeyboard/MinitelAsKeyboard.ino

+ 398 - 5
Minitel.cpp

@@ -27,20 +27,16 @@ boolean _currentShowCursor = false;
 
 
 Minitel::Minitel() : SoftwareSerial(6,7) {
-	pinMode(6, OUTPUT);
-	pinMode(7, OUTPUT);
 	init();
 }
 
 
 Minitel::Minitel(int rx, int tx) : SoftwareSerial(rx,tx) {
-	pinMode(rx, INPUT);
-	pinMode(tx, OUTPUT);
 	init();
 }
 
 void Minitel::init() {
-	//Serial.begin(1200);
+	Serial.begin(1200);
 	begin(1200);
 	refreshSettings();
 }
@@ -513,6 +509,403 @@ void Minitel::bip(long duration) {
   }
 }
 
+byte Minitel::getKeyCode() {
+	byte b = 255;
+	b = read();		
+	if (b != 255) {
+		Serial.println(b);
+	}
+	return b;
+}
+
+char Minitel::getKey() {
+  byte b = 255; 
+  b =  read();
+  char c = '^';
+
+  // Menu keys
+  if (b == 147) {
+  	_menuKeyPressed = true;
+  	delay(50);
+  }
+  else if (_menuKeyPressed) {
+	if (b == 198) { // Sommaire
+		c = '1';
+	
+} 
+	
+else if (b == 197) { // Annul
+		c = '2';
+	
+} 
+	
+else if (b == 66) { // Retour
+		c = '3';
+	
+} 
+	
+else if (b == 195) { // Répétition
+		c = '4';
+	
+} 
+	
+else if (b == 68) { // Guide
+		c = '5';
+	
+} 
+	
+else if (b == 71) { // Correction
+		c = '6';
+	
+} 
+	
+else if (b == 72) { // Suite
+		c = '7';
+	
+} 
+	
+else if (b == 65) { // Envoi
+		c = '8';
+	
+} 
+	_menuKeyPressed = false;
+  }
+  else {
+	if (b == 160) { // Space
+		c = ' ';
+	}
+
+	else if (b == 177) { // 1
+		c = '1';
+	
+} 
+	
+else if (b == 178) { // 2
+		c = '2';
+	
+} 
+	
+else if (b == 51) { // 3
+		c = '3';
+	
+} 
+	
+else if (b == 180) { // 4
+		c = '4';
+	
+} 
+	
+else if (b == 53) { // 5
+		c = '5';
+	
+} 
+	
+else if (b == 54) { // 6
+		c = '6';
+	
+} 
+	
+else if (b == 183) { // 7
+		c = '7';
+	
+} 
+	
+else if (b == 184) { // 8
+		c = '8';
+	
+} 
+	
+else if (b == 57) { // 9
+		c = '9';
+	
+} 
+	
+else if (b == 48) { // 0
+		c = '0';
+	
+} 
+	
+else if (b == 170) { // *
+		c = '*';
+	
+} 
+	
+else if (b == 163) { // #
+		c = '#';
+	
+} 
+	
+else if (b == 172) { // ,
+		c = ',';
+	
+} 
+	
+else if (b == 46) { // .
+		c = '.';
+	
+} 
+	
+else if (b == 39) { // '
+		c = '\'';
+	
+} 
+	
+else if (b == 187) { // ;
+		c = ';';
+	
+} 
+	
+else if (b == 45) { // -
+		c = '-';
+	
+} 
+	
+else if (b == 58) { // :
+		c = ':';
+	
+} 
+	
+else if (b == 63) { // ?
+		c = '?';
+	
+} 
+	
+else if (b == 65) { // A
+		c = 'A';
+	
+} 
+	
+else if (b == 66) { //  B
+		c = 'B';
+	
+} 
+	
+else if (b == 195) { // C
+		c = 'C';
+	
+} 
+	
+else if (b == 68) { // D
+		c = 'D';
+	
+} 
+	
+else if (b == 197) { // E
+		c = 'E';
+	
+} 
+	
+else if (b == 198) { // F
+		c = 'F';
+	
+} 
+	
+else if (b == 71) { // G
+		c = 'G';
+	
+} 
+	
+else if (b == 72) { // H
+		c = 'H';
+	
+} 
+	
+else if (b == 201) { // I
+		c = 'I';
+	
+} 
+	
+else if (b == 202) { // J
+		c = 'J';
+	
+} 
+	
+else if (b == 75) { // K
+		c = 'K';
+	
+} 
+	
+else if (b == 204) { // L
+		c = 'L';
+	
+} 
+	
+else if (b == 77) { // M
+		c = 'M';
+	
+} 
+	
+else if (b == 78) { // N
+		c = 'N';
+	
+} 
+	
+else if (b == 207) { // O
+		c = 'O';
+	
+} 
+	
+else if (b == 80) { // P
+		c = 'P';
+	
+} 
+	
+else if (b == 209) { // Q
+		c = 'Q';
+	
+} 
+	
+else if (b == 210) { // R
+		c = 'R';
+	
+} 
+	
+else if (b == 83) { // S
+		c = 'S';
+	
+} 
+	
+else if (b == 212) { // T
+		c = 'T';
+	
+} 
+	
+else if (b == 85) {  //U
+		c = 'U';
+	
+} 
+	
+else if (b == 86) { // V
+		c = 'V';
+	
+} 
+	
+else if (b == 215) { // W
+		c = 'W';
+	
+} 
+	
+else if (b == 216) { // X
+		c = 'X';
+	
+} 
+	
+else if (b == 89) { // Y
+		c = 'Y';
+	
+} 
+	
+else if (b == 90) { // Z
+		c = 'Z';
+	
+}
+	
+else if (b == 33) { // !
+		c = '!';
+	
+}
+	
+else if (b == 34) { // !
+		c = '"';
+	
+}
+	
+else if (b == 163) { // #
+		c = '#';
+	
+}
+	
+else if (b == 36) { // $
+		c = '$';
+	
+}
+	
+else if (b == 165) { // %
+		c = '%';
+	
+}
+	
+else if (b == 166) { // &
+		c = '&';
+	
+}
+	
+else if (b == 39) { // '
+		c = '\'';
+	
+}
+	
+else if (b == 40) { // (
+		c = '(';
+	
+}
+	
+else if (b == 169) { // )
+		c = ')';
+	
+}
+	
+else if (b == 219) { // [
+		c = '[';
+	
+}
+	
+else if (b == 222) { // ↑
+		c = '↑';
+	
+}
+	
+else if (b == 221) { // ]
+		c = '[';
+	
+}
+	
+else if (b == 60) { // < 
+		c = '<';
+	
+}
+	
+else if (b == 190) { // >
+		c = '>';
+	
+}
+	
+else if (b == 192) { // @
+		c = '@';
+	
+}
+	
+else if (b == 43) { // +
+		c = '+';
+	
+}
+	
+else if (b == 189) { // =
+		c = '=';
+	
+}
+	
+else if (b == 170) { // *
+		c = '*';
+	
+}
+	
+else if (b == 175) { // /
+		c = '/';
+	
+}
+	
+else if (b == 123) { // /
+		c = '|';
+	
+}
+	}
+	return c;
+}
+
+boolean Minitel::isMenuKey() {
+	return _menuKeyPressed;
+}
 
 void Minitel::rect(char c, int x, int y, int w, int h) {
   byte b = getCharByte(c);

+ 64 - 0
Minitel.h

@@ -128,6 +128,66 @@
 #define SPE_CHAR_LOWER_OE 122
 #define SPE_CHAR_BETA 123
 
+/*
+#define kPause  160
+#define k1  177
+#define k2  178
+#define k3  51
+#define k4  180
+#define k5  53
+#define k6  54
+#define k7  183
+#define k8  184
+#define k9  57
+#define k0  48
+#define kStar  170
+#define kHash  163
+
+#define kComa  172
+#define kDot  46
+#define kExcl  39
+#define kSemi  187
+#define kDash  45
+#define kColon  58
+#define kInterro  63
+
+#define kMenu  147
+#define kSomm  198
+#define kGuide  68
+#define kAnnul  197
+#define kCorrect  71
+#define kRetour  66
+#define kSuite  72
+#define kRepet  195
+#define kEnvoi  65
+
+#define kA  65
+#define kB  66
+#define kC  195
+#define kD  68
+#define kE  197
+#define kF  198
+#define kG  71
+#define kH  72
+#define kI  201
+#define kJ  202
+#define kK  75
+#define kL  204
+#define kM  77
+#define kN  78
+#define kO  207
+#define kP  80
+#define kQ  209
+#define kR  210
+#define kS  83
+#define kT  212
+#define kU  85
+#define kV  86
+#define kW  215
+#define kX  216
+#define kY  89
+#define kZ  90
+*/
 
 class Minitel : public SoftwareSerial {
 
@@ -142,6 +202,7 @@ private :
 	boolean _currentUnderline;
 	boolean _currentBlink;
 	boolean _currentShowCursor;
+	boolean _menuKeyPressed;
 	void init();
 	void refreshSettings();
 	void mode(byte mode);
@@ -204,6 +265,9 @@ public :
 	void transparentVideo();
 	void setMaxSpeed();
 	void bip(long duration);
+	char getKey();
+	byte getKeyCode();
+	boolean isMenuKey();
 	void rect(char c, int x, int y, int w, int h);
 	void rect(byte c, int x, int y, int w, int h);
 	void spiral(int x, int y, int siz, int c);

+ 66 - 0
examples/MinitelAsKeyboard/MinitelAsKeyboard.ino

@@ -0,0 +1,66 @@
+/**
+ * Minitel library for Arduino (v0.1) / May 2013
+ * http://github.com/01010101/Minitel
+ *
+ * By Jerome Saint-Clair aka 01010101
+ * http://saint-clair.net
+ * 
+ * For the Graffiti Research Lab France
+ * http://graffitiresearchlab.fr
+ * 
+ * Based on works by the Tetalab (Fabrice, Renaud, PG & Phil)
+ * http://tetalab.org
+ */
+
+/**
+ * Use Fnct T + E to disable echo
+ *
+ */
+
+#include <SoftwareSerial.h>
+#include <Minitel.h>
+
+Minitel m(6,7);
+boolean input = true;
+char key = '^';
+boolean isMenu = false;
+
+void setup() {
+  m.clearScreen();
+  Serial.begin(1200);
+  m.textMode();
+  m.cursor();
+}
+
+void loop() {
+  // Read key each 2 loops only
+  if (input) {
+    key = m.getKey();
+    if (m.isMenuKey()) {
+     isMenu = true; 
+    }
+  }
+  else {
+   if (key != '^') {
+     if (isMenu) {
+       if (key == '3') { // Return
+        m.moveCursorTo(HOME);
+        m.moveCursor(DOWN,1);
+       }
+       else if (key == '6') { // Correction
+        m.moveCursor(LEFT,1);
+        m.textChar(' ');
+        m.moveCursor(LEFT, 1);
+       }
+       else { // Clear screen
+        m.clearScreen();
+       }
+      isMenu = false; 
+     }
+     else { // Display char
+       m.textChar(key);
+     }
+   } 
+  }
+  input = !input;
+}