Prometheus / Pixy

Dependents:   PixyTest PixyTest

Files at this revision

API Documentation at this revision

Comitter:
ZHAW_Prometheus
Date:
Wed May 17 07:37:43 2017 +0000
Parent:
0:a2603d7fa0ac
Commit message:
Vers. 17.05.2017

Changed in this revision

Pixy.cpp Show annotated file Show diff for this revision Revisions of this file
Pixy.h Show annotated file Show diff for this revision Revisions of this file
PixyLink.h Show annotated file Show diff for this revision Revisions of this file
PixyLinkI2C.h Show annotated file Show diff for this revision Revisions of this file
--- a/Pixy.cpp	Fri May 05 12:03:13 2017 +0000
+++ b/Pixy.cpp	Wed May 17 07:37:43 2017 +0000
@@ -1,23 +1,15 @@
 #include "Pixy.h"
 
-Pixy::Pixy(Pixy::LinkType linkType, PinName mosi_sda_tx, PinName miso_scl_rx, PinName sclk)
+
+Pixy::Pixy(PinName mosi_sda_tx, PinName miso_scl_rx)
 {
-    switch (linkType) {
-        /*case SPI:
-            m_link = new PixyLinkSPI(mosi_sda_tx, miso_scl_rx, sclk);
-            break;*/
-        case I2C:
-            m_link = new PixyLinkI2C(mosi_sda_tx, miso_scl_rx);
-            break;
-        /*case UART:
-            m_link = new PixyLinkUART(mosi_sda_tx, miso_scl_rx);
-            break;*/
-    };
+    m_link = new PixyLinkI2C(mosi_sda_tx, miso_scl_rx);
     pc = 0;
     skipStart = false;
     blockCount = 0;
     blockArraySize = PIXY_INITIAL_ARRAYSIZE;
     blocks = new Block[blockArraySize];
+
 }
 
 Pixy::~Pixy()
@@ -42,11 +34,11 @@
         checksum = m_link->getWord();
         if (checksum == PIXY_START_WORD) { // we've reached the beginning of the next frame
             skipStart = true;
-            //if (pc)
-            //  pc->printf("skip\n\r");
+        //  if (pc)
+        //  pc->printf("skip\n\r");
             return blockCount;
         } else if (checksum == 0)
-            return blockCount;
+            return blockCount; // Made by Renske
 
         if (blockCount > blockArraySize)
             resize();
@@ -59,10 +51,12 @@
             *((uint16_t *)block + i) = w;
         }
 
-        if (checksum == sum)
+        if (checksum == sum){
             blockCount++;
-        else if (pc)
-            pc->printf("cs error\n\r");
+            //w = m_link->getWord();
+            }
+        else if (pc) {
+            pc->printf("cs error\n\r");}
 
         w = m_link->getWord();
         if (w != PIXY_START_WORD)
@@ -71,18 +65,6 @@
     return blockCount;
 }
 
-int8_t Pixy::setServos(uint16_t s0, uint16_t s1)
-{
-    uint8_t outBuf[6];
-
-    outBuf[0] = 0x00;
-    outBuf[1] = 0xff;
-    *(uint16_t *)(outBuf + 2) = s0;
-    *(uint16_t *)(outBuf + 4) = s1;
-
-    return m_link->send(outBuf, 6);
-}
-
 void Pixy::setAddress(uint8_t addr)
 {
     m_link->setAddress(addr);
@@ -122,4 +104,4 @@
     memcpy(newBlocks, blocks, sizeof(Block) * blockCount);
     delete[] blocks;
     blocks = newBlocks;
-}
+}
\ No newline at end of file
--- a/Pixy.h	Fri May 05 12:03:13 2017 +0000
+++ b/Pixy.h	Wed May 17 07:37:43 2017 +0000
@@ -1,13 +1,11 @@
-#ifndef TUIASI_PIXY_H
-#define TUIASI_PIXY_H
+#ifndef PIXY_H
+#define PIXY_H
 
 #include "mbed.h"
-//#include "PixyLinkSPI.h"
 #include "PixyLinkI2C.h"
-//#include "PixyLinkUART.h"
 
 struct Block {
-    void print(Serial &pc) {
+   void print(Serial &pc) {
         pc.printf("sig: %d x: %d y: %d width: %d height: %d\n", signature, x, y, width, height);
     };
     uint16_t signature;
@@ -20,8 +18,7 @@
 class Pixy
 {
 public:
-    enum LinkType {SPI, I2C, UART};
-    Pixy(LinkType linkType, PinName mosi_sda_tx, PinName miso_scl_rx, PinName sclk = NC);
+    Pixy(PinName mosi_sda_tx, PinName miso_scl_rx);
     ~Pixy();
     uint16_t getBlocks(uint16_t maxBlocks=1000);
     int8_t setServos(uint16_t s0, uint16_t s1);
@@ -35,7 +32,7 @@
     static const uint8_t PIXY_MAXIMUM_ARRAYSIZE = 130;
     static const uint16_t PIXY_START_WORD = 0xaa55;
     static const uint16_t PIXY_START_WORDX = 0x55aa;
-    static const uint8_t PIXY_DEFAULT_ADDR = 0x54;  // I2C
+    static const uint8_t PIXY_DEFAULT_ADDR = 0xAC;  // I2C Adresse
 
     bool getStart();
     void resize();
@@ -47,4 +44,4 @@
     PixyLink *m_link;
     Serial *pc;
 };
-#endif //TUIASI_PIXY_H
+#endif //PIXY_H
\ No newline at end of file
--- a/PixyLink.h	Fri May 05 12:03:13 2017 +0000
+++ b/PixyLink.h	Wed May 17 07:37:43 2017 +0000
@@ -1,5 +1,5 @@
-#ifndef TUIASI_PIXYLINK_H
-#define TUIASI_PIXYLINK_H
+#ifndef PIXYLINK_H
+#define PIXYLINK_H
 
 #include "stdint.h"
 
@@ -14,9 +14,8 @@
     virtual uint16_t getWord() = 0;
     virtual uint8_t getByte() = 0;
     virtual int8_t send(uint8_t *data, uint8_t len) = 0;
-
 protected:
     uint8_t m_addr;
 };
 
-#endif //TUIASI_PIXYLINK_H
+#endif //PIXYLINK_H
\ No newline at end of file
--- a/PixyLinkI2C.h	Fri May 05 12:03:13 2017 +0000
+++ b/PixyLinkI2C.h	Wed May 17 07:37:43 2017 +0000
@@ -1,5 +1,5 @@
-#ifndef TUIASI_PIXYLINKI2C_H
-#define TUIASI_PIXYLINKI2C_H
+#ifndef PIXYLINKI2C_H
+#define PIXYLINKI2C_H
 
 #include "I2C.h"
 #include "PixyLink.h"
@@ -8,8 +8,9 @@
 {
 public:
     PixyLinkI2C(PinName sda, PinName scl) :
-        PixyLink(PIXY_DEFAULT_ADDR), I2C(sda, scl) {
-    };
+        PixyLink(PIXY_DEFAULT_ADDR), I2C(sda, scl){
+            I2C::frequency(100000);
+            };
 
     virtual uint16_t getWord() {
         uint8_t data[2] = {0, 0};
@@ -29,7 +30,7 @@
 
 
 private:
-    static const uint8_t PIXY_DEFAULT_ADDR = 0x54;
+    static const uint8_t PIXY_DEFAULT_ADDR = 0xAC;
 };
 
-#endif //TUIASI_PIXYLINKI2C_H
+#endif //PIXYLINKI2C_H
\ No newline at end of file