#include "screen_main.h" screen_c mainScreen(e_displayState::mainscreen, 5); const e_displayState thisScreen = e_displayState::mainscreen; bool WarningActive = false; bool confirmed = false; uint16_t timer = 0; void button1(void) // yes { if (WarningActive) { screenMainSetWarning(false); setMeasureMode(e_measureMode::mA1000); } else { setMeasureMode(e_measureMode::mA20); } } void button2(void) // no { if (WarningActive) { screenMainSetWarning(false); } else { setMeasureMode(e_measureMode::mA200); } } void button3(void) { if (!WarningActive) { screenMainSetWarning(true); } } void button4(void) { if (!WarningActive) { clearStats(); } } void button5(void) { if (!WarningActive) { setDisplayState(e_displayState::setupscreen); log_i("Conf button pressed, go to setupscreen"); } } c_onScreenButton ma20("20m", mA20, LocBottom, BUTTON1, &button1); c_onScreenButton ma200("200m", mA200, LocBottom, BUTTON2, &button2); c_onScreenButton ma1000("1A", mA1000, LocBottom, BUTTON3, &button3); c_onScreenButton mauto("Reset", 4, LocBottom, BUTTON4, &button4); c_onScreenButton bsetup("Conf", 5, LocBottom, BUTTON5, &button5); c_onScreenButton errorState("ER", 6, LocRight, &getErrorState); c_onScreenButton okState("OK", 7, LocRight, &getOkState); c_onScreenButton openState("Open", 8, LocRight, &getOpenState); c_onScreenButton wifiState("Wifi", 9, LocRight, &getWifiState); void screenMainSetWarning(bool warning) { if (warning) { WarningActive = true; ma20.setAltName("Yes"); ma200.setAltName("No"); ma1000.setAltName(""); mauto.setAltName(""); bsetup.setAltName(""); } else { WarningActive = false; ma20.clearAltName(); ma200.clearAltName(); ma1000.clearAltName(); mauto.clearAltName(); bsetup.clearAltName(); } } void initDisplayMain(void) { // fill vector log_i("Store main screen items"); mainScreen.addItem(&ma20); mainScreen.addItem(&ma200); mainScreen.addItem(&ma1000); mainScreen.addItem(&mauto); mainScreen.addItem(&bsetup); mainScreen.addItem(&errorState); mainScreen.addItem(&okState); mainScreen.addItem(&openState); mainScreen.addItem(&wifiState); mainScreen.begin(); log_i("mainscreen OK"); } void screenMainDrawLayout(void) { drawDashedHLine(0, 12, 220); drawDashedVLine(40, 12, 33); getDisplay()->setFont(FONT8); uint16_t rate = float(1 / getSampleRate()); getDisplay()->setCursor(5, 8); getDisplay()->printf("Fs:%dHz", rate); getDisplay()->setCursor(170, 8); getDisplay()->printf("loop=%dms", timer); } void ScreenMainDrawValues(void) { getDisplay()->setFont(FONT24); getDisplay()->setCursor(60, 45); getDisplay()->printf("%4.3f", getValue()); uint16_t stringwidth = getDisplay()->getStrWidth(drawValue("", getValue(), "").c_str()); getDisplay()->setFont(u8g2_font_8x13_t_symbols); getDisplay()->drawUTF8(78 + stringwidth + 3, 43, "Ω"); getDisplay()->setFont(FONT8); // getDisplay()->drawUTF8(60 + stringwidth + 3, 43, "v"); getDisplay()->setCursor(168, 27); getDisplay()->printf("Min: %4.2f", getADCMin()); getDisplay()->setCursor(168, 36); getDisplay()->printf("Avg: %4.2f", getADCavg()); getDisplay()->setCursor(168, 45); getDisplay()->printf("Max: %4.2f", getADCMax()); } void screenMaindrawWarning(void) { getDisplay()->setFont(FONT16); getDisplay()->setCursor(42, 32); getDisplay()->printf("WARNING!"); getDisplay()->setCursor(42, 45); getDisplay()->printf("Confirm to use 1A mode"); } void screenMainDrawInfo(void) { screenMainDrawLayout(); if (WarningActive) { screenMaindrawWarning(); } else { ScreenMainDrawValues(); } } void setTimer(uint16_t newtimer) { timer = newtimer; } void ScreenMainHandle(void) { if (getDisplay() == NULL) { log_e("Display is NULL"); return; } mainScreen.activateModeButton(WarningActive); mainScreen.handle(); mainScreen.draw(); screenMainDrawInfo(); }