Commit f0d8dc8f6025a054c5f9c966a4d54a34d943f499

Authored by mduquesn
1 parent baa616ee

FULL ok keygrab

avec le clavier 12 touches capacitives Adafruit MPR121
version debug
Showing 1 changed file with 106 additions and 11 deletions   Show diff stats
@@ -20,14 +20,20 @@ Adafruit_MPR121 cap = Adafruit_MPR121(); @@ -20,14 +20,20 @@ Adafruit_MPR121 cap = Adafruit_MPR121();
20 uint16_t lasttouched = 0; 20 uint16_t lasttouched = 0;
21 uint16_t currtouched = 0; 21 uint16_t currtouched = 0;
22 int tab[]={3,7,15,2,6,14,1,5,9,0,4,8}; 22 int tab[]={3,7,15,2,6,14,1,5,9,0,4,8};
23 -File fichier; 23 +File fichier,fichier2;
24 String filename="texte.txt"; 24 String filename="texte.txt";
25 -char c; 25 +String filename2="texto.txt";
  26 +char c; boolean written;
  27 +
  28 +
  29 +
  30 +
  31 +
  32 +
  33 +
  34 +
26 35
27 36
28 -void Printstr(String msg){  
29 - Serial.println(msg);  
30 -}  
31 37
32 void keyboardprint ( String texte ){ 38 void keyboardprint ( String texte ){
33 int i = 0; 39 int i = 0;
@@ -51,6 +57,16 @@ void keyboardprint ( String texte ){ @@ -51,6 +57,16 @@ void keyboardprint ( String texte ){
51 } 57 }
52 } 58 }
53 59
  60 +
  61 +
  62 +
  63 +
  64 +
  65 +
  66 +
  67 +
  68 +
  69 +
