Skip to content

Commit

Permalink
Merge pull request #94 from airgradienthq/develop
Browse files Browse the repository at this point in the history
Next version 3.1.0-beta.1
  • Loading branch information
pnt325 authored Apr 25, 2024
2 parents 26546a6 + c025bae commit 4fac3fd
Show file tree
Hide file tree
Showing 18 changed files with 1,892 additions and 9 deletions.
1 change: 1 addition & 0 deletions examples/BASIC/BASIC.ino
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ void setup() {
/** Init AirGradient server */
apiClient.begin();
apiClient.setAirGradient(&ag);
configuration.setAirGradient(&ag);
wifiConnector.setAirGradient(&ag);

/** Show boot display */
Expand Down
2 changes: 1 addition & 1 deletion examples/OneOpenAir/OneOpenAir.ino
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ void setup() {

/** Init sensor */
boardInit();

configuration.setAirGradient(ag);
oledDisplay.setAirGradient(ag);
stateMachine.setAirGradient(ag);
wifiConnector.setAirGradient(ag);
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=AirGradient Air Quality Sensor
version=3.0.10beta2
version=3.1.0-beta.1
author=AirGradient <[email protected]>
maintainer=AirGradient <[email protected]>
sentence=ESP32-C3 / ESP8266 library for air quality monitor measuring PM, CO2, Temperature, TVOC and Humidity with OLED display.
Expand Down
8 changes: 8 additions & 0 deletions src/AgConfigure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -815,3 +815,11 @@ int Configuration::getTvocLearningOffset(void) {
int Configuration::getNoxLearningOffset(void) {
return config.noxLearningOffset;
}

String Configuration::wifiSSID(void) {
return "airgradient-" + ag->deviceId();
}

String Configuration::wifiPass(void) { return String("cleanair"); }

void Configuration::setAirGradient(AirGradient *ag) { this->ag = ag;}
6 changes: 6 additions & 0 deletions src/AgConfigure.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "App/AppDef.h"
#include "Main/PrintLog.h"
#include "AirGradient.h"
#include <Arduino.h>

class Configuration : public PrintLog {
Expand Down Expand Up @@ -36,6 +37,8 @@ class Configuration : public PrintLog {
bool _noxLearnOffsetChanged;
bool _tvocLearningOffsetChanged;

AirGradient* ag;

String getLedBarModeName(LedBarMode mode);
void saveConfig(void);
void loadConfig(void);
Expand Down Expand Up @@ -83,6 +86,9 @@ class Configuration : public PrintLog {
bool tvocLearnOffsetChanged(void);
int getTvocLearningOffset(void);
int getNoxLearningOffset(void);
String wifiSSID(void);
String wifiPass(void);
void setAirGradient(AirGradient *ag);
};

#endif /** _AG_CONFIG_H_ */
25 changes: 24 additions & 1 deletion src/AgOledDisplay.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "AgOledDisplay.h"
#include "Libraries/U8g2/src/U8g2lib.h"
#include "Libraries/QRCode/src/qrcode.h"

/** Cast U8G2 */
#define DISP() ((U8G2_SH1106_128X64_NONAME_F_HW_I2C *)(this->u8g2))
Expand Down Expand Up @@ -201,7 +202,7 @@ void OledDisplay::showDashboard(const char *status) {
logInfo(strStatus);

int strWidth = DISP()->getStrWidth(status);
DISP()->drawStr((126 - strWidth) / 2, 10, status);
DISP()->drawStr((DISP()->getWidth() - strWidth) / 2, 10, status);

/** Show WiFi NA*/
if (strcmp(status, "WiFi N/A") == 0) {
Expand Down Expand Up @@ -285,3 +286,25 @@ void OledDisplay::showDashboard(const char *status) {
DISP()->drawStr(85, 63, strBuf);
} while (DISP()->nextPage());
}

void OledDisplay::showWiFiQrCode(String content, String label) {
QRCode qrcode;
int version = 6;
int x_start = (DISP()->getWidth() - (version * 4 + 17))/ 2;
uint8_t qrcodeData[qrcode_getBufferSize(version)];
qrcode_initText(&qrcode, qrcodeData, version, 0, content.c_str());

DISP()->firstPage();
do {
for (uint8_t y = 0; y < qrcode.size; y++) {
for (uint8_t x = 0; x < qrcode.size; x++) {
if (qrcode_getModule(&qrcode, x, y)) {
DISP()->drawPixel(x + x_start, y);
}
}
}
DISP()->setFont(u8g2_font_t0_16_tf);
x_start = (DISP()->getWidth() - DISP()->getStrWidth(label.c_str()))/2;
DISP()->drawStr(x_start, 60, label.c_str());
} while (DISP()->nextPage());
}
1 change: 1 addition & 0 deletions src/AgOledDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class OledDisplay : public PrintLog {
const char *line4);
void showDashboard(void);
void showDashboard(const char *status);
void showWiFiQrCode(String content, String label);
};

#endif /** _AG_OLED_DISPLAY_H_ */
17 changes: 12 additions & 5 deletions src/AgStateMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,19 @@ void StateMachine::displayHandle(AgStateMachineState state) {
switch (state) {
case AgStateMachineWiFiManagerMode:
case AgStateMachineWiFiManagerPortalActive: {
// if (wifiConnectCountDown >= 0) {
// String line1 = String(wifiConnectCountDown) + "s to connect";
// String line2 = "to WiFi hotspot:";
// String line3 = "\"airgradient-";
// String line4 = ag->deviceId() + "\"";
// disp.setText(line1, line2, line3, line4);
// wifiConnectCountDown--;
// }
if (wifiConnectCountDown >= 0) {
String line1 = String(wifiConnectCountDown) + "s to connect";
String line2 = "to WiFi hotspot:";
String line3 = "\"airgradient-";
String line4 = ag->deviceId() + "\"";
disp.setText(line1, line2, line3, line4);
String qrContent = "WIFI:S:" + config.wifiSSID() +
";T:WPA;P:" + config.wifiPass() + ";;";
String label = "Scan me (" + String(wifiConnectCountDown) + String(")");
disp.showWiFiQrCode(qrContent, label);
wifiConnectCountDown--;
}
break;
Expand Down
1 change: 0 additions & 1 deletion src/AgStateMachine.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class StateMachine : public PrintLog {
OledDisplay &disp;
Measurements &value;
Configuration &config;

bool addToDashBoard = false;
uint32_t addToDashboardTime;
int wifiConnectCountDown;
Expand Down
1 change: 1 addition & 0 deletions src/Libraries/QRCode/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.DS_Store
26 changes: 26 additions & 0 deletions src/Libraries/QRCode/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
The MIT License (MIT)

This library is written and maintained by Richard Moore.
Major parts were derived from Project Nayuki's library.

Copyright (c) 2017 Richard Moore (https://github.com/ricmoo/QRCode)
Copyright (c) 2017 Project Nayuki (https://www.nayuki.io/page/qr-code-generator-library)

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Loading

0 comments on commit 4fac3fd

Please sign in to comment.