Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
Update README.md and use allman astyle
Browse files Browse the repository at this point in the history
  • Loading branch information
khoih-prog authored Nov 25, 2022
1 parent a902ab3 commit e34c77e
Show file tree
Hide file tree
Showing 80 changed files with 5,470 additions and 5,357 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,33 +36,33 @@
unsigned long dispatchTime = millis() + MIN_IN_MS;

// setup function for setupEthernet connection
void setupEthernet()
void setupEthernet()
{
#if USE_ETHERNET_PORTENTA_H7
SRP_LOGWARN(F("======== USE_PORTENTA_H7_ETHERNET ========"));
#elif USE_NATIVE_ETHERNET
SRP_LOGWARN(F("======== USE_NATIVE_ETHERNET ========"));
#elif USE_ETHERNET_GENERIC
SRP_LOGWARN(F("=========== USE_ETHERNET_GENERIC ==========="));
SRP_LOGWARN(F("=========== USE_ETHERNET_GENERIC ==========="));
#elif USE_ETHERNET_ESP8266
SRP_LOGWARN(F("=========== USE_ETHERNET_ESP8266 ==========="));
#elif USE_ETHERNET_ENC
SRP_LOGWARN(F("=========== USE_ETHERNET_ENC ==========="));
SRP_LOGWARN(F("=========== USE_ETHERNET_ENC ==========="));
#else
SRP_LOGWARN(F("========================="));
#endif

#if !(USE_NATIVE_ETHERNET || USE_ETHERNET_PORTENTA_H7)

#if (USING_SPI2)
#if defined(CUR_PIN_MISO)
SRP_LOGWARN(F("Default SPI pinout:"));
SRP_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
SRP_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
SRP_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
SRP_LOGWARN1(F("SS:"), CUR_PIN_SS);
SRP_LOGWARN(F("========================="));
#endif
#if defined(CUR_PIN_MISO)
SRP_LOGWARN(F("Default SPI pinout:"));
SRP_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
SRP_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
SRP_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
SRP_LOGWARN1(F("SS:"), CUR_PIN_SS);
SRP_LOGWARN(F("========================="));
#endif
#else
SRP_LOGWARN(F("Default SPI pinout:"));
SRP_LOGWARN1(F("MOSI:"), MOSI);
Expand All @@ -76,57 +76,57 @@ void setupEthernet()

pinMode(USE_THIS_SS_PIN, OUTPUT);
digitalWrite(USE_THIS_SS_PIN, HIGH);

// ETHERNET_USE_RPIPICO, use default SS = 5 or 17
#ifndef USE_THIS_SS_PIN
#if defined(ARDUINO_ARCH_MBED)
#define USE_THIS_SS_PIN 5 // For Arduino Mbed core
#else
#define USE_THIS_SS_PIN 17 // For E.Philhower core
#endif
#endif
#ifndef USE_THIS_SS_PIN
#if defined(ARDUINO_ARCH_MBED)
#define USE_THIS_SS_PIN 5 // For Arduino Mbed core
#else
#define USE_THIS_SS_PIN 17 // For E.Philhower core
#endif
#endif

SRP_LOGWARN1(F("RPIPICO setCsPin:"), USE_THIS_SS_PIN);

// For other boards, to change if necessary
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
// Must use library patch for Ethernet, EthernetLarge libraries
// For RPI Pico using Arduino Mbed RP2040 core
// SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5
// For RPI Pico using E. Philhower RP2040 core
// SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17
// Default pin 5/17 to SS/CS
//Ethernet.setCsPin (USE_THIS_SS_PIN);
Ethernet.init (USE_THIS_SS_PIN);
#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
// Must use library patch for Ethernet, EthernetLarge libraries
// For RPI Pico using Arduino Mbed RP2040 core
// SCK: GPIO2, MOSI: GPIO3, MISO: GPIO4, SS/CS: GPIO5
// For RPI Pico using E. Philhower RP2040 core
// SCK: GPIO18, MOSI: GPIO19, MISO: GPIO16, SS/CS: GPIO17
// Default pin 5/17 to SS/CS

//Ethernet.setCsPin (USE_THIS_SS_PIN);
Ethernet.init (USE_THIS_SS_PIN);

#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )

#else // ETHERNET_USE_RPIPICO
// unknown board, do nothing, use default SS = 10
#ifndef USE_THIS_SS_PIN
#define USE_THIS_SS_PIN 10 // For other boards
#endif
#ifndef USE_THIS_SS_PIN
#define USE_THIS_SS_PIN 10 // For other boards
#endif

#if defined(BOARD_NAME)
SRP_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
#else
SRP_LOGWARN1(F("Unknown board setCsPin:"), USE_THIS_SS_PIN);
#endif
#if defined(BOARD_NAME)
SRP_LOGWARN3(F("Board :"), BOARD_NAME, F(", setCsPin:"), USE_THIS_SS_PIN);
#else
SRP_LOGWARN1(F("Unknown board setCsPin:"), USE_THIS_SS_PIN);
#endif

// For other boards, to change if necessary
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET )
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries
Ethernet.init (USE_THIS_SS_PIN);
#elif USE_CUSTOM_ETHERNET
// You have to add initialization for your Custom Ethernet here
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
Ethernet.init(USE_THIS_SS_PIN);
#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )
#if ( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC || USE_NATIVE_ETHERNET )
// Must use library patch for Ethernet, Ethernet2, EthernetLarge libraries

