release to henk
This commit is contained in:
@@ -16,6 +16,6 @@ monitor_speed = 115200
|
||||
lib_ldf_mode = deep+
|
||||
lib_deps =
|
||||
adafruit/Adafruit ADS1X15@^2.2.0
|
||||
#olikraus/U8g2@^2.32.12
|
||||
robtillaart/RunningAverage@^0.4.2
|
||||
build_flags =
|
||||
-DCORE_DEBUG_LEVEL=3
|
||||
|
||||
@@ -46,18 +46,20 @@ void c_onScreenButton::drawButton()
|
||||
getDisplay()->setDrawColor(1);
|
||||
|
||||
uint16_t yTpos_pressed = !getState() ? _yTpos : (_yTpos + 1);
|
||||
//check if we need to display something else
|
||||
String label = (_useAltName ? _altName : _name);
|
||||
|
||||
if (getDisplayState())
|
||||
{
|
||||
getDisplay()->drawRBox(_xpos, _ypos, _width, _height, _radius);
|
||||
getDisplay()->setDrawColor(0);
|
||||
getDisplay()->drawStr(_xTpos, yTpos_pressed, _name.c_str());
|
||||
getDisplay()->drawStr(_xTpos, yTpos_pressed, label.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
getDisplay()->setDrawColor(1);
|
||||
getDisplay()->drawRFrame(_xpos, _ypos, _width, _height, _radius);
|
||||
getDisplay()->drawStr(_xTpos, yTpos_pressed, _name.c_str());
|
||||
getDisplay()->drawStr(_xTpos, yTpos_pressed, label.c_str());
|
||||
}
|
||||
|
||||
getDisplay()->setDrawColor(1);
|
||||
@@ -68,7 +70,7 @@ void c_onScreenButton::handle()
|
||||
if (_physButton.isValid())
|
||||
{
|
||||
_physButton.read();
|
||||
_pressed = _physButton.pressedFor(200);
|
||||
_pressed = _physButton.pressedFor(100);
|
||||
if (_pressed)
|
||||
{
|
||||
if(_actionFn != NULL && (actionHandled == false))
|
||||
|
||||
@@ -35,7 +35,7 @@ class c_onScreenButton
|
||||
void (*const _actionFn)();
|
||||
bool actionHandled = false;
|
||||
c_button _physButton;
|
||||
|
||||
String _altName = "";
|
||||
|
||||
uint16_t _xpos;
|
||||
uint16_t _ypos;
|
||||
@@ -52,9 +52,21 @@ class c_onScreenButton
|
||||
bool _displayState;
|
||||
bool _pressed;
|
||||
bool _visible;
|
||||
bool _useAltName = false;
|
||||
|
||||
|
||||
void setState(bool state) { _state = state; }
|
||||
void setDefaults(void)
|
||||
{
|
||||
_xpos = 1;
|
||||
_ypos = 1;
|
||||
_visible = false;
|
||||
_pressed = false;
|
||||
_state = false;
|
||||
_displayState = false;
|
||||
_altName = "";
|
||||
_useAltName = false;
|
||||
}
|
||||
|
||||
public:
|
||||
c_onScreenButton(String name, e_measureMode mode, e_buttonLoc location, uint8_t pin,void (*const action)() ) :
|
||||
@@ -64,12 +76,7 @@ public:
|
||||
_actionFn(action),
|
||||
_physButton(pin, (uint8_t)mode)
|
||||
{
|
||||
_xpos = 1;
|
||||
_ypos = 1;
|
||||
_visible = false;
|
||||
_pressed = false;
|
||||
_state = false;
|
||||
_displayState = false;
|
||||
setDefaults();
|
||||
_mode = mode;
|
||||
_location = location;
|
||||
}
|
||||
@@ -81,12 +88,7 @@ public:
|
||||
_actionFn(action),
|
||||
_physButton(pin, index)
|
||||
{
|
||||
_xpos = 1;
|
||||
_ypos = 1;
|
||||
_visible = false;
|
||||
_pressed = false;
|
||||
_state = false;
|
||||
_displayState = false;
|
||||
setDefaults();
|
||||
_mode = e_measureMode::mNone;
|
||||
_location = location;
|
||||
}
|
||||
@@ -97,11 +99,7 @@ public:
|
||||
_actionFn(NULL),
|
||||
_physButton(NOBUTTON, index)
|
||||
{
|
||||
_xpos = 1;
|
||||
_ypos = 1;
|
||||
_visible = false;
|
||||
_pressed = false;
|
||||
_state = false;
|
||||
setDefaults();
|
||||
_location = location;
|
||||
_mode = e_measureMode::mNone;
|
||||
|
||||
@@ -115,6 +113,8 @@ public:
|
||||
void handle(void);
|
||||
void setVisible(bool state) { _visible = state; }
|
||||
bool getVisible(void) { return _visible; }
|
||||
void setAltName(String name) { _altName = name; _useAltName = true;}
|
||||
void clearAltName(void) { _useAltName = false; }
|
||||
uint8_t getIndex(void) { return _index; }
|
||||
e_buttonLoc getLocation(void) { return _location; }
|
||||
};
|
||||
@@ -6,12 +6,7 @@ uint32_t lastScreenchange = 0;
|
||||
void setDisplayState(e_displayState newstate)
|
||||
{
|
||||
log_i("setDisplayState to %d", newstate);
|
||||
uint32_t timeNow = millis();
|
||||
// if(timeNow - lastScreenchange > MINSCREENSWITCHDELAY)
|
||||
// {
|
||||
CurrentScreen = newstate;
|
||||
lastScreenchange = timeNow;
|
||||
//}
|
||||
}
|
||||
|
||||
e_displayState getDisplayState()
|
||||
@@ -33,7 +28,7 @@ void screen_c::begin(void)
|
||||
{
|
||||
uint16_t ypos = getDisplay()->getDisplayHeight() - 1 - CONTROLSLINE_H + 2;
|
||||
item->begin(buttonXpos, ypos, buttonwidth, CONTROLSLINE_H + 6, CONTROLRADIUS);
|
||||
buttonXpos+=buttonwidth-1;
|
||||
buttonXpos += buttonwidth - 1;
|
||||
item->setVisible(true);
|
||||
}
|
||||
else if (item->getLocation() == LocRight)
|
||||
@@ -74,10 +69,17 @@ void screen_c::draw(void)
|
||||
}
|
||||
}
|
||||
|
||||
void screen_c::activateModeButton(void)
|
||||
void screen_c::activateModeButton(bool clear)
|
||||
{
|
||||
for (auto &&item : _items)
|
||||
{
|
||||
item->setDisplayState((item->getIndex() == (uint8_t)getMeasureMode()));
|
||||
if (!clear)
|
||||
{
|
||||
item->setDisplayState((item->getIndex() == (uint8_t)getMeasureMode()));
|
||||
}
|
||||
else
|
||||
{
|
||||
item->setDisplayState(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public:
|
||||
void begin(void);
|
||||
void handle(void);
|
||||
void draw(void);
|
||||
void activateModeButton(void);
|
||||
void activateModeButton(bool clear);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -20,10 +20,6 @@ void initGainControl(void)
|
||||
gainList.push_back(mode1000mA);
|
||||
}
|
||||
|
||||
void handleGainControl(void)
|
||||
{
|
||||
}
|
||||
|
||||
bool setGain(e_measureMode mode)
|
||||
{
|
||||
bool found = false;
|
||||
@@ -39,6 +35,7 @@ bool setGain(e_measureMode mode)
|
||||
gain.activate();
|
||||
found = true;
|
||||
lastGain = mode;
|
||||
log_i("set new gain %d", mode);
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "measure_mode.h"
|
||||
#include "measure_types.h"
|
||||
#include "board.h"
|
||||
#include <vector>
|
||||
|
||||
|
||||
@@ -1,68 +0,0 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
static const unsigned char PROGMEM VUMeter[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x06, 0x03, 0x00, 0x60, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x09, 0x04, 0x80, 0x21, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x01, 0x98, 0x08, 0x06, 0x03, 0x80, 0x21, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xA4, 0x10, 0x09, 0x00, 0x80, 0x21, 0x20, 0x07, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0xA4, 0x10, 0x06, 0x03, 0x00, 0x20, 0xC0, 0x00, 0x80, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x71, 0x80, 0xA4, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x0A, 0x40, 0x98, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x3C, 0x00, 0x00,
|
||||
0x00, 0x00, 0x3A, 0x40, 0x00, 0x00, 0x02, 0x01, 0x00, 0x40, 0x80, 0x07, 0x00, 0x20, 0x00, 0x00,
|
||||
0x00, 0x00, 0x42, 0x40, 0x00, 0x08, 0x02, 0x01, 0x08, 0x40, 0x80, 0x00, 0x00, 0x38, 0x00, 0x00,
|
||||
0x00, 0x00, 0x79, 0x80, 0x04, 0x08, 0x02, 0x01, 0x08, 0x81, 0x10, 0x00, 0x00, 0x04, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x04, 0x08, 0x02, 0x01, 0x08, 0x81, 0x11, 0x04, 0x00, 0x38, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x02, 0x04, 0x02, 0x01, 0x08, 0x81, 0x21, 0x04, 0x00, 0x00, 0x08, 0x00,
|
||||
0x00, 0x00, 0x00, 0x84, 0x02, 0x04, 0x0F, 0xFF, 0xFF, 0xC3, 0xE2, 0x04, 0x00, 0x00, 0x08, 0x00,
|
||||
0x00, 0x00, 0x00, 0xC2, 0x01, 0x07, 0xF0, 0x00, 0x00, 0x3B, 0xFE, 0x08, 0x40, 0x40, 0x08, 0x00,
|
||||
0x00, 0xFE, 0x00, 0x62, 0x01, 0xF8, 0x00, 0x00, 0x00, 0x03, 0xFF, 0xE8, 0x40, 0x80, 0x7F, 0x00,
|
||||
0x00, 0x00, 0x00, 0x21, 0x1E, 0x00, 0x04, 0x00, 0x80, 0x00, 0x7F, 0xFE, 0x80, 0x80, 0x08, 0x00,
|
||||
0x00, 0x00, 0x03, 0x31, 0xE0, 0x00, 0x04, 0x00, 0x80, 0x04, 0x01, 0xFF, 0xC1, 0x00, 0x08, 0x00,
|
||||
0x00, 0x00, 0x07, 0x1E, 0x00, 0x40, 0x00, 0x00, 0x00, 0x04, 0x00, 0x1F, 0xFA, 0x00, 0x08, 0x00,
|
||||
0x00, 0x00, 0x07, 0xF0, 0x00, 0x40, 0x3B, 0x07, 0x60, 0x00, 0x00, 0x01, 0xFF, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x03, 0x80, 0x00, 0x00, 0x34, 0x81, 0x90, 0xCC, 0xC0, 0x00, 0x3F, 0xC0, 0x00, 0x00,
|
||||
0x00, 0x00, 0x0C, 0x00, 0x03, 0x30, 0x0C, 0x82, 0x90, 0x53, 0x20, 0x00, 0x07, 0xF8, 0x00, 0x00,
|
||||
0x00, 0x00, 0x70, 0x40, 0x00, 0xC8, 0x3B, 0x02, 0x60, 0x53, 0x20, 0x00, 0x00, 0xFE, 0x00, 0x00,
|
||||
0x00, 0x01, 0x80, 0x20, 0x01, 0xC8, 0x00, 0x00, 0x00, 0x4C, 0xC0, 0x00, 0x00, 0x3F, 0x80, 0x00,
|
||||
0x00, 0x06, 0x00, 0x00, 0x03, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0xE0, 0x00,
|
||||
0x00, 0x08, 0x00, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xFC, 0x00,
|
||||
0x00, 0x30, 0x00, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x78, 0x00,
|
||||
0x00, 0x00, 0x40, 0x12, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,
|
||||
0x00, 0x00, 0xA0, 0x0C, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x44, 0x00, 0x00, 0x00, 0x02, 0x02, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x03, 0x06, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x01, 0x8C, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x22, 0x00, 0x00, 0x00, 0x00, 0xD8, 0x30, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x70, 0x19, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x20, 0x0F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
@@ -10,9 +10,10 @@ uint64_t looptime = 0;
|
||||
void setup()
|
||||
{
|
||||
initBoard();
|
||||
initMeasure();
|
||||
initDisplay();
|
||||
initGainControl();
|
||||
initMeasure();
|
||||
initMeasureMode();
|
||||
initDisplay();
|
||||
looptime = millis();
|
||||
}
|
||||
|
||||
@@ -21,7 +22,7 @@ void loop()
|
||||
// put your main code here, to run repeatedly:
|
||||
looptime = micros();
|
||||
handleMeasure();
|
||||
handleGainControl();
|
||||
handleDisplay();
|
||||
setTimer((double)(micros() - looptime)/1000);
|
||||
log_d("T=%4.2fms\n", (double)(micros() - looptime)/1000);
|
||||
}
|
||||
@@ -8,35 +8,33 @@ void initMeasure(void)
|
||||
initMeasureMode();
|
||||
initMeasureState();
|
||||
log_i("init measure: OK");
|
||||
|
||||
}
|
||||
|
||||
void handleMeasure(void)
|
||||
{
|
||||
log_d("handle measure");
|
||||
handleMeasureHall();
|
||||
handleMeasureMode();
|
||||
handleMeasureState();
|
||||
|
||||
}
|
||||
|
||||
double getMin(void)
|
||||
{
|
||||
return 14.4;
|
||||
return getADCMin();
|
||||
}
|
||||
|
||||
double getMax(void)
|
||||
{
|
||||
return 234.8;
|
||||
return getADCMax();
|
||||
}
|
||||
|
||||
double getRms(void)
|
||||
{
|
||||
return 146.7;
|
||||
return getADCavg();
|
||||
}
|
||||
|
||||
uint8_t getBar(void)
|
||||
{
|
||||
return 68;
|
||||
return map(getMeasurement(),getADCMin(),getADCMax(), 0, 100);
|
||||
}
|
||||
|
||||
float getValue(void)
|
||||
@@ -45,3 +43,9 @@ float getValue(void)
|
||||
return getMeasurement();
|
||||
}
|
||||
|
||||
void clearStats(void)
|
||||
{
|
||||
clearAverages();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
#include "measure_mode.h"
|
||||
#include "measure_state.h"
|
||||
|
||||
|
||||
|
||||
#define DACINTERVAL 10 //ms
|
||||
#define DACSTEP 8 //ticks
|
||||
|
||||
@@ -17,5 +19,5 @@ double getMax(void);
|
||||
double getRms(void);
|
||||
uint8_t getBar(void);
|
||||
float getValue(void);
|
||||
|
||||
void clearStats(void);
|
||||
|
||||
|
||||
@@ -3,7 +3,12 @@
|
||||
TwoWire wire();
|
||||
Adafruit_ADS1115 ads; /* Use this for the 12-bit version */
|
||||
uint64_t lastMeasurement = 0;
|
||||
uint32_t lastAverage = 0;
|
||||
float ADCvolts = 0;
|
||||
uint16_t sampleRate = 10;
|
||||
|
||||
RunningAverage samples = RunningAverage(100);
|
||||
RunningAverage ADCavg = RunningAverage(10);
|
||||
|
||||
void initMeasureHall(void)
|
||||
{
|
||||
@@ -28,15 +33,51 @@ void initMeasureHall(void)
|
||||
void handleMeasureHall(void)
|
||||
{
|
||||
uint64_t currentmillis = millis();
|
||||
if (currentmillis - lastMeasurement > MEASUREMENTINTERVAL)
|
||||
if (currentmillis - lastMeasurement > sampleRate)
|
||||
{
|
||||
ADCvolts = ads.computeVolts(ads.readADC_SingleEnded(MEAS_CHANNEL));
|
||||
|
||||
ADCavg.add(ADCvolts);
|
||||
lastMeasurement = currentmillis;
|
||||
}
|
||||
if(currentmillis - lastAverage > MEASUREAVGINTERVAL)
|
||||
{
|
||||
samples.add(ADCavg.getAverage());
|
||||
lastAverage = currentmillis;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
float getMeasurement(void)
|
||||
{
|
||||
return ADCvolts;
|
||||
return ADCavg.getAverage();
|
||||
}
|
||||
|
||||
float getADCMin(void)
|
||||
{
|
||||
return samples.getMin();
|
||||
}
|
||||
|
||||
float getADCMax(void)
|
||||
{
|
||||
return samples.getMax();
|
||||
}
|
||||
|
||||
float getADCavg(void)
|
||||
{
|
||||
return samples.getAverage();
|
||||
}
|
||||
|
||||
void clearAverages(void)
|
||||
{
|
||||
samples.clear();
|
||||
ADCavg.clear();
|
||||
}
|
||||
|
||||
uint16_t getSampleRate(void)
|
||||
{
|
||||
return sampleRate;
|
||||
}
|
||||
uint16_t setSampleRate(uint16_t rate)
|
||||
{
|
||||
sampleRate = rate;
|
||||
}
|
||||
@@ -4,9 +4,19 @@
|
||||
#include "board.h"
|
||||
#include <Adafruit_ADS1X15.h>
|
||||
|
||||
//external libs
|
||||
#include "RunningAverage.h"
|
||||
|
||||
#define MEASUREMENTINTERVAL 10 //ms
|
||||
#define MEASUREAVGINTERVAL 100
|
||||
|
||||
void handleMeasureHall(void);
|
||||
void initMeasureHall(void);
|
||||
|
||||
float getMeasurement(void);
|
||||
float getMeasurement(void);
|
||||
float getADCMin(void);
|
||||
float getADCMax(void);
|
||||
float getADCavg(void);
|
||||
void clearAverages(void);
|
||||
uint16_t getSampleRate(void);
|
||||
uint16_t setSampleRate(void);
|
||||
@@ -9,6 +9,7 @@ bool measureOpen = false;
|
||||
void setMeasureMode(e_measureMode newMode)
|
||||
{
|
||||
measureMode = newMode;
|
||||
setGain(measureMode);
|
||||
}
|
||||
|
||||
e_measureMode getMeasureMode(void)
|
||||
@@ -28,15 +29,21 @@ bool getOkState(void)
|
||||
|
||||
bool getOpenState(void)
|
||||
{
|
||||
return measureOpen;
|
||||
if(getValue() > 3.2F)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void initMeasureMode(void)
|
||||
{
|
||||
log_i("init measure mode");
|
||||
setMeasureMode(e_measureMode::mA20);
|
||||
log_i("init measure mode OK");
|
||||
}
|
||||
|
||||
void handleMeasureMode(void)
|
||||
{
|
||||
|
||||
//nothing to handle
|
||||
}
|
||||
@@ -2,18 +2,9 @@
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "board.h"
|
||||
|
||||
|
||||
enum e_measureMode
|
||||
{
|
||||
mNone,
|
||||
mA20,
|
||||
mA200,
|
||||
mA1000,
|
||||
mAuto,
|
||||
mSetup,
|
||||
mLast,
|
||||
};
|
||||
#include "gain_control.h"
|
||||
#include "measure_types.h"
|
||||
#include "measure.h"
|
||||
|
||||
|
||||
e_measureMode getMeasureMode( void );
|
||||
|
||||
12
MilliOhmMeter_FW/src/measure_types.h
Normal file
12
MilliOhmMeter_FW/src/measure_types.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
enum e_measureMode
|
||||
{
|
||||
mNone,
|
||||
mA20,
|
||||
mA200,
|
||||
mA1000,
|
||||
mAuto,
|
||||
mSetup,
|
||||
mLast,
|
||||
};
|
||||
@@ -1,45 +1,92 @@
|
||||
#include "screen_main.h"
|
||||
|
||||
void setma20(void)
|
||||
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
|
||||
{
|
||||
setMeasureMode(e_measureMode::mA20);
|
||||
if (WarningActive)
|
||||
{
|
||||
screenMainSetWarning(false);
|
||||
setMeasureMode(e_measureMode::mA1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
setMeasureMode(e_measureMode::mA20);
|
||||
}
|
||||
}
|
||||
|
||||
void setma200(void)
|
||||
void button2(void) // no
|
||||
{
|
||||
setMeasureMode(e_measureMode::mA200);
|
||||
if (WarningActive)
|
||||
{
|
||||
screenMainSetWarning(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
setMeasureMode(e_measureMode::mA200);
|
||||
}
|
||||
}
|
||||
|
||||
void setma1000(void)
|
||||
void button3(void)
|
||||
{
|
||||
setMeasureMode(e_measureMode::mA1000);
|
||||
if (!WarningActive)
|
||||
{
|
||||
screenMainSetWarning(true);
|
||||
}
|
||||
}
|
||||
|
||||
void setmAuto(void)
|
||||
void button4(void)
|
||||
{
|
||||
setMeasureMode(e_measureMode::mAuto);
|
||||
if (!WarningActive)
|
||||
{
|
||||
clearStats();
|
||||
}
|
||||
}
|
||||
|
||||
void buttonSetup(void)
|
||||
void button5(void)
|
||||
{
|
||||
setDisplayState(e_displayState::setupscreen);
|
||||
log_i("Conf button pressed, go to setupscreen");
|
||||
if (!WarningActive)
|
||||
{
|
||||
setDisplayState(e_displayState::setupscreen);
|
||||
log_i("Conf button pressed, go to setupscreen");
|
||||
}
|
||||
}
|
||||
|
||||
c_onScreenButton ma20("20m", mA20, LocBottom, BUTTON1, &setma20);
|
||||
c_onScreenButton ma200("200m", mA200, LocBottom, BUTTON2, &setma200);
|
||||
c_onScreenButton ma1000("1A", mA1000, LocBottom, BUTTON3, &setma1000);
|
||||
c_onScreenButton mauto("Auto", mAuto, LocBottom, BUTTON4, &setmAuto);
|
||||
c_onScreenButton bsetup("Conf", 5, LocBottom, BUTTON5, &buttonSetup);
|
||||
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);
|
||||
|
||||
//std::vector<c_onScreenButton*> MainScreen;
|
||||
screen_c mainScreen(e_displayState::mainscreen, 5);
|
||||
|
||||
const e_displayState thisScreen = e_displayState::mainscreen;
|
||||
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)
|
||||
{
|
||||
@@ -61,31 +108,76 @@ void initDisplayMain(void)
|
||||
log_i("mainscreen OK");
|
||||
}
|
||||
|
||||
void ScreenMainDrawValues(void)
|
||||
void screenMainDrawLayout(void)
|
||||
{
|
||||
if (getDisplay() == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
drawDashedHLine(0, 12, 220);
|
||||
drawDashedVLine(40, 12, 33);
|
||||
getDisplay()->setFont(FONT8);
|
||||
getDisplay()->drawStr(5, 8, "Fs:100Hz LP");
|
||||
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.2f", getValue());
|
||||
getDisplay()->printf("%4.3f", getValue());
|
||||
uint16_t stringwidth = getDisplay()->getStrWidth(drawValue("", getValue(), "").c_str());
|
||||
getDisplay()->setFont(u8g2_font_8x13_t_symbols);
|
||||
getDisplay()->drawUTF8(60 + stringwidth + 3, 43, "mΩ");
|
||||
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)
|
||||
{
|
||||
mainScreen.activateModeButton();
|
||||
if (getDisplay() == NULL)
|
||||
{
|
||||
log_e("Display is NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
mainScreen.activateModeButton(WarningActive);
|
||||
|
||||
mainScreen.handle();
|
||||
mainScreen.draw();
|
||||
ScreenMainDrawValues();
|
||||
screenMainDrawInfo();
|
||||
}
|
||||
@@ -9,3 +9,6 @@
|
||||
|
||||
void initDisplayMain(void);
|
||||
void ScreenMainHandle(void);
|
||||
|
||||
void screenMainSetWarning(bool warning);
|
||||
void setTimer(uint16_t newtimer);
|
||||
|
||||
Reference in New Issue
Block a user