54 void setup() { 70 void setup() {
55 //keyboard out 71 //keyboard out
56 pinMode(2, INPUT_PULLUP); 72 pinMode(2, INPUT_PULLUP);
@@ -68,11 +84,17 @@ void setup() { @@ -68,11 +84,17 @@ void setup() {
68 } 84 }
69 Serial.println("SD OK"); 85 Serial.println("SD OK");
70 86
71 - //File 87 + //File1
72 while( !(fichier=SD.open(filename,FILE_WRITE)) ){ 88 while( !(fichier=SD.open(filename,FILE_WRITE)) ){
73 delay(1000); 89 delay(1000);
74 } 90 }
75 Serial.println("file OK"); 91 Serial.println("file OK");
  92 +
  93 + //File2
  94 + while( !(fichier2=SD.open(filename,FILE_WRITE)) ){
  95 + delay(1000);
  96 + }
  97 + Serial.println("file2 OK");
76 98
77 //keyboard in 99 //keyboard in
78 Serial.println("Adafruit MPR121 Capacitive Touch sensor test"); 100 Serial.println("Adafruit MPR121 Capacitive Touch sensor test");
@@ -103,12 +125,25 @@ void setup() { @@ -103,12 +125,25 @@ void setup() {
103 void loop() { 125 void loop() {
104 // Get the currently touched pads 126 // Get the currently touched pads
105 currtouched = cap.touched(); 127 currtouched = cap.touched();
106 - /* 128 + written=false;
  129 +
  130 +
  131 +
  132 +
  133 +
107 //effacement de la mémoire 134 //effacement de la mémoire
108 if ((currtouched & _BV(2)) && !(lasttouched & _BV(2)) ) { 135 if ((currtouched & _BV(2)) && !(lasttouched & _BV(2)) ) {
109 Serial.println("D"); 136 Serial.println("D");
  137 + fichier.close();
  138 + SD.remove(filename);
  139 + fichier=SD.open(filename,FILE_WRITE);
  140 +
  141 + fichier2.close();
  142 + SD.remove(filename2);
  143 + fichier=SD.open(filename2,FILE_WRITE);
  144 +
110 //effacer ce qui est présent dans la carte SD 145 //effacer ce qui est présent dans la carte SD
111 - }*/ 146 + }
112 //récupération des entrées 147 //récupération des entrées
113 if ((currtouched & _BV(5)) && !(lasttouched & _BV(5))) { 148 if ((currtouched & _BV(5)) && !(lasttouched & _BV(5))) {
114 Serial.println("R"); 149 Serial.println("R");
@@ -116,30 +151,89 @@ void loop() { @@ -116,30 +151,89 @@ void loop() {
116 while((c=fichier.read())!=-1){ 151 while((c=fichier.read())!=-1){
117 Keyboard.write(c); 152 Keyboard.write(c);
118 } 153 }
  154 + Keyboard.write(KEY_RETURN);
  155 + Keyboard.write(KEY_RETURN);
  156 +
  157 + fichier2.seek(0);
  158 + while((c=fichier2.read())!=-1){
  159 + Keyboard.write(c);
  160 + }
119 } 161 }
120 - 162 +
  163 +
  164 +
  165 +
  166 +
  167 +
  168 +
  169 +
  170 +
  171 +
  172 +
  173 +
121 174
122 for (uint8_t i=0; i<12; i++) { 175 for (uint8_t i=0; i<12; i++) {
  176 +
  177 + if(i==2 || i==5)i++;//ne pas traiter R et D
  178 +
123 // it if *is* touched and *wasnt* touched before, alert! 179 // it if *is* touched and *wasnt* touched before, alert!
124 if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) { 180 if ((currtouched & _BV(i)) && !(lasttouched & _BV(i)) ) {
  181 + written=true;
125 Serial.print(tab[i]); Serial.println(" touched"); 182 Serial.print(tab[i]); Serial.println(" touched");
126 c=('0'+tab[i]); 183 c=('0'+tab[i]);
  184 + fichier2.write('<');
  185 + fichier2.write(c);
  186 + fichier2.write('>');
127 Keyboard.press(c); 187 Keyboard.press(c);
128 } 188 }
  189 +
129 // if it *was* touched and now *isnt*, alert! 190 // if it *was* touched and now *isnt*, alert!
130 if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) { 191 if (!(currtouched & _BV(i)) && (lasttouched & _BV(i)) ) {
  192 + written=true;
131 Serial.print(tab[i]); Serial.println(" released"); 193 Serial.print(tab[i]); Serial.println(" released");
132 c=('0'+tab[i]); 194 c=('0'+tab[i]);
  195 + fichier2.write('>');
  196 + fichier2.write(c);
  197 + fichier2.write('<');
  198 +
  199 + fichier.write(c);
133 Keyboard.release(c); 200 Keyboard.release(c);
134 } 201 }
135 - if(i==1 || i==5)i++;  
136 } 202 }
  203 + if(written){
  204 + fichier.write('\n');
  205 + fichier.flush();//force l'enregistrement physique des données
  206 + fichier2.write('\n');
  207 + fichier2.flush();
  208 + }
  209 +
  210 +
  211 +
  212 +
  213 +
  214 +
  215 +
  216 +
  217 +
137 218
138 // reset our state 219 // reset our state
139 lasttouched = currtouched; 220 lasttouched = currtouched;
140 221
141 // comment out this line for detailed data from the sensor! 222 // comment out this line for detailed data from the sensor!
142 return; 223 return;
  224 +
  225 +
  226 +
  227 +
  228 +
  229 +
  230 +
  231 +
  232 +
  233 +
  234 +
  235 +
  236 +
143 237
144 // debugging info, what 238 // debugging info, what
145 Serial.print("\t\t\t\t\t\t\t\t\t\t\t\t\t 0x"); Serial.println(cap.touched(), HEX); 239 Serial.print("\t\t\t\t\t\t\t\t\t\t\t\t\t 0x"); Serial.println(cap.touched(), HEX);
@@ -159,4 +253,5 @@ void loop() { @@ -159,4 +253,5 @@ void loop() {
159 } 253 }
160 254
161 255
162 -// >v< <v> 256 +// v released >v<
  257 +// v pressed <v>
163 \ No newline at end of file 258 \ No newline at end of file