Ethernet.init (USE_THIS_SS_PIN);

#elif USE_CUSTOM_ETHERNET

// You have to add initialization for your Custom Ethernet here
// This is just an example to setCSPin to USE_THIS_SS_PIN, and can be not correct and enough
Ethernet.init(USE_THIS_SS_PIN);

#endif //( USE_ETHERNET_GENERIC || USE_ETHERNET_ENC )

#endif // ETHERNET_USE_RPIPICO

Expand All @@ -141,38 +141,40 @@ void setupEthernet()

#if !(USE_NATIVE_ETHERNET || USE_ETHERNET_PORTENTA_H7)
SRP_LOGWARN(F("========================="));
#if defined(CUR_PIN_MISO)
SRP_LOGWARN(F("Currently Used SPI pinout:"));
SRP_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
SRP_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
SRP_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
SRP_LOGWARN1(F("SS:"), CUR_PIN_SS);
#else
SRP_LOGWARN(F("Currently Used SPI pinout:"));
SRP_LOGWARN1(F("MOSI:"), MOSI);
SRP_LOGWARN1(F("MISO:"), MISO);
SRP_LOGWARN1(F("SCK:"), SCK);
SRP_LOGWARN1(F("SS:"), SS);
#endif

#if defined(CUR_PIN_MISO)
SRP_LOGWARN(F("Currently Used SPI pinout:"));
SRP_LOGWARN1(F("MOSI:"), CUR_PIN_MOSI);
SRP_LOGWARN1(F("MISO:"), CUR_PIN_MISO);
SRP_LOGWARN1(F("SCK:"), CUR_PIN_SCK);
SRP_LOGWARN1(F("SS:"), CUR_PIN_SS);
#else
SRP_LOGWARN(F("Currently Used SPI pinout:"));
SRP_LOGWARN1(F("MOSI:"), MOSI);
SRP_LOGWARN1(F("MISO:"), MISO);
SRP_LOGWARN1(F("SCK:"), SCK);
SRP_LOGWARN1(F("SS:"), SS);
#endif

SRP_LOGWARN(F("========================="));

#elif (USE_ETHERNET_PORTENTA_H7)
if (Ethernet.hardwareStatus() == EthernetNoHardware)

if (Ethernet.hardwareStatus() == EthernetNoHardware)
{
Serial.println("No Ethernet found. Stay here forever");
while (true)

while (true)
{
delay(1); // do nothing, no point running without Ethernet hardware
}
}
if (Ethernet.linkStatus() == LinkOFF)

if (Ethernet.linkStatus() == LinkOFF)
{
Serial.println("Not connected Ethernet cable");
}

#endif

Serial.print(F("Using mac index = "));
Expand All @@ -183,44 +185,45 @@ void setupEthernet()
}

// setup function for SinricPro
void setupSinricPro()
void setupSinricPro()
{
// add device to SinricPro
SinricProAirQualitySensor& mySinricProAirQualitySensor = SinricPro[DEVICE_ID];

// set callback function to device

// setup SinricPro
SinricPro.onConnected([]()
SinricPro.onConnected([]()
{
Serial.println("Connected to SinricPro");
});
SinricPro.onDisconnected([]()

SinricPro.onDisconnected([]()
{
Serial.println("Disconnected from SinricPro");
});

SinricPro.begin(APP_KEY, APP_SECRET);
}

void setup()
void setup()
{
Serial.begin(BAUD_RATE);
Serial.begin(BAUD_RATE);

while (!Serial);

Serial.println("\nStarting Generic_Ethernet_AQSensor on " + String(BOARD_NAME));
Serial.println("Version : " + String(SINRICPRO_VERSION_STR));

setupEthernet();
setupSinricPro();
}

void loop()
void loop()
{
SinricPro.handle();

if ((long)(millis() - dispatchTime) >= 0)
if ((long)(millis() - dispatchTime) >= 0)
{
SinricProAirQualitySensor &mySinricProAirQualitySensor = SinricPro[DEVICE_ID]; // get sensor device

Expand All @@ -230,7 +233,7 @@ void loop()

mySinricProAirQualitySensor.sendAirQualityEvent(pm1, pm2_5, pm10, "PERIODIC_POLL");
dispatchTime += MIN_IN_MS;

Serial.println("Sending Air Quality event ..");
}
}
Loading

0 comments on commit e34c77e

Please sign in to comment.