updated firmware

This commit is contained in:
2022-02-08 19:27:00 +01:00
parent dd0ff7eb29
commit 589f064959
63 changed files with 197 additions and 21274 deletions

View File

@@ -17,7 +17,8 @@ void scanI2C(void);
#define DAC1_OUT 26
#define BUTTON1 21
#define BUTTON2 12
#define BUTTON3 13
#define BUTTON4 16
#define BUTTON1 18
#define BUTTON2 15
#define BUTTON3 32
#define BUTTON4 33
#define BUTTON5 13

View File

@@ -1,66 +1,12 @@
#include "display.h"
c_onScreenButton ma20("20m", (uint8_t)mA20, LocBottom);
c_onScreenButton ma200("200m", (uint8_t)mA200, LocBottom);
c_onScreenButton ma1000("1A", (uint8_t)mA1000, LocBottom);
c_onScreenButton mauto("Auto", (uint8_t)mAuto, LocBottom);
c_onScreenButton bsetup("Conf", 5, LocBottom);
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);
std::vector<c_onScreenButton> MainScreen;
#define FONT8 u8g2_font_helvR08_tf
#define FONT16 u8g2_font_7x14_tf
#define FONT24 u8g2_font_freedoomr25_tn //u8g2_font_logisoso24_tf
U8G2_SSD1322_NHD_256X64_F_4W_HW_SPI display(U8G2_R0, OLED_CS, OLED_DC, OLED_RST);
void initMainScreenButtons(void)
U8G2_SSD1322_NHD_256X64_F_4W_HW_SPI* getDisplay(void)
{
Serial.print("Init GUI: ");
display.setFont(FONT8);
uint16_t screenwidth = display.getWidth() - 1;
uint16_t buttonwidth = ((screenwidth / mLast) - CONTROLLOFFSET * 2) - 1;
uint16_t currentWidth = 0;
uint16_t ypos = display.getHeight() - 1 - CONTROLSLINE_H + 2;
//setup bottom buttons
ma20.begin(currentWidth, ypos, buttonwidth, CONTROLSLINE_H + 6, CONTROLRADIUS);
ma200.begin(currentWidth += (buttonwidth - 1), ypos, buttonwidth, CONTROLSLINE_H + CONTROLRADIUS, CONTROLRADIUS);
ma1000.begin(currentWidth += (buttonwidth - 1), ypos, buttonwidth, CONTROLSLINE_H + CONTROLRADIUS, CONTROLRADIUS);
mauto.begin(currentWidth += (buttonwidth - 1), ypos, buttonwidth, CONTROLSLINE_H + CONTROLRADIUS, CONTROLRADIUS);
bsetup.begin(currentWidth += (buttonwidth - 1), ypos, buttonwidth, CONTROLSLINE_H + CONTROLRADIUS, CONTROLRADIUS);
//setup right side indicators
uint16_t currentYpos = 0;
uint16_t IndicatorXpos = screenwidth - INDICATORWIDTH - (INDICATORWIDTH / 2);
errorState.begin(IndicatorXpos, currentYpos, INDICATORWIDTH, INDICATORHEIGHT, INDICATORRADIUS);
okState.begin(IndicatorXpos, currentYpos += (INDICATORHEIGHT - 1), INDICATORWIDTH, INDICATORHEIGHT, INDICATORRADIUS);
openState.begin(IndicatorXpos, currentYpos += (INDICATORHEIGHT - 1), INDICATORWIDTH, INDICATORHEIGHT, INDICATORRADIUS);
wifiState.begin(IndicatorXpos, currentYpos += (INDICATORHEIGHT - 1), INDICATORWIDTH, INDICATORHEIGHT, INDICATORRADIUS);
//fill vector
Serial.print("Store");
MainScreen.push_back(ma20);
MainScreen.push_back(ma200);
MainScreen.push_back(ma1000);
MainScreen.push_back(mauto);
MainScreen.push_back(bsetup);
MainScreen.push_back(errorState);
MainScreen.push_back(okState);
MainScreen.push_back(openState);
MainScreen.push_back(wifiState);
for (auto &&button : MainScreen)
{
button.setVisible(true);
}
Serial.println("OK");
return &display;
}
void c_onScreenButton::begin(uint16_t xpos, uint16_t ypos, uint16_t width, uint16_t height, uint16_t radius)
@@ -90,21 +36,6 @@ void c_onScreenButton::begin(uint16_t xpos, uint16_t ypos, uint16_t width, uint1
Serial.print(":OK | ");
}
void drawDashedHLine(uint16_t x, uint16_t y, uint16_t len)
{
for(int i = 0; i < len; i+=2)
{
display.drawPixel(x+i, y);
}
}
void drawDashedVLine(uint16_t x, uint16_t y, uint16_t len)
{
for(int i = 0; i < len; i+=2)
{
display.drawPixel(x, y+i);
}
}
void c_onScreenButton::drawButton()
{
@@ -162,46 +93,39 @@ void drawProgressBar(uint16_t x, uint16_t y, uint16_t width, uint16_t height, ui
display.drawRBox(x + 1, y + 2, maxProgressWidth, height - 3, radius);
}
void drawMeasurementValues()
void drawDashedHLine(uint16_t x, uint16_t y, uint16_t len)
{
drawDashedHLine(0,12,220);
drawDashedVLine(40,12,33);
display.setFont(FONT8);
display.drawStr(5,8,"Fs:100Hz LP");
display.setFont(FONT24);
//display.drawStr(60, 45, String(getValue()).c_str());
display.setCursor(60,45);
display.printf("%4.2f",getValue());
uint16_t stringwidth = display.getStrWidth(showValue("", getValue(), "").c_str());
display.setFont(u8g2_font_8x13_t_symbols);
display.drawUTF8(60+stringwidth+3 , 43, "mΩ");
//drawProgressBar(0, 40, 127, 5, getBar());
}
void drawMainSceenButtons()
{
//draw controlstrip indicators
for (auto &&thismode : MainScreen)
for(int i = 0; i < len; i+=2)
{
thismode.setState((thismode.getIndex() == (uint8_t)getMeasureMode()));
thismode.drawButton();
display.drawPixel(x+i, y);
}
}
void drawMainScreen()
void drawDashedVLine(uint16_t x, uint16_t y, uint16_t len)
{
drawMainSceenButtons();
drawMeasurementValues();
for(int i = 0; i < len; i+=2)
{
display.drawPixel(x, y+i);
}
}
uint16_t getDisplayWidth(void)
{
return display.getWidth();
}
uint16_t getDisplayHeight(void)
{
return display.getHeight();
}
uint64_t lastDisplayTime = 0;
void initDisplay()
{
initMainScreenButtons();
display.setFont(FONT8);
display.begin();
display.clearBuffer();
lastDisplayTime = millis();
@@ -212,13 +136,15 @@ void handleDisplay()
uint64_t currentmillis = millis();
if (currentmillis - lastDisplayTime > SCREENREFRESH)
{
display.clearBuffer();
// do
// {
drawMainScreen();
// } while (display.nextPage());
display.sendBuffer();
lastDisplayTime = millis();
}
}
void clearDisplay(void)
{
display.clearBuffer();
}

View File

@@ -22,13 +22,13 @@
#define SCREENREFRESH 20
enum displayState
{
mainscreen,
setupscreen
};
#define FONT8 u8g2_font_helvR08_tf
#define FONT16 u8g2_font_7x14_tf
#define FONT24 u8g2_font_freedoomr25_tn //u8g2_font_logisoso24_tf
typedef enum
typedef enum
{
LocTop,
LocRight,
@@ -57,24 +57,21 @@ class c_onScreenButton
bool (*const _stateFn)() = NULL;
public:
c_onScreenButton(String name, uint8_t index, e_buttonLoc location) :
_xpos(1),
_width(1),
_name(name),
_index(index),
_location(location),
_stateFn(NULL)
c_onScreenButton(String name, uint8_t index, e_buttonLoc location) : _xpos(1),
_width(1),
_name(name),
_index(index),
_location(location),
_stateFn(NULL)
{
_visible = false;
}
c_onScreenButton(String name, uint8_t index, e_buttonLoc location, bool (*stateFn)()) :
_xpos(1),
_width(1),
_name(name),
_index(index),
_location(location),
_stateFn(stateFn)
c_onScreenButton(String name, uint8_t index, e_buttonLoc location, bool (*stateFn)()) : _xpos(1),
_width(1),
_name(name),
_index(index),
_location(location),
_stateFn(stateFn)
{
_visible = false;
}
@@ -95,9 +92,19 @@ public:
void setVisible(bool state) { _visible = state; }
bool getVisible(void) { return _visible; }
uint8_t getIndex(void) { return _index; }
e_buttonLoc getLocation( void ) {return _location; }
e_buttonLoc getLocation(void) { return _location; }
};
//#endif
void initDisplay(void);
void handleDisplay(void);
void handleDisplay(void);
void clearDisplay(void);
String showValue(String designator, float value, String unit);
uint16_t getDisplayWidth(void);
uint16_t getDisplayHeight(void);
U8G2_SSD1322_NHD_256X64_F_4W_HW_SPI *getDisplay(void);
void drawDashedVLine(uint16_t x, uint16_t y, uint16_t len);
void drawDashedHLine(uint16_t x, uint16_t y, uint16_t len);

View File

@@ -3,6 +3,8 @@
#include "display.h"
#include "leds.h"
#include "measure.h"
#include "buttons.h"
#include "gui.h"
uint64_t looptime = 0;
@@ -10,9 +12,12 @@ void setup()
{
// put your setup code here, to run once:
initBoard();
initButtons();
initDisplay();
initLeds();
initMeasure();
initGui();
looptime = millis();
}
@@ -20,10 +25,10 @@ void loop()
{
// put your main code here, to run repeatedly:
looptime = micros();
handleDisplay();
handleLeds();
handleMeasure();
handleButtons();
handleGui();
handleDisplay(); //make sure to update the display last (writes buffer to the screen)
Serial.printf("T=%4.2fms\n", (double)(micros() - looptime)/1000);
}

View File

@@ -52,29 +52,6 @@ void handleDAC(void)
}
}
void initMeasure(void)
{
Serial.print("init measurements:ADC=");
if (!ads.begin())
{
Serial.println("Failed to initialize ADS.");
}
else
{
Serial.println("OK");
}
lastMeasurement = millis();
lastDacWrite = millis();
pinMode(BUTTON3, INPUT_PULLUP);
}
void handleMeasure(void)
{
handleADC();
handleDAC();
}
measureMode getMeasureMode(void)
{
return measureMode::mA200;
@@ -120,3 +97,26 @@ bool getOpenState(void)
{
return false;
}
void initMeasure(void)
{
Serial.print("init measurements:ADC=");
if (!ads.begin())
{
Serial.println("Failed to initialize ADS.");
}
else
{
Serial.println("OK");
}
lastMeasurement = millis();
lastDacWrite = millis();
pinMode(BUTTON3, INPUT_PULLUP);
}
void handleMeasure(void)
{
handleADC();
handleDAC();
}