Mini projet LOO

Dependencies:   mbed APDS_9960 mbed-rtos

Dependents:   MoveYourTetris_OK

Home du projet

Revision:
29:95469b25e187
Parent:
28:e932eb039271
Child:
30:c647da947bd9
--- a/src/cSPI.cpp	Wed Apr 20 14:18:18 2016 +0000
+++ b/src/cSPI.cpp	Wed Apr 20 15:09:43 2016 +0000
@@ -8,7 +8,8 @@
 #include "cSPI.h"
 #include "cMatrice.h"
 
-
+DigitalOut _cs(p14);
+SPI _spi(p11,p12, p13);
 
 // CONSTRUCTEURS
 
@@ -19,6 +20,20 @@
     _bits = 0;
 }
 
+cSPI::cSPI(unsigned int f, unsigned int m, unsigned int b)
+{
+    _freq = f;
+    _mode = m;
+    _bits = b;
+    
+    _cs = 0;
+    wait(0.5);
+    _spi.frequency(_freq);
+    _spi.format(_bits, _mode);
+    wait(0.5);
+    _cs = 1;
+}
+
 // DESTRUCTEUR
 
 cSPI::~cSPI()
@@ -37,7 +52,7 @@
     return _mode;
 }
 
-unsigned char cSPI::getBits()
+unsigned int cSPI::getBits()
 {
     return _bits;
 }
@@ -54,7 +69,7 @@
     _mode = mode;
 }
 
-void cSPI::setBits(unsigned char bits)
+void cSPI::setBits(unsigned int bits)
 {
     _bits = bits;
 }
@@ -63,8 +78,6 @@
 
 void cSPI::initSPI(unsigned int frequence, unsigned int bits, unsigned int mode)
 {
-    DigitalOut _cs(p14);
-    SPI _spi(p11,p12, p13);
     _cs = 0;
     wait(0.5);
     _spi.frequency(frequence);
@@ -75,27 +88,32 @@
 
 int cSPI::envoyerMatrice(cMatrice & mat)  // Renvoi la reponse SPI
 {
-    DigitalOut _cs(p14); //avant p8
-    SPI _spi(p11,p12, p13);
+    int i = 0;
     _cs = 0;
-    wait(0.1);
-    for(unsigned char i = 0; i < mat.getLig(); i++) {
-        for(unsigned char j = 0; j < mat.getCol(); j ++) {
+    wait(0.5);
+    
+    for(; i < mat.getLig()/2; i++) {
+        for(int j = 0; j < mat.getCol(); j ++) {
             _spi.write(mat.getValTab(i, j));
         }
     }
-    wait(0.1);
+    wait(0.01);
+    for(; i < mat.getLig(); i++) {
+        for(int j = 0; j < mat.getCol(); j ++) {
+            _spi.write(mat.getValTab(i, j));
+        }
+    }
+    wait(0.5);
     _cs = 1; //avant 0
     return 1; // temporaire
 }
 
-void cSPI::configurerNbMatrices(const char* nb)
+void cSPI::configurerNbMatrices(const int nb)
 {
-    DigitalOut _cs(p14);
-    SPI _spi(p11,p12, p13);
     _cs = 0;
     wait(0.5);
-    _spi.write(*nb);
+    _spi.write(0x25);
+    _spi.write(nb);
     wait(0.5);
     _cs = 1;
 }
\ No newline at end of file