1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-17 22:23:10 +03:00

Cleaning the code

This commit is contained in:
mlafauci
2011-04-30 07:48:10 +02:00
parent c10210a881
commit 8d1761f009
5 changed files with 29 additions and 72 deletions

View File

@ -119,10 +119,12 @@ void setup()
{ {
Serial.begin(9600); Serial.begin(9600);
Serial.println("*** Start WiFi example ***"); Serial.println("*** Start WiFi example ***");
delay(3000);
WiFi.begin(); WiFi.begin();
// Wait for initialize WiFi
delay(3000);
scanNetworks(); scanNetworks();
int _status = startWiFiWpa(); int _status = startWiFiWpa();
@ -156,26 +158,12 @@ void loop()
{ {
byte _status = 0; byte _status = 0;
Client client = server.available(&_status); Client client = server.available(&_status);
//delay(2000);
if (client) { if (client) {
if (!gotAMessage) { if (!gotAMessage) {
Serial.println("\nWe have a new client\n"); Serial.println("\nWe have a new client\n");
client.println("Hello, client!"); client.println("Hello, client!");
gotAMessage = true; 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; static byte idx = 0;

View File

@ -42,6 +42,7 @@ void SpiDrv::begin()
// the SS pin MUST be kept as OUTPUT. // the SS pin MUST be kept as OUTPUT.
SPCR |= _BV(MSTR); SPCR |= _BV(MSTR);
SPCR |= _BV(SPE); SPCR |= _BV(SPE);
//SPSR |= _BV(SPI2X);
} }
void SpiDrv::end() { void SpiDrv::end() {
@ -76,48 +77,29 @@ int SpiDrv::waitSpiChar(unsigned char waitChar)
unsigned char _readChar = 0; unsigned char _readChar = 0;
do{ do{
_readChar = readChar(); //get data byte _readChar = readChar(); //get data byte
if (_readChar == WAIT_CMD) if (_readChar == ERR_CMD)
{
delayMicroseconds(WAIT_CHAR_DELAY);
}else if (_readChar == ERR_CMD)
{ {
WARN("Err cmd received\n");
return -1; return -1;
}else
{
delayMicroseconds(TIMEOUT_CHAR_DELAY);
} }
// else if (_readChar != waitChar)
// {
// Serial.println(_readChar,16);
// }
}while((timeout-- > 0) && (_readChar != waitChar)); }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); return (_readChar == waitChar);
} }
int SpiDrv::waitSpiChar(char waitChar, char* readChar) //int SpiDrv::waitSpiChar(char waitChar, char* readChar)
{ //{
int timeout = TIMEOUT_CHAR; // int timeout = TIMEOUT_CHAR;
do{ // do{
*readChar = spiTransfer(DUMMY_DATA); //get data byte // *readChar = spiTransfer(DUMMY_DATA); //get data byte
if (*readChar == WAIT_CMD) // if (*readChar == WAIT_CMD)
{ // {
INFO1("WAIT"); // INFO1("WAIT");
delayMicroseconds(WAIT_CHAR_DELAY); // delayMicroseconds(WAIT_CHAR_DELAY);
} // }
}while((timeout-- > 0) && (*readChar != waitChar)); // }while((timeout-- > 0) && (*readChar != waitChar));
//
return (*readChar == waitChar); // return (*readChar == waitChar);
} //}
int SpiDrv::readAndCheckChar(char checkChar, char* readChar) int SpiDrv::readAndCheckChar(char checkChar, char* readChar)
@ -153,22 +135,11 @@ char SpiDrv::readChar()
return 0; \ return 0; \
}else \ }else \
bool SpiDrv::waitSlaveReady() #define waitSlaveReady() (digitalRead(SLAVEREADY) == LOW)
{
return (digitalRead(SLAVEREADY) == LOW);
}
void SpiDrv::waitForSlaveReady() void SpiDrv::waitForSlaveReady()
{ {
#if 0
int count = 0;
while (!waitSlaveReady() && (++count<TIMEOUT_READY_SLAVE))
{
delayMicroseconds(1);
}
#else
while (!waitSlaveReady()); while (!waitSlaveReady());
#endif
} }
int SpiDrv::waitResponseCmd(uint8_t cmd, uint8_t numParam, uint8_t* param, uint8_t* param_len) int SpiDrv::waitResponseCmd(uint8_t cmd, uint8_t numParam, uint8_t* param, uint8_t* param_len)

View File

@ -5,9 +5,9 @@
#include "wifi_spi.h" #include "wifi_spi.h"
#define WAIT_CHAR_DELAY 100 #define WAIT_CHAR_DELAY 100
#define TIMEOUT_CHAR_DELAY 10 #define TIMEOUT_CHAR_DELAY 1 //10
#define TIMEOUT_READY_SLAVE 1000 #define TIMEOUT_READY_SLAVE 1000
#define SPI_TX_DELAY 5 #define SPI_TX_DELAY 1
#define SPI_START_CMD_DELAY 10 #define SPI_START_CMD_DELAY 10
@ -18,8 +18,7 @@
#define WAIT_FOR_SLAVE_SELECT() \ #define WAIT_FOR_SLAVE_SELECT() \
SpiDrv::waitForSlaveReady(); \ SpiDrv::waitForSlaveReady(); \
SpiDrv::spiSlaveSelect(); \ SpiDrv::spiSlaveSelect();
delayMicroseconds(SPI_TX_DELAY);
@ -43,7 +42,7 @@ public:
static void waitForSlaveReady(); static void waitForSlaveReady();
static int waitSpiChar(char waitChar, char* readChar); //static int waitSpiChar(char waitChar, char* readChar);
static int waitSpiChar(unsigned char waitChar); static int waitSpiChar(unsigned char waitChar);

View File

@ -302,10 +302,10 @@ uint8_t WiFiDrv::scanNetworks()
WAIT_FOR_SLAVE_SELECT(); WAIT_FOR_SLAVE_SELECT();
// Send Command // Send Command
SpiDrv::sendCmd(SCAN_NETWORKS, PARAM_NUMS_1); SpiDrv::sendCmd(SCAN_NETWORKS, PARAM_NUMS_0);
uint8_t _dummy = DUMMY_DATA; // uint8_t _dummy = DUMMY_DATA;
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM); // SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
//Wait the reply elaboration //Wait the reply elaboration
SpiDrv::waitForSlaveReady(); SpiDrv::waitForSlaveReady();

View File

@ -16,7 +16,6 @@
#define NO_SOCKET_AVAIL 255 #define NO_SOCKET_AVAIL 255
#define START_CMD 0xE0 #define START_CMD 0xE0
#define WAIT_CMD 0xE1
#define END_CMD 0xEE #define END_CMD 0xEE
#define ERR_CMD 0xEF #define ERR_CMD 0xEF