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 fea942d commit a902ab3
Show file tree
Hide file tree
Showing 40 changed files with 1,253 additions and 1,113 deletions.
31 changes: 16 additions & 15 deletions examples/ESP/AirQualitySensor/AirQualitySensor/AirQualitySensor.ino
Original file line number Diff line number Diff line change
Expand Up @@ -55,60 +55,61 @@
unsigned long dispatchTime = millis() + MIN;

// setup function for WiFi connection
void setupWiFi()
void setupWiFi()
{
Serial.print("\n[Wifi]: Connecting");
WiFi.begin(WIFI_SSID, WIFI_PASS);

while (WiFi.status() != WL_CONNECTED)
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(250);
}

Serial.print("\n[WiFi]: IP-Address is ");
Serial.println(WiFi.localIP());
}

// 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 AirQualitySensor on " + String(ARDUINO_BOARD));
Serial.println("Version : " + String(SINRICPRO_VERSION_STR));

setupWiFi();
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 @@ -118,7 +119,7 @@ void loop()

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

Serial.println("Sending Air Quality event ..");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
Built by Khoi Hoang https://github.com/khoih-prog/SinricPro_Generic
Licensed under MIT license
**********************************************************************************************************************************/

/*
Example for how to use SinricPro Air Quality Sensor with Sharp Dust Sensor (GP2Y1014AU0F) connected to WemosD1 Mini
More information is here
Expand All @@ -32,9 +32,9 @@
//#define ENABLE_DEBUG

#ifdef ENABLE_DEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#define DEBUG_ESP_PORT Serial
#define NODEBUG_WEBSOCKETS
#define NDEBUG
#endif

#include <GP2YDustSensor.h> // https://github.com/luciansabo/GP2YDustSensor
Expand Down Expand Up @@ -70,67 +70,68 @@ unsigned long dispatchTime = millis() + MIN;
GP2YDustSensor dustSensor(GP2YDustSensorType::GP2Y1014AU0F, SHARP_LED_PIN, SHARP_VO_PIN);

// setup function for WiFi connection
void setupWiFi()
void setupWiFi()
{
Serial.print("\n[Wifi]: Connecting");
WiFi.begin(WIFI_SSID, WIFI_PASS);

while (WiFi.status() != WL_CONNECTED)
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(250);
}

Serial.print("\n[WiFi]: IP-Address is ");
Serial.println(WiFi.localIP());
}

// 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 setupDustSensor()
void setupDustSensor()
{
//dustSensor.setBaseline(0.4); // set no dust voltage according to your own experiments
//dustSensor.setCalibrationFactor(1.1); // calibrate against precision instrument
dustSensor.begin();
}

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

while (!Serial);

Serial.println("\nStarting AirQualitySensor_GP2Y1014AU0F on " + String(ARDUINO_BOARD));
Serial.println("Version : " + String(SINRICPRO_VERSION_STR));

setupWiFi();
setupSinricPro();
}

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

if ((long)(millis() - dispatchTime) >= 0)
if ((long)(millis() - dispatchTime) >= 0)
{
Serial.print("Dust density: ");
Serial.print(dustSensor.getDustDensity());
Expand Down
35 changes: 18 additions & 17 deletions examples/ESP/Blinds/Blinds.ino
Original file line number Diff line number Diff line change
Expand Up @@ -54,45 +54,45 @@
int blindsPosition = 0;
bool powerState = false;

bool onPowerState(const String &deviceId, bool &state)
bool onPowerState(const String &deviceId, bool &state)
{
Serial.printf("Device %s power turned %s \r\n", deviceId.c_str(), state ? "on" : "off");
powerState = state;
return true; // request handled properly
}

bool onSetPosition(const String &deviceId, int &position)
bool onSetPosition(const String &deviceId, int &position)
{
Serial.printf("Device %s set position to %d\r\n", deviceId.c_str(), position);
return true; // request handled properly
}

bool onAdjustPosition(const String &deviceId, int &positionDelta)
bool onAdjustPosition(const String &deviceId, int &positionDelta)
{
blindsPosition += positionDelta;
Serial.printf("Device %s position changed about %i to %d\r\n", deviceId.c_str(), positionDelta, blindsPosition);
positionDelta = blindsPosition; // calculate and return absolute position

return true; // request handled properly
}

// setup function for WiFi connection
void setupWiFi()
void setupWiFi()
{
Serial.print("\n[Wifi]: Connecting");
WiFi.begin(WIFI_SSID, WIFI_PASS);

while (WiFi.status() != WL_CONNECTED)
while (WiFi.status() != WL_CONNECTED)
{
Serial.print(".");
delay(250);
}

Serial.print("\n[WiFi]: IP-Address is ");
Serial.println(WiFi.localIP());
}

void setupSinricPro()
void setupSinricPro()
{
// get a new Blinds device from SinricPro
SinricProBlinds &myBlinds = SinricPro[BLINDS_ID];
Expand All @@ -101,33 +101,34 @@ void setupSinricPro()
myBlinds.onAdjustPosition(onAdjustPosition);

// 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);
}

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

while (!Serial);

Serial.println("\nStarting Blinds on " + String(ARDUINO_BOARD));
Serial.println("Version : " + String(SINRICPRO_VERSION_STR));

setupWiFi();
setupSinricPro();
}

void loop()
void loop()
{
SinricPro.handle();
}
15 changes: 8 additions & 7 deletions examples/ESP/Camera/Camera.ino
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ IPAddress secondaryDNS(8, 8, 4, 4); //optional
bool onPowerState(const String &deviceId, bool &state)
{
Serial.printf("Device %s turned %s (via SinricPro) \r\n", deviceId.c_str(), state ? "on" : "off");

return true; // request handled properly
}

Expand All @@ -105,12 +105,12 @@ void setupSinricPro()
mySwitch.onPowerState(onPowerState);

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

SinricPro.onDisconnected([]()
{
Serial.println("Disconnected from SinricPro");
});
Expand Down Expand Up @@ -146,7 +146,7 @@ void setupCamera()
camera_config_t config;
config.ledc_channel = LEDC_CHANNEL_0;
config.ledc_timer = LEDC_TIMER_0;

config.pin_d0 = Y2_GPIO_NUM;
config.pin_d1 = Y3_GPIO_NUM;
config.pin_d2 = Y4_GPIO_NUM;
Expand All @@ -155,7 +155,7 @@ void setupCamera()
config.pin_d5 = Y7_GPIO_NUM;
config.pin_d6 = Y8_GPIO_NUM;
config.pin_d7 = Y9_GPIO_NUM;

config.pin_xclk = XCLK_GPIO_NUM;
config.pin_pclk = PCLK_GPIO_NUM;
config.pin_vsync = VSYNC_GPIO_NUM;
Expand All @@ -180,7 +180,7 @@ void setupCamera()
if (psramFound())
{
Serial.println("psram found");

config.frame_size = FRAMESIZE_UXGA;
config.jpeg_quality = 40; //10-63 lower number means higher quality
config.fb_count = 2;
Expand Down Expand Up @@ -247,6 +247,7 @@ void handleStreaming()
void setup()
{
Serial.begin(BAUD_RATE);

while (!Serial); //wait for serial connection.

Serial.println("\nStarting Camera on " + String(ARDUINO_BOARD));
Expand Down
Loading

0 comments on commit a902ab3

Please sign in to comment.