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 e34c77e commit 6de4235
Show file tree
Hide file tree
Showing 91 changed files with 7,160 additions and 6,712 deletions.
165 changes: 84 additions & 81 deletions examples/Generic/Fan/Generic_Ethernet_Fan/Generic_Ethernet_Fan.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,68 +25,68 @@

// we use a struct to store all states and values for our fan
// fanSpeed (1..3)
struct
struct
{
bool powerState = false;
int fanSpeed = 1;
} device_state;

bool onPowerState(const String &deviceId, bool &state)
bool onPowerState(const String &deviceId, bool &state)
{
Serial.println("Fan turned " + String(state ? "on" : "off"));
device_state.powerState = state;
return true; // request handled properly
}

// Fan rangeValue is from 1..3
bool onRangeValue(const String &deviceId, int &rangeValue)
bool onRangeValue(const String &deviceId, int &rangeValue)
{
device_state.fanSpeed = rangeValue;

Serial.println("Fan speed changed to " + String(device_state.fanSpeed));

return true;
}

// Fan rangeValueDelta is from -3..+3
bool onAdjustRangeValue(const String &deviceId, int rangeValueDelta)
bool onAdjustRangeValue(const String &deviceId, int rangeValueDelta)
{
device_state.fanSpeed += rangeValueDelta;

Serial.println("Fan speed changed about " + String(rangeValueDelta) + " to " + String(device_state.fanSpeed));

rangeValueDelta = device_state.fanSpeed; // return absolute fan speed
return true;
}

// 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 @@ -100,57 +100,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 @@ -165,38 +165,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 @@ -207,7 +209,7 @@ void setupEthernet()
}


void setupSinricPro()
void setupSinricPro()
{
SinricProFanUS &myFan = SinricPro[FAN_ID];

Expand All @@ -231,9 +233,10 @@ void setupSinricPro()
}

// main setup function
void setup()
void setup()
{
Serial.begin(BAUD_RATE);

while (!Serial);

Serial.println("\nStarting Generic_Ethernet_Fan on " + String(BOARD_NAME));
Expand All @@ -243,7 +246,7 @@ void setup()
setupSinricPro();
}

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

0 comments on commit 6de4235

Please sign in to comment.