01010101 9 жил өмнө
parent
commit
b02e815607

Файлын зөрүү хэтэрхий том тул дарагдсан байна
+ 327 - 528
Minitel.cpp


+ 88 - 14
Minitel.h

@@ -1,5 +1,5 @@
 /**
- * Minitel library for Arduino (v0.1) / May 2013
+ * Minitel library for Arduino (v0.2) / April 2015
  * http://github.com/01010101/Minitel
  *
  * By Jerome Saint-Clair aka 01010101
@@ -105,33 +105,63 @@
 #define BIP 7
 
 // Accents
-#define ACCUTE 65
-#define GRAVE 66
-#define CIRCUMFLEX 67
-#define UMLAUT 72
+// #define ACCUTE 65
+// #define GRAVE 66
+// #define CIRCUMFLEX 67
+// #define UMLAUT 72
 
 #define SUB_ARTICLE_SEPARATOR 31;
 
 // Preceeded by 25
-#define SPE_CHAR_BOOK 35
+#define SPE_CHAR_POUND 35
+#define SPE_CHAR_DOLLAR 36
+#define SPE_CHAR_HASHTAG 38
 #define SPE_CHAR_PARAGRAPH 39
 #define SPE_CHAR_ARROW_LEFT 44
 #define SPE_CHAR_ARROW_UP 45
 #define SPE_CHAR_ARROW_RIGHT 46
 #define SPE_CHAR_ARROW_DOWN 47
-#define SPE_CHAR_CIRCLE 48
+#define SPE_CHAR_DEGREE 48
 #define SPE_CHAR_MINUS_PLUS 49
-#define SPE_CHAR_1_4 60
-#define SPE_CHAR_1_2 61
-#define SPE_CHAR_3_4 62
+#define SPE_CHAR_DIVIDE 56
+#define SPE_CHAR_1_4 60 // output only ?
+#define SPE_CHAR_1_2 61 // output only ?
+#define SPE_CHAR_3_4 62 // output only ?
+#define SPE_CHAR_GRAVE 65
+#define SPE_CHAR_ACUTE 66
+#define SPE_CHAR_CIRCUMFLEX 67
+#define SPE_CHAR_UMLAUT 72
+#define SPE_CHAR_CEDIL 75
 #define SPE_CHAR_UPPER_OE 106
 #define SPE_CHAR_LOWER_OE 122
 #define SPE_CHAR_BETA 123
 
+// Non Arduino characters
+#define SPE_CHAR_ARROW_UP2 94
+#define SPE_CHAR_PIPE_BOTTOM 95
+#define SPE_CHAR_PIPE_MIDDLE 96
+#define SPE_CHAR_PIPE_LEFT 123
+#define SPE_CHAR_PIPE_CENTER 124
+#define SPE_CHAR_PIPE_RIGHT 125
+#define SPE_CHAR_PIPE_TOP 126
+
+// TODO Escape character handling ???
+
+#define SOMMAIRE 198
+#define ANNULATION 197
+#define RETOUR 66
+#define REPETITION 195
+#define GUIDE 68
+#define CORRECTION 71
+#define SUITE 72
+#define ENVOI 65
 
 class Minitel : public SoftwareSerial {
 
 private :	
+
+	String accents = "àáâäèéêëìíîïòóôöùúûü";
+	
 	byte _currentBgColor;
 	byte _currentTextColor;
 	byte _currentMode;
@@ -141,6 +171,14 @@ private :
 	boolean _currentBlink;
 	boolean _currentShowCursor;
 	boolean _menuKeyPressed;
+			
+	int _menuKey;
+	int _specialCharacterKey;
+	int _characterKey;
+	int _accentKey;
+	
+	char _nullChar = '~';
+
 	void init();
 	void mode(byte mode);
 	void cursor(boolean b);
@@ -149,11 +187,15 @@ private :
 	void video(byte v);
 	void incrustation(boolean b);
 	void lineMask(boolean b);
+	
 	boolean isValidChar(byte index);
+	boolean isSpecialChar(byte c);
+
 	boolean isAccent(char c);
 	boolean printAccentChar(char c);
 	void printAccent(int index);
 	char getAccentLetter(int letterIndex);
+
 	void refreshSettings();
 
 
@@ -161,10 +203,13 @@ public :
 
 	Minitel();
 	Minitel(int rx, int tx);
+
 	void serialprint7(byte b);
+
 	byte getGraphicChar(String s);
 	void graphic(String s, int x, int y);
 	void graphic(String s);
+
 	void textByte(byte c);
 	void textByte(byte b, int x, int y);
 	boolean textChar(byte c);
@@ -176,22 +221,33 @@ public :
 	byte getCharByte(char c);
 	void specialChar(byte c, int x, int y);
 	void specialChar(byte c);
+	void semiGraphic(byte b, int x, int y);
+	void semiGraphic(byte b);
+
 	void repeat(byte n);
+
 	void bgColor(byte c);
 	void textColor(byte c);
 	void useDefaultColors();
+	
 	void moveCursorTo(byte x, byte y);
 	void moveCursor(byte dir);
 	void moveCursorTo(byte location);
 	void moveCursor(byte dir, int n);
+	
 	void cursor();
 	void noCursor();
+	
 	void clearScreen();
+	
 	void graphicMode();
 	void textMode();
+	
 	void blink();
 	void noBlink();
+	
 	void charSize(byte type);
+	
 	void incrustation();
 	void noIncrustation();
 	void pixelate();
@@ -201,15 +257,33 @@ public :
 	void standardVideo();
 	void invertVideo();
 	void transparentVideo();
+	
 	void setMaxSpeed();
-	void bip(long duration);
-	char getKey();
-	byte getKeyCode();
-	boolean isMenuKey();
+	
+	void bip(unsigned long duration);
+
 	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);
 
+	void readKey();
+	boolean keyTyped();
+
+	boolean isMenuKey();
+	int getMenuKey();
+
+	boolean isSpecialCharacterKey();
+	int getSpecialCharacterKey();
+
+ 	boolean accentKeyStored();
+ 	int getAccentKey();
+
+	boolean isCharacterKey();
+	boolean isSerializableKey();
+	char getCharacterKey();
+
+
+
 };
 
 #endif

+ 32 - 15
README.md

@@ -169,22 +169,29 @@ minitel.textChar('z', 1, 1);
 The Minitel's special characters can be typed by using the corresponding constants
 
 ```
-minitel.specialChar(SPE_CHAR_CIRCLE);
-minitel.specialChar(SPE_CHAR_CIRCLE, 2, 10);
+minitel.specialChar(SPE_CHAR_DEGREE);
+minitel.specialChar(SPE_CHAR_DEGREE, 2, 10);
 ```
 
 Available special characters are :
-- SPE_CHAR_BOOK
-- SPE_CHAR_PARAGRAPH
+- SPE_CHAR_POUND
+- SPE_CHAR_DOLLAR
+- SPE_CHAR_HASHTAG
 - SPE_CHAR_ARROW_LEFT
 - SPE_CHAR_ARROW_UP
 - SPE_CHAR_ARROW_RIGHT
 - SPE_CHAR_ARROW_DOWN
-- SPE_CHAR_CIRCLE
+- SPE_CHAR_DEGREE
 - SPE_CHAR_MINUS_PLUS
+- SPE_CHAR_DIVIDE
 - SPE_CHAR_1_4
 - SPE_CHAR_1_2
 - SPE_CHAR_3_4
+- SPE_CHAR_GRAVE (needs a supported vowel right after)
+- SPE_CHAR_ACUTE (needs a supported vowel right after)
+- SPE_CHAR_CIRCUMFLEX (needs a supported vowel right after)
+- SPE_CHAR_UMLAUT (needs a supported vowel right after)
+- SPE_CHAR_CEDIL 
 - SPE_CHAR_UPPER_OE
 - SPE_CHAR_LOWER_OE
 - SPE_CHAR_BETA
@@ -324,28 +331,38 @@ minitel.spiral(int x, int y, int siz, int c);
 
 Refer to the MinitelAsKeyboard example for more details
 
-WARNING : It doesn't seem to be working perfectly
+WARNINGS
+- It doesn't seem to be working perfectly when you update display in the meantime
+- Some keys can't be captured (ie: direction keys)
+- The keyboard may enter in sleep mode after some time, meaning there will be some delay when typing the first key after it went to sleep
 
 Another option is to hack the keyboard using a MPC23017 chip and get the input directly.
-
 I'll link to a tutorial and post samples when ready.
 
-### Get the keyboard's key pressed
+### Read and decode the input and then store value(s)
 
-```
-char c = getKey();
-```
+minitel.readKey();
+
+### Check if a key was pressed
+
+boolean pressed = minitel.keyTyped();
 
-### Get the key code
+### Check which kind of key was pressed (returns a boolean)
 
 ```
-byte keyCode = getKeyCode();
+minitel.isMenuKey();
+minitel.isSpecialCharacterKey();
+minitel.isCharacterKey();
+minitel.accentKeyStored();
 ```
 
-### Check if it is a menu key
+### Get the key
 
 ```
-boolean isMenuKey = isMenuKey();
+int menu = minitel.getMenuKey(); // Can be checked against the menu key constants
+int specialChar = minitel.getSpecialCharacterKey(); // Can be checked agains the special characters constants
+char character = minitel.getCharacterKey(); // If 
+int accent = minitel.getAccentKey(); // In addition to checking if a character and in case of a lowercase vowel
 ```
 
 

+ 39 - 52
examples/MinitelAsKeyboard/MinitelAsKeyboard.ino

@@ -1,66 +1,53 @@
 /**
- * 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
- */
+   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
- *
- */
+   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;
+Minitel minitel;
 
 void setup() {
-  m.clearScreen();
-  Serial.begin(1200);
-  m.textMode();
-  m.cursor();
+  minitel.clearScreen();
+  minitel.textMode();
+  minitel.cursor();
 }
 
 void loop() {
-  // Read key each 2 loops only
-  if (input) {
-    key = m.getKey();
-    if (m.isMenuKey()) {
-     isMenu = true; 
-    }
+  minitel.listen(); // Listen for info coming from the Minitel
+  minitel.readKey(); // Try to read a key press
+
+  if (minitel.isCharacterKey()) {
+    char key = minitel.getCharacterKey();
+    minitel.textChar(key);
   }
-  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);
-     }
-   } 
+  else if (minitel.isMenuKey()) {
+    int key = minitel.getMenuKey();
+    if (key == RETOUR) { // Return
+      minitel.moveCursorTo(HOME);
+      minitel.moveCursor(DOWN, 1);
+    }
+    else if (key == CORRECTION) {
+      minitel.moveCursor(LEFT, 1);
+      minitel.textChar(' ');
+      minitel.moveCursor(LEFT, 1);          
+    }
+    else if (key == ANNULATION) {
+      minitel.clearScreen();
+    }
   }
