From 8d1761f0097a1d74173f717ed009e840fdc42d43 Mon Sep 17 00:00:00 2001 From: mlafauci Date: Sat, 30 Apr 2011 07:48:10 +0200 Subject: [PATCH] Cleaning the code --- .../wifi_Server_example_WPA.pde | 20 ++---- WiFi/utility/spi_drv.cpp | 65 +++++-------------- WiFi/utility/spi_drv.h | 9 ++- WiFi/utility/wifi_drv.cpp | 6 +- WiFi/utility/wifi_spi.h | 1 - 5 files changed, 29 insertions(+), 72 deletions(-) diff --git a/WiFi/examples/wifi_Server_example_WPA/wifi_Server_example_WPA.pde b/WiFi/examples/wifi_Server_example_WPA/wifi_Server_example_WPA.pde index e9b27b15d..a3a5c8b0d 100644 --- a/WiFi/examples/wifi_Server_example_WPA/wifi_Server_example_WPA.pde +++ b/WiFi/examples/wifi_Server_example_WPA/wifi_Server_example_WPA.pde @@ -119,10 +119,12 @@ void setup() { Serial.begin(9600); Serial.println("*** Start WiFi example ***"); - delay(3000); WiFi.begin(); + // Wait for initialize WiFi + delay(3000); + scanNetworks(); int _status = startWiFiWpa(); @@ -156,27 +158,13 @@ void loop() { byte _status = 0; Client client = server.available(&_status); - //delay(2000); if (client) { if (!gotAMessage) { Serial.println("\nWe have a new client\n"); client.println("Hello, client!"); gotAMessage = true; } -/* - // read the bytes incoming from the client: - char thisChar = client.read(); - // echo the bytes back to the client: - server.write(thisChar); - // echo the bytes to the server as well: - Serial.print(thisChar); - */ - /* - Serial.print("Status: "); - Serial.println(_status, 16); - delay(2000); - */ - + static byte idx = 0; while (client.available()) diff --git a/WiFi/utility/spi_drv.cpp b/WiFi/utility/spi_drv.cpp index c48ce8ba9..bd7dd16a1 100644 --- a/WiFi/utility/spi_drv.cpp +++ b/WiFi/utility/spi_drv.cpp @@ -42,6 +42,7 @@ void SpiDrv::begin() // the SS pin MUST be kept as OUTPUT. SPCR |= _BV(MSTR); SPCR |= _BV(SPE); + //SPSR |= _BV(SPI2X); } void SpiDrv::end() { @@ -76,48 +77,29 @@ int SpiDrv::waitSpiChar(unsigned char waitChar) unsigned char _readChar = 0; do{ _readChar = readChar(); //get data byte - if (_readChar == WAIT_CMD) - { - delayMicroseconds(WAIT_CHAR_DELAY); - }else if (_readChar == ERR_CMD) + if (_readChar == ERR_CMD) { + WARN("Err cmd received\n"); return -1; - }else - { - delayMicroseconds(TIMEOUT_CHAR_DELAY); } -// else if (_readChar != waitChar) -// { -// Serial.println(_readChar,16); -// } }while((timeout-- > 0) && (_readChar != waitChar)); - - if ((_readChar != waitChar)&&(timeout >=0)) - { - INFO1("*C*"); - Serial.println(_readChar,16); - }else if (timeout == 0) - { - INFO1("*T*"); - } - return (_readChar == waitChar); } -int SpiDrv::waitSpiChar(char waitChar, char* readChar) -{ - int timeout = TIMEOUT_CHAR; - do{ - *readChar = spiTransfer(DUMMY_DATA); //get data byte - if (*readChar == WAIT_CMD) - { - INFO1("WAIT"); - delayMicroseconds(WAIT_CHAR_DELAY); - } - }while((timeout-- > 0) && (*readChar != waitChar)); - - return (*readChar == waitChar); -} +//int SpiDrv::waitSpiChar(char waitChar, char* readChar) +//{ +// int timeout = TIMEOUT_CHAR; +// do{ +// *readChar = spiTransfer(DUMMY_DATA); //get data byte +// if (*readChar == WAIT_CMD) +// { +// INFO1("WAIT"); +// delayMicroseconds(WAIT_CHAR_DELAY); +// } +// }while((timeout-- > 0) && (*readChar != waitChar)); +// +// return (*readChar == waitChar); +//} int SpiDrv::readAndCheckChar(char checkChar, char* readChar) @@ -153,22 +135,11 @@ char SpiDrv::readChar() return 0; \ }else \ -bool SpiDrv::waitSlaveReady() -{ - return (digitalRead(SLAVEREADY) == LOW); -} +#define waitSlaveReady() (digitalRead(SLAVEREADY) == LOW) void SpiDrv::waitForSlaveReady() { -#if 0 - int count = 0; - while (!waitSlaveReady() && (++count