Temp Fork
Dependencies: MMA8451Q Multi_WS2811 NVIC_set_all_priorities TSI cc3000_hostdriver_mbedsocket mbed
Fork of CubicHand by
Revision 13:c701f1122797, committed 2014-12-06
- Comitter:
- kalbers
- Date:
- Sat Dec 06 23:25:32 2014 +0000
- Parent:
- 12:df94d17b5bee
- Child:
- 14:0c4a26dc6873
- Child:
- 16:a3de0c0dbe33
- Commit message:
- Fixed Glove Wifi class to initialize correctly.
Changed in this revision
--- a/DataGlove.cpp Fri Dec 05 22:54:35 2014 +0000
+++ b/DataGlove.cpp Sat Dec 06 23:25:32 2014 +0000
@@ -1,9 +1,8 @@
#include "DataGlove.h"
-DataGlove::DataGlove():
-notConnectedCount(0)
+DataGlove::DataGlove()
{
-
+ notConnectedCount = 0;
}
DataGlove::~DataGlove()
@@ -13,7 +12,7 @@
void DataGlove::Init()
{
- GloveSocket.Init();
+ //GloveSocket.Init();
GloveSocket.Connect();
SendBuf[0] = '$';
SendBuf[1] = 0x0A;
@@ -26,7 +25,7 @@
void DataGlove::Receive()
{
- numReceived = GloveSocket.GetDataFromBuffer(Buf, 99);
+ numReceived = GloveSocket.GetDataFromBuffer(Buf, 99);
if(numReceived >= 42 && Buf[0] == '$') {
gyrox = ((int16_t *)Buf)[5];
gyroy = ((int16_t *)Buf)[6];
--- a/DataGlove.h Fri Dec 05 22:54:35 2014 +0000
+++ b/DataGlove.h Sat Dec 06 23:25:32 2014 +0000
@@ -1,5 +1,7 @@
#include "GloveWifi.h"
+#pragma once
+
class DataGlove
{
public:
--- a/GloveWifi.cpp Fri Dec 05 22:54:35 2014 +0000
+++ b/GloveWifi.cpp Sat Dec 06 23:25:32 2014 +0000
@@ -8,26 +8,23 @@
#define SSID "CubeNet"
#define PASSWORD "modelbased"
-#define MMA8451_I2C_ADDRESS (0x1d<<1)
-
-
-using namespace mbed_cc3000;
+#define ECHO_SERVER_ADDRESS "192.168.1.33"
+#define ECHO_SERVER_PORT 2000
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
-
-GloveWifi::GloveWifi() :
-ECHO_SERVER_ADDRESS("192.168.1.33"),
-ECHO_SERVER_PORT(2000)
+GloveWifi::GloveWifi()
{
}
GloveWifi::~GloveWifi()
{
+ delete socket;
+ delete wifi;
}
void GloveWifi::Init()
{
- pc = new Serial(USBTX, USBRX);
//Init from the cc3000 example
DigitalOut PWR_EN1(PTB2);
DigitalOut PWR_EN2(PTB3);
@@ -42,15 +39,14 @@
NVIC_SetPriority(SysTick_IRQn, 0x2); // SysTick set to lower priority than Wi-Fi SPI bus interrupt
PORTA->PCR[16] |= PORT_PCR_ISF_MASK;
PORTA->ISFR |= (1 << 16);
-
- pc->baud(115200);
}
void GloveWifi::Connect()
{
- //TODO: Make this call (or recall) the initial constructor.
+
wifi = new cc3000(PTD4, PTC9, PTD0, SPI(PTD2, PTD3, PTD1), SSID, PASSWORD, WPA2, false);
wifi->init();
+ socket = new TCPSocketConnection;
if (wifi->connect() == -1)
{
printf("Failed to connect. Please verify connection details and try again. \r\n");
@@ -58,30 +54,31 @@
{
printf("IP address: %s \r\n", wifi->getIPAddress());
}
- while (socket.connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0)
+ while (socket->connect(ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT) < 0)
{
printf("Unable to connect to (%s) on port (%d) \r\n", ECHO_SERVER_ADDRESS, ECHO_SERVER_PORT);
wait(1);
}
- socket.set_blocking(true);
+ socket->set_blocking(true);
printf("Connected!\r\n");
}
void GloveWifi::Disconnect()
{
- socket.close();
+ socket->close();
wifi->disconnect();
+ delete socket;
delete wifi;
}
uint8_t GloveWifi::GetDataFromBuffer(uint8_t * buf, uint16_t size)
{
- return socket.receive((char *)buf, size);
+ return socket->receive((char *)buf, size);
}
uint8_t GloveWifi::SendDataToGlove(uint8_t * buf, uint16_t size)
{
- return socket.send((char *)buf, size);
+ return socket->send((char *)buf, size);
}
\ No newline at end of file
--- a/GloveWifi.h Fri Dec 05 22:54:35 2014 +0000
+++ b/GloveWifi.h Sat Dec 06 23:25:32 2014 +0000
@@ -2,6 +2,10 @@
#include "cc3000.h"
#include "TCPSocketConnection.h"
+#pragma once
+
+using namespace mbed_cc3000;
+
class GloveWifi
{
public:
@@ -14,10 +18,7 @@
uint8_t SendDataToGlove(uint8_t * buf, uint16_t size);
private:
- const char* ECHO_SERVER_ADDRESS;
- const int ECHO_SERVER_PORT;
- TCPSocketConnection socket;
+ TCPSocketConnection * socket;
cc3000 * wifi;
- Serial * pc;
};
\ No newline at end of file
--- a/main.cpp Fri Dec 05 22:54:35 2014 +0000
+++ b/main.cpp Sat Dec 06 23:25:32 2014 +0000
@@ -6,13 +6,18 @@
DataGlove MasterGlove;
+
int main()
{
+ Serial pc(USBTX, USBRX);
+ pc.baud(115200);
+ pc.printf("Connceted to PC \r\n");
MasterGlove.Init();
- printf("DataGlove Cube Client\r\n");
+ pc.printf("DataGlove Cube Client\r\n");
while(true)
{
- MasterGlove.Receive();
- printf("Looping \r\n");
+ //MasterGlove.Receive();
+ pc.printf("Looping \r\n");
+ wait(0.5);
}
}