-  input = !input;
 }

+ 99 - 90
examples/MinitelDemo/MinitelDemo.ino

@@ -1,29 +1,29 @@
 /**
-   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
-*/
+ * 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
+ */
 
 
 #include <SoftwareSerial.h>
 #include <Minitel.h>
 
-Minitel m(6, 7);
+Minitel m(6,7);
 
 void setup() {
-
+  
 }
 
 void loop() {
-
+ 
   long pause = 2000;
 
   demoColor();
@@ -46,14 +46,14 @@ void loop() {
 
   demoCharacters();
   delay(pause);
-
+  
 }
 
 /**
-
-   DEMOS
-
-*/
+ *
+ * DEMOS
+ *
+ */
 
 // Graphic characters
 
@@ -66,76 +66,76 @@ void demoGraphics(boolean underline) {
   m.text(" GRAPHICS DEMO ", 4, 1);
   m.bgColor(BLACK);
 
-
+  
   m.graphicMode();
-
+  
   if (underline) {
     m.pixelate();
   }
   m.noCursor();
 
-  // No color
+  // No color 
   m.useDefaultColors();
 
   int xPos = 5;
   int yPos = 5;
   m.moveCursorTo(xPos, yPos);
   int x = 32;
-  for (int i = x; i < x + 16; i++) {
+  for (int i=x; i<x+16; i++) {
     m.serialprint7(i);
     m.serialprint7(9);
   }
 
-  m.moveCursorTo(xPos, yPos + 2);
-  for (int i = x + 16; i < x + 32; i++) {
+  m.moveCursorTo(xPos, yPos+2);
+  for (int i=x+16; i<x+32; i++) {
     m.serialprint7(i);
     m.serialprint7(9);
   }
 
-  m.moveCursorTo(xPos, yPos + 4);
-  for (int i = x + 32; i < x + 48; i++) {
+  m.moveCursorTo(xPos, yPos+4);
+  for (int i=x+32; i<x+48; i++) {
     m.serialprint7(i);
     m.serialprint7(9);
   }
 
-  m.moveCursorTo(xPos, yPos + 6);
-  for (int i = x + 48; i < x + 64; i++) {
+  m.moveCursorTo(xPos, yPos+6);
+  for (int i=x+48; i<x+64; i++) {
     m.serialprint7(i);
     m.serialprint7(9);
-  }
+  } 
 
   // Colored
   m.bgColor(RED);
   m.textColor(WHITE);
 
-  m.moveCursorTo(xPos, yPos + 10);
+  m.moveCursorTo(xPos, yPos+10);
   x = 32;
-  for (int i = x; i < x + 16; i++) {
+  for (int i=x; i<x+16; i++) {
     m.serialprint7(i);
     m.serialprint7(9);
   }
 
-  m.moveCursorTo(xPos, yPos + 12);
-  for (int i = x + 16; i < x + 32; i++) {
+  m.moveCursorTo(xPos, yPos+12);
+  for (int i=x+16; i<x+32; i++) {
     m.serialprint7(i);
     m.serialprint7(9);
   }
 
-  m.moveCursorTo(xPos, yPos + 14);
-  for (int i = x + 32; i < x + 48; i++) {
+  m.moveCursorTo(xPos, yPos+14);
+  for (int i=x+32; i<x+48; i++) {
     m.serialprint7(i);
     m.serialprint7(9);
   }
 
-  m.moveCursorTo(xPos, yPos + 16);
-  for (int i = x + 48; i < x + 64; i++) {
+  m.moveCursorTo(xPos, yPos+16);
+  for (int i=x+48; i<x+64; i++) {
     m.serialprint7(i);
     m.serialprint7(9);
   }
-
+  
   m.useDefaultColors();
   m.noPixelate();
-
+  
 }
 
 
@@ -192,80 +192,89 @@ void demoCharacters() {
   int yPos = 5;
   m.cursor();
 
-  // a->z
-  m.moveCursorTo(xPos, yPos);
-  for (int i = 97; i < 97 + 26; i++) {
-    m.serialprint7(i);
-  }
-
-  // A->Z
-  m.moveCursorTo(xPos, yPos + 1);
-  for (int i = 65; i < 65 + 26; i++) {
-    m.serialprint7(i);
-  }
+  m.text("abcdefghijklmnopqrstuvwxyz", xPos, yPos);
+  m.text("ABCDEFGHIJKLMNOPQRSTUVWXYZ", xPos, yPos+1);
 
   // 0-9 + punctuation marks, ...
-  m.moveCursorTo(xPos, yPos + 2);
-  for (int i = 33; i < 33 + 32; i++) {
-    m.serialprint7(i);
-  }
-  for (int i = 91; i < 97; i++) {
-    m.serialprint7(i);
-  }
+  m.text("!\"#$%&'()*+,-./0123456789",xPos, yPos+2);
+  m.text(":;<=>?@[\\]",xPos, yPos+3);
+
+  m.moveCursorTo(xPos, yPos+2);
+  m.serialprint7(96);
+  m.serialprint7(95);
+  m.serialprint7(94);
+  m.serialprint7(123);
+  m.serialprint7(124);
+  m.serialprint7(125);
+  m.serialprint7(126);
 
   // Colored characters
-  m.moveCursorTo(xPos, yPos + 3);
+  m.moveCursorTo(xPos, yPos+4);
   m.textColor(RED);
-  for (int i = 97; i < 97 + 26; i++) {
+  
+  for (int i=97; i<97+26; i++) {
     m.serialprint7(i);
   }
   m.textColor(WHITE);
 
   // Double width 1/2
-  m.moveCursorTo(xPos, yPos + 4);
   m.charSize(SIZE_DOUBLE_WIDTH);
-  for (int i = 97; i < 97 + 13; i++) {
-    m.serialprint7(i);
-  }
-  m.moveCursorTo(xPos, yPos + 5);
-  for (int i = 97 + 13; i < 97 + 26; i++) {
-    m.serialprint7(i);
-  }
+  m.text("abcdefghijklmnopqrstuvwxyz", xPos, yPos+5);
+  m.text("ABCDEFGHIJKLMNOPQRSTUVWXYZ", xPos, yPos+6);
   m.charSize(SIZE_NORMAL);
 
   // Special characters
-  m.moveCursorTo(xPos, yPos + 6);
+  m.moveCursorTo(xPos, yPos+7);
   byte chars[] = {
-    SPE_CHAR_BOOK, SPE_CHAR_PARAGRAPH, SPE_CHAR_ARROW_LEFT, SPE_CHAR_ARROW_UP, SPE_CHAR_ARROW_RIGHT, SPE_CHAR_ARROW_DOWN, SPE_CHAR_CIRCLE, SPE_CHAR_MINUS_PLUS, SPE_CHAR_1_4, SPE_CHAR_1_2, SPE_CHAR_3_4, SPE_CHAR_UPPER_OE, SPE_CHAR_LOWER_OE, SPE_CHAR_BETA
-  };
-  for (int i = 0; i < sizeof(chars); i++) {
+SPE_CHAR_POUND,
+SPE_CHAR_DOLLAR,
+SPE_CHAR_HASHTAG,
+SPE_CHAR_PARAGRAPH,
+SPE_CHAR_ARROW_LEFT,
+SPE_CHAR_ARROW_UP,
+SPE_CHAR_ARROW_RIGHT,
+SPE_CHAR_ARROW_DOWN,
+SPE_CHAR_DEGREE,
+SPE_CHAR_MINUS_PLUS,
+SPE_CHAR_DIVIDE,
+SPE_CHAR_1_4,
+SPE_CHAR_1_2,
+SPE_CHAR_3_4,
+SPE_CHAR_GRAVE,
+SPE_CHAR_ACUTE,
+SPE_CHAR_CIRCUMFLEX,
+SPE_CHAR_UMLAUT,
+SPE_CHAR_CEDIL,
+SPE_CHAR_UPPER_OE,
+SPE_CHAR_LOWER_OE,
+SPE_CHAR_BETA
+//SPE_CHAR_ARROW_UP2,
+//SPE_CHAR_PIPE_BOTTOM,
+//SPE_CHAR_PIPE_MIDDLE,
+//SPE_CHAR_PIPE_LEFT,
+//SPE_CHAR_PIPE_CENTER,
+//SPE_CHAR_PIPE_RIGHT,
+//SPE_CHAR_PIPE_TOP
+};
+  for (int i=0; i<sizeof(chars); i++) {
     m.specialChar(chars[i]);
   }
 
   // Blink
-  m.moveCursorTo(xPos, yPos + 7);
   m.blink();
-  for (int i = 97; i < 97 + 26; i++) {
-    m.serialprint7(i);
-  }
+  m.text("ABCDEFGHIJKLMNOPQRSTUVWXYZ", xPos, yPos+8);
   m.noBlink();
 
   // Invert video
-  m.moveCursorTo(xPos, yPos + 8);
   m.invertVideo();
-  for (int i = 97; i < 97 + 26; i++) {
-    m.serialprint7(i);
-  }
+  m.text("ABCDEFGHIJKLMNOPQRSTUVWXYZ", xPos, yPos+9);
   m.standardVideo();
 
 
   // Transparent
   // No effet on Minitel 1
-  m.moveCursorTo(xPos, yPos + 9);
   m.transparentVideo();
-  for (int i = 97; i < 97 + 26; i++) {
-    m.serialprint7(i);
-  }
+  m.text("ABCDEFGHIJKLMNOPQRSTUVWXYZ", xPos, yPos+10);
   m.standardVideo();
 }
 
@@ -277,8 +286,8 @@ void demoBip() {
   m.bgColor(RED);
   m.text(" BIP DEMO ", 4, 1);
   m.bgColor(BLACK);
-
-  for (int i = 0; i < 2; i++) {
+  
+  for (int i=0; i<2; i++) {
     m.bip(50);
     delay(700);
     m.bip(5);
@@ -303,7 +312,7 @@ void demoText() {
   m.noBlink();
   m.text("This is a test", 13, 15);
   m.text("****************************************", 1, 20);
-  m.noCursor();
+  m.noCursor(); 
 }
 
 void demoColor() {
@@ -318,8 +327,8 @@ void demoColor() {
   m.bgColor(RED);
   m.rect((byte) m.getGraphicChar("011001"), 4, 4, 33, 20);
 
-  for (int i = 0; i < 18; i++) {
-    m.moveCursorTo(5, 5 + i);
+  for(int i=0; i<18; i++) {
+    m.moveCursorTo(5, 5+i);
 
     m.textColor(WHITE);
     m.graphic("111111");

Энэ ялгаанд хэт олон файл өөрчлөгдсөн тул зарим файлыг харуулаагүй болно