1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-03-01 23:29:28 +01: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.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())

View File

@ -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<TIMEOUT_READY_SLAVE))
{
delayMicroseconds(1);
}
#else
while (!waitSlaveReady());
#endif
}
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"
#define WAIT_CHAR_DELAY 100
#define TIMEOUT_CHAR_DELAY 10
#define TIMEOUT_CHAR_DELAY 1 //10
#define TIMEOUT_READY_SLAVE 1000
#define SPI_TX_DELAY 5
#define SPI_TX_DELAY 1
#define SPI_START_CMD_DELAY 10
@ -18,8 +18,7 @@
#define WAIT_FOR_SLAVE_SELECT() \
SpiDrv::waitForSlaveReady(); \
SpiDrv::spiSlaveSelect(); \
delayMicroseconds(SPI_TX_DELAY);
SpiDrv::spiSlaveSelect();
@ -43,7 +42,7 @@ public:
static void waitForSlaveReady();
static int waitSpiChar(char waitChar, char* readChar);
//static int waitSpiChar(char waitChar, char* readChar);
static int waitSpiChar(unsigned char waitChar);

View File

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

View File

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