Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bc21b1ee2d | |||
| ebdbb04041 | |||
| d9a4dc8565 | |||
| c503f35e3f | |||
| 351d3e44d3 | |||
| 3bd2c193f4 | |||
| c22d6658f2 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -3581,6 +3581,9 @@
|
||||
(pin "1" (uuid c96e6c66-1b00-41dc-8ece-1cb982e39597))
|
||||
(pin "2" (uuid 2782ab09-9172-4804-8592-6981f889e3cd))
|
||||
(pin "6" (uuid f1b427b1-42e1-43d9-be2b-400f9689e8ac))
|
||||
(pin "3" (uuid 8ec9513c-ea56-4a67-b9c0-93569e9d02a7))
|
||||
(pin "4" (uuid 83278a79-368d-4b00-bb62-b97c1bf16e10))
|
||||
(pin "5" (uuid a03d6ccb-d390-4ff8-b803-38eb2599c186))
|
||||
)
|
||||
|
||||
(symbol (lib_id "Transistor_BJT:UMH3N") (at 105.41 38.1 0) (mirror x) (unit 2)
|
||||
@@ -3598,6 +3601,9 @@
|
||||
(property "Datasheet" "http://rohmfs.rohm.com/en/products/databook/datasheet/discrete/transistor/digital/emh3t2r-e.pdf" (id 3) (at 109.22 38.1 0)
|
||||
(effects (font (size 1.27 1.27)) hide)
|
||||
)
|
||||
(pin "1" (uuid 82820ceb-aa9a-48df-ba50-13a5e410c155))
|
||||
(pin "2" (uuid eae5fd45-fb41-4a98-8509-a8d81f0c6bb9))
|
||||
(pin "6" (uuid b28d6ace-0284-435d-bae3-5fdb7c12c8ef))
|
||||
(pin "3" (uuid c54940b4-016d-4175-b00f-6005d628f1ab))
|
||||
(pin "4" (uuid b6bbaf60-0188-4b4e-a93b-1fc2bc940e94))
|
||||
(pin "5" (uuid 403bea84-bff5-4580-8789-bea6467d5f84))
|
||||
@@ -4435,14 +4441,14 @@
|
||||
(in_bom yes) (on_board yes)
|
||||
(uuid 1ffda2f5-0580-4927-ab9a-1e41d5bd6ab6)
|
||||
(property "Reference" "R7" (id 0) (at 156.21 39.37 90))
|
||||
(property "Value" "10K" (id 1) (at 160.02 39.37 90))
|
||||
(property "Footprint" "Resistor_SMD:R_0603_1608Metric" (id 2) (at 158.75 40.132 90)
|
||||
(property "Value" "" (id 1) (at 160.02 39.37 90))
|
||||
(property "Footprint" "" (id 2) (at 158.75 40.132 90)
|
||||
(effects (font (size 1.27 1.27)) hide)
|
||||
)
|
||||
(property "Datasheet" "~" (id 3) (at 158.75 41.91 0)
|
||||
(effects (font (size 1.27 1.27)) hide)
|
||||
)
|
||||
(property "DNP" "" (id 4) (at 158.75 41.91 90))
|
||||
(property "DNP" "DNP" (id 4) (at 158.75 41.91 90))
|
||||
(pin "1" (uuid 58bf593c-919f-404a-8176-77876f79b172))
|
||||
(pin "2" (uuid 73bdd6e0-8c43-4ede-b59d-8710b7244af0))
|
||||
)
|
||||
|
||||
@@ -16,6 +16,7 @@ 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
|
||||
fabianoriccardi/Melody Player@^2.2.2
|
||||
build_flags =
|
||||
-DCORE_DEBUG_LEVEL=3
|
||||
|
||||
@@ -5,7 +5,7 @@ void initSerial(void)
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.flush();
|
||||
delay(2000);
|
||||
delay(500);
|
||||
log_i("Init serial: OK");
|
||||
}
|
||||
|
||||
|
||||
@@ -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))
|
||||
@@ -87,6 +89,7 @@ void c_onScreenButton::handle()
|
||||
else if (_stateFn != NULL)
|
||||
{
|
||||
_state = _stateFn();
|
||||
_displayState = _state;
|
||||
}
|
||||
log_d("item(%s)=%d",_name.c_str(), _state);
|
||||
}
|
||||
|
||||
@@ -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; }
|
||||
};
|
||||
@@ -14,6 +14,7 @@
|
||||
#define FONT8 u8g2_font_helvR08_tf
|
||||
#define FONT16 u8g2_font_7x14_tf
|
||||
#define FONT24 u8g2_font_freedoomr25_tn //u8g2_font_logisoso24_tf
|
||||
#define FONT25 u8g2_font_helvR24_tf
|
||||
|
||||
class U8G2_SSD1322 : public U8G2 {
|
||||
public:
|
||||
|
||||
@@ -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);
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -9,19 +9,17 @@ c_gainControl mode1000mA(e_measureMode::mA1000, 0, 1, 0, 0, 0, 1); //warning not
|
||||
//UC02 > G=1 (met JP5naar 1000mA); UC03 > G=5(met JP7 naar 200mA); UC04 > G=50 (@20mA); UC05 > 1000mA; UC06 > 200mA. Current: niets gekozen = 20mA.
|
||||
|
||||
|
||||
std::vector<c_gainControl> gainList;
|
||||
std::vector<c_gainControl*> gainList;
|
||||
|
||||
e_measureMode lastGain = e_measureMode::mA20;
|
||||
|
||||
void initGainControl(void)
|
||||
{
|
||||
gainList.push_back(mode20mA);
|
||||
gainList.push_back(mode200mA);
|
||||
gainList.push_back(mode1000mA);
|
||||
}
|
||||
gainList.push_back(&mode20mA);
|
||||
gainList.push_back(&mode200mA);
|
||||
gainList.push_back(&mode1000mA);
|
||||
|
||||
void handleGainControl(void)
|
||||
{
|
||||
mode20mA.activate();
|
||||
}
|
||||
|
||||
bool setGain(e_measureMode mode)
|
||||
@@ -34,11 +32,12 @@ bool setGain(e_measureMode mode)
|
||||
|
||||
for (auto &&gain : gainList)
|
||||
{
|
||||
if (gain.getMode() == mode)
|
||||
if (gain->getMode() == mode)
|
||||
{
|
||||
gain.activate();
|
||||
gain->activate();
|
||||
found = true;
|
||||
lastGain = mode;
|
||||
log_i("set new gain %d", mode);
|
||||
}
|
||||
}
|
||||
if(!found)
|
||||
@@ -55,7 +54,7 @@ void resetGain(void)
|
||||
log_d("reset gain control");
|
||||
for (auto &&gain : gainList)
|
||||
{
|
||||
gain.deactivate();
|
||||
gain->deactivate();
|
||||
}
|
||||
setGain(mA20);
|
||||
}
|
||||
@@ -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
|
||||
};
|
||||
@@ -4,15 +4,18 @@
|
||||
#include "buttons.h"
|
||||
#include "display.h"
|
||||
#include "gain_control.h"
|
||||
#include "tone_hall.hpp"
|
||||
|
||||
uint64_t looptime = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
initBoard();
|
||||
initMeasure();
|
||||
initDisplay();
|
||||
initGainControl();
|
||||
initMeasure();
|
||||
//initTone();
|
||||
initMeasureMode();
|
||||
initDisplay();
|
||||
looptime = millis();
|
||||
}
|
||||
|
||||
@@ -21,7 +24,8 @@ void loop()
|
||||
// put your main code here, to run repeatedly:
|
||||
looptime = micros();
|
||||
handleMeasure();
|
||||
handleGainControl();
|
||||
//handleTone();
|
||||
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,26 @@ float getValue(void)
|
||||
return getMeasurement();
|
||||
}
|
||||
|
||||
|
||||
String getErrorString()
|
||||
{
|
||||
if(getOpenState())
|
||||
{
|
||||
return "OPEN";
|
||||
}
|
||||
else if(getValue() < 0)
|
||||
{
|
||||
return "POL";
|
||||
}
|
||||
else
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
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,6 @@ double getMax(void);
|
||||
double getRms(void);
|
||||
uint8_t getBar(void);
|
||||
float getValue(void);
|
||||
|
||||
String getErrorString();
|
||||
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)
|
||||
@@ -23,20 +24,48 @@ bool getErrorState(void)
|
||||
|
||||
bool getOkState(void)
|
||||
{
|
||||
|
||||
return measureOK;
|
||||
}
|
||||
|
||||
bool getOpenState(void)
|
||||
{
|
||||
return measureOpen;
|
||||
if(getValue() > 2.4F)
|
||||
{
|
||||
measureOK = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool getPolarity(void)
|
||||
{
|
||||
if(getValue() < 0)
|
||||
{
|
||||
measureOK = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void setMeasurementOK()
|
||||
{
|
||||
measureOK = true;
|
||||
}
|
||||
|
||||
void setMeasuremoteNOK()
|
||||
{
|
||||
measureOK = 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 );
|
||||
@@ -21,6 +12,8 @@ void setMeasureMode(e_measureMode newMode);
|
||||
bool getErrorState(void);
|
||||
bool getOkState(void);
|
||||
bool getOpenState(void);
|
||||
|
||||
bool getPolarity(void);
|
||||
void setMeasurementOK();
|
||||
void setMeasurementNOK();
|
||||
void initMeasureMode(void);
|
||||
void handleMeasureMode(void);
|
||||
@@ -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 errorState("ER", 6, LocRight, &getErrorState);
|
||||
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("", 6, LocRight, NULL);
|
||||
c_onScreenButton okState("OK", 7, LocRight, &getOkState);
|
||||
c_onScreenButton openState("Open", 8, LocRight, &getOpenState);
|
||||
c_onScreenButton wifiState("Wifi", 9, LocRight, &getWifiState);
|
||||
c_onScreenButton polState("Pol", 9, LocRight, &getPolarity);
|
||||
|
||||
//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)
|
||||
{
|
||||
@@ -54,38 +101,96 @@ void initDisplayMain(void)
|
||||
mainScreen.addItem(&errorState);
|
||||
mainScreen.addItem(&okState);
|
||||
mainScreen.addItem(&openState);
|
||||
mainScreen.addItem(&wifiState);
|
||||
mainScreen.addItem(&polState);
|
||||
|
||||
mainScreen.begin();
|
||||
|
||||
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");
|
||||
float rate = getSampleRate();
|
||||
getDisplay()->setCursor(5, 8);
|
||||
getDisplay()->printf("Fs:%4.0fHz", 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());
|
||||
uint16_t stringwidth = getDisplay()->getStrWidth(drawValue("", getValue(), "").c_str());
|
||||
getDisplay()->setFont(u8g2_font_8x13_t_symbols);
|
||||
getDisplay()->drawUTF8(60 + stringwidth + 3, 43, "mΩ");
|
||||
String errorstr = getErrorString();
|
||||
|
||||
if(errorstr == "")
|
||||
{
|
||||
setMeasurementOK();
|
||||
getDisplay()->printf("%4.3f", getValue());
|
||||
uint16_t stringwidth = getDisplay()->getStrWidth(drawValue("", getValue(), "").c_str());
|
||||
getDisplay()->setFont(u8g2_font_8x13_t_symbols);
|
||||
getDisplay()->drawUTF8(70 + stringwidth + 10, 43, "Ω");
|
||||
}
|
||||
else
|
||||
{
|
||||
getDisplay()->setFont(FONT25);
|
||||
log_d("get errorstring: %s",errorstr);
|
||||
getDisplay()->printf("%s", errorstr.c_str());
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#include "tone_hall.hpp"
|
||||
|
||||
#include <melody_player.h>
|
||||
#include <melody_factory.h>
|
||||
|
||||
|
||||
MelodyPlayer player(BUZZER1, LOW);
|
||||
|
||||
void initTone(void)
|
||||
{
|
||||
String notes[] = { "C4", "G3", "G3", "A3", "G3", "SILENCE", "B3", "C4" };
|
||||
Melody melody = MelodyFactory.load("Nice Melody", 175, notes, 8);
|
||||
player.play(melody);
|
||||
|
||||
player.playAsync(melody);
|
||||
}
|
||||
|
||||
void handleTone(void)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "board.h"
|
||||
|
||||
void initTone(void);
|
||||
void handleTone(void);
|
||||
Reference in New Issue
Block a user