Skip to content

Commit

Permalink
Merge pull request #242 from J-A-A-M/test_mode
Browse files Browse the repository at this point in the history
Технічне: Тестовий режим для JAAM 2
  • Loading branch information
Foroxon authored Nov 27, 2024
2 parents e4c802a + 8f199d3 commit 8c50d74
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 7 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/compile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,26 @@
with:
name: firmware-lite.bin
path: ${{ github.workspace }}/firmware-lite.bin
compile_jaam2_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Switch to TEST_MODE build
run: |
sed -i 's/#define LITE ./#define LITE 0/' ${{ github.workspace }}/firmware/src/Definitions.h
sed -i 's/#define TEST_MODE ./#define TEST_MODE 1/' ${{ github.workspace }}/firmware/src/Definitions.h
- name: Compile test firmware
uses: ./.github/workflows/firmware-compile
with:
project-folder: firmware
- name: Copy bin file
run: |
cp -f ${{ github.workspace }}/firmware/.pio/build/firmware/firmware.bin ${{ github.workspace }}/firmware-jaam2-test.bin
- name: Upload firmware lite
uses: actions/upload-artifact@v4
with:
name: firmware-jaam2-test.bin
path: ${{ github.workspace }}/firmware-jaam2-test.bin
# check_firmware:
# runs-on: ubuntu-latest
# steps:
Expand Down
11 changes: 11 additions & 0 deletions firmware/src/Definitions.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define LITE 0
#define TEST_MODE 0
#if LITE
#define ARDUINO_OTA_ENABLED 0
#define FW_UPDATE_ENABLED 0
Expand All @@ -9,6 +10,16 @@
#define SHT3X_ENABLED 0
#define BH1750_ENABLED 0
#define BUZZER_ENABLED 0
#elif TEST_MODE
#define ARDUINO_OTA_ENABLED 0
#define FW_UPDATE_ENABLED 0
#define HA_ENABLED 0
#define DISPLAY_ENABLED 1
#define BME280_ENABLED 1
#define SHT2X_ENABLED 1
#define SHT3X_ENABLED 1
#define BH1750_ENABLED 1
#define BUZZER_ENABLED 1
#else
#define ARDUINO_OTA_ENABLED 0
#define FW_UPDATE_ENABLED 1
Expand Down
64 changes: 57 additions & 7 deletions firmware/src/JaamFirmware.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ int currentDimDisplay = 0;
#define SHORT_PRESS_TIME 500 // 500 milliseconds
#define LONG_PRESS_TIME 500 // 500 milliseconds
struct ButtonState {
char* name;
int lastState = LOW; // the previous state from the input pin
int currentState; // the current reading from the input pin
unsigned long pressedTime = 0;
Expand Down Expand Up @@ -1026,14 +1027,24 @@ void buttonUpdate(ButtonState &button, uint8_t pin, int mode, int modeLong) {

long pressDuration = button.releasedTime - button.pressedTime;

if (pressDuration < SHORT_PRESS_TIME) singleClick(mode);
if (pressDuration < SHORT_PRESS_TIME) {
#if TEST_MODE
displayMessage("Single click!", button.name);
#else
singleClick(mode);
#endif
}
}

if (button.isPressing == true && button.isLongDetected == false) {
long pressDuration = millis() - button.pressedTime;

if (pressDuration > LONG_PRESS_TIME) {
#if TEST_MODE
displayMessage("Long click!", button.name);
#else
longClick(modeLong);
#endif
button.isLongDetected = true;
}
}
Expand Down Expand Up @@ -1281,7 +1292,7 @@ void showLocalHum() {
displayMessage(message, "Вологість");
}

void showLocalPresure() {
void showLocalPressure() {
char message[12];
sprintf(message, "%.1fmmHg", climate.getPressure(settings.pressure_correction));
displayMessage(message, "Тиск");
Expand All @@ -1297,7 +1308,7 @@ void showLocalClimateInfo(int index) {
return;
}
if (index <= 2 && climate.isPressureAvailable()) {
showLocalPresure();
showLocalPressure();
return;
}
}
Expand Down Expand Up @@ -3072,6 +3083,9 @@ void initSettings() {
}

void initLegacy() {
#if TEST_MODE
settings.legacy = 3;
#endif
switch (settings.legacy) {
case 0:
Serial.println("Mode: jaam 1");
Expand Down Expand Up @@ -3130,8 +3144,10 @@ void initLegacy() {
break;
}
pinMode(settings.buttonpin, INPUT_PULLUP);
button1.name = "Button 1";
if (isButton2Available()) {
pinMode(settings.button2pin, INPUT_PULLUP);
button2.name = "Button 2";
}
Serial.printf("Offset: %d\n", offset);
}
Expand Down Expand Up @@ -3422,6 +3438,33 @@ void initTime() {
syncTime(7);
}

void showLocalLightLevel() {
char message[10];
sprintf(message, "%.1f lx", lightSensor.getLightLevel(settings.light_sensor_factor));
displayMessage(message, "Освітлення");
}

#if TEST_MODE
void runSelfTests() {
mapFlag();
playMelody(UA_ANTHEM);
servicePin(POWER, HIGH, true);
servicePin(WIFI, HIGH, true);
servicePin(DATA, HIGH, true);
servicePin(HA, HIGH, true);
servicePin(RESERVED, HIGH, true);
showLocalTemp();
sleep(2);
showLocalHum();
sleep(2);
showLocalPressure();
sleep(2);
showLocalLightLevel();
sleep(2);
displayMessage("Please test buttons");
}
#endif

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

Expand All @@ -3433,6 +3476,9 @@ void setup() {
initStrip();
initDisplay();
initSensors();
#if TEST_MODE
runSelfTests();
#else
initWifi();
initTime();

Expand All @@ -3451,22 +3497,26 @@ void setup() {
asyncEngine.setInterval(lightSensorCycle, 2000);
asyncEngine.setInterval(climateSensorCycle, 5000);
asyncEngine.setInterval(calculateStates, 500);
#endif
}

void loop() {
#if TEST_MODE==0
wm.process();
asyncEngine.run();
#if ARDUINO_OTA_ENABLED
ArduinoOTA.handle();
#endif
buttonUpdate(button1, settings.buttonpin, settings.button_mode, settings.button_mode_long);
if (isButton2Available()) {
buttonUpdate(button2, settings.button2pin, settings.button2_mode, settings.button2_mode_long);
}
ha.loop();
client_websocket.poll();
syncTime(2);
if (getCurrentMapMode() == 1 && settings.alarms_notify_mode == 2) {
mapCycle();
}
#endif

buttonUpdate(button1, settings.buttonpin, settings.button_mode, settings.button_mode_long);
if (isButton2Available()) {
buttonUpdate(button2, settings.button2pin, settings.button2_mode, settings.button2_mode_long);
}
}

0 comments on commit 8c50d74

Please sign in to comment.