7 Commits

Author SHA1 Message Date
willem bc21b1ee2d update check lights + meas error handling 2022-09-23 14:41:48 +02:00
willem ebdbb04041 update code, fix samplerate display, init io 2022-04-25 15:09:18 +02:00
willem d9a4dc8565 update schematic 2022-04-25 15:08:59 +02:00
willem c503f35e3f release to henk 2022-04-16 21:57:01 +02:00
willem 351d3e44d3 Merge branch 'new_PCB_code' 2022-04-14 17:02:53 +02:00
willem 3bd2c193f4 Merge branch 'master' of 192.168.2.214:willemoldemans/miliohm-meter 2022-03-21 11:51:16 +01:00
willem c22d6658f2 update schematic 2022-02-21 20:03:24 +01:00
27 changed files with 374 additions and 181 deletions
+9 -3
View File
@@ -3581,6 +3581,9 @@
(pin "1" (uuid c96e6c66-1b00-41dc-8ece-1cb982e39597)) (pin "1" (uuid c96e6c66-1b00-41dc-8ece-1cb982e39597))
(pin "2" (uuid 2782ab09-9172-4804-8592-6981f889e3cd)) (pin "2" (uuid 2782ab09-9172-4804-8592-6981f889e3cd))
(pin "6" (uuid f1b427b1-42e1-43d9-be2b-400f9689e8ac)) (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) (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) (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) (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 "3" (uuid c54940b4-016d-4175-b00f-6005d628f1ab))
(pin "4" (uuid b6bbaf60-0188-4b4e-a93b-1fc2bc940e94)) (pin "4" (uuid b6bbaf60-0188-4b4e-a93b-1fc2bc940e94))
(pin "5" (uuid 403bea84-bff5-4580-8789-bea6467d5f84)) (pin "5" (uuid 403bea84-bff5-4580-8789-bea6467d5f84))
@@ -4435,14 +4441,14 @@
(in_bom yes) (on_board yes) (in_bom yes) (on_board yes)
(uuid 1ffda2f5-0580-4927-ab9a-1e41d5bd6ab6) (uuid 1ffda2f5-0580-4927-ab9a-1e41d5bd6ab6)
(property "Reference" "R7" (id 0) (at 156.21 39.37 90)) (property "Reference" "R7" (id 0) (at 156.21 39.37 90))
(property "Value" "10K" (id 1) (at 160.02 39.37 90)) (property "Value" "" (id 1) (at 160.02 39.37 90))
(property "Footprint" "Resistor_SMD:R_0603_1608Metric" (id 2) (at 158.75 40.132 90) (property "Footprint" "" (id 2) (at 158.75 40.132 90)
(effects (font (size 1.27 1.27)) hide) (effects (font (size 1.27 1.27)) hide)
) )
(property "Datasheet" "~" (id 3) (at 158.75 41.91 0) (property "Datasheet" "~" (id 3) (at 158.75 41.91 0)
(effects (font (size 1.27 1.27)) hide) (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 "1" (uuid 58bf593c-919f-404a-8176-77876f79b172))
(pin "2" (uuid 73bdd6e0-8c43-4ede-b59d-8710b7244af0)) (pin "2" (uuid 73bdd6e0-8c43-4ede-b59d-8710b7244af0))
) )
+2 -1
View File
@@ -16,6 +16,7 @@ monitor_speed = 115200
lib_ldf_mode = deep+ lib_ldf_mode = deep+
lib_deps = lib_deps =
adafruit/Adafruit ADS1X15@^2.2.0 adafruit/Adafruit ADS1X15@^2.2.0
#olikraus/U8g2@^2.32.12 robtillaart/RunningAverage@^0.4.2
fabianoriccardi/Melody Player@^2.2.2
build_flags = build_flags =
-DCORE_DEBUG_LEVEL=3 -DCORE_DEBUG_LEVEL=3
+1 -1
View File
@@ -5,7 +5,7 @@ void initSerial(void)
{ {
Serial.begin(115200); Serial.begin(115200);
Serial.flush(); Serial.flush();
delay(2000); delay(500);
log_i("Init serial: OK"); log_i("Init serial: OK");
} }
+6 -3
View File
@@ -46,18 +46,20 @@ void c_onScreenButton::drawButton()
getDisplay()->setDrawColor(1); getDisplay()->setDrawColor(1);
uint16_t yTpos_pressed = !getState() ? _yTpos : (_yTpos + 1); uint16_t yTpos_pressed = !getState() ? _yTpos : (_yTpos + 1);
//check if we need to display something else
String label = (_useAltName ? _altName : _name);
if (getDisplayState()) if (getDisplayState())
{ {
getDisplay()->drawRBox(_xpos, _ypos, _width, _height, _radius); getDisplay()->drawRBox(_xpos, _ypos, _width, _height, _radius);
getDisplay()->setDrawColor(0); getDisplay()->setDrawColor(0);
getDisplay()->drawStr(_xTpos, yTpos_pressed, _name.c_str()); getDisplay()->drawStr(_xTpos, yTpos_pressed, label.c_str());
} }
else else
{ {
getDisplay()->setDrawColor(1); getDisplay()->setDrawColor(1);
getDisplay()->drawRFrame(_xpos, _ypos, _width, _height, _radius); 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); getDisplay()->setDrawColor(1);
@@ -68,7 +70,7 @@ void c_onScreenButton::handle()
if (_physButton.isValid()) if (_physButton.isValid())
{ {
_physButton.read(); _physButton.read();
_pressed = _physButton.pressedFor(200); _pressed = _physButton.pressedFor(100);
if (_pressed) if (_pressed)
{ {
if(_actionFn != NULL && (actionHandled == false)) if(_actionFn != NULL && (actionHandled == false))
@@ -87,6 +89,7 @@ void c_onScreenButton::handle()
else if (_stateFn != NULL) else if (_stateFn != NULL)
{ {
_state = _stateFn(); _state = _stateFn();
_displayState = _state;
} }
log_d("item(%s)=%d",_name.c_str(), _state); log_d("item(%s)=%d",_name.c_str(), _state);
} }
+18 -18
View File
@@ -35,7 +35,7 @@ class c_onScreenButton
void (*const _actionFn)(); void (*const _actionFn)();
bool actionHandled = false; bool actionHandled = false;
c_button _physButton; c_button _physButton;
String _altName = "";
uint16_t _xpos; uint16_t _xpos;
uint16_t _ypos; uint16_t _ypos;
@@ -52,9 +52,21 @@ class c_onScreenButton
bool _displayState; bool _displayState;
bool _pressed; bool _pressed;
bool _visible; bool _visible;
bool _useAltName = false;
void setState(bool state) { _state = state; } 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: public:
c_onScreenButton(String name, e_measureMode mode, e_buttonLoc location, uint8_t pin,void (*const action)() ) : c_onScreenButton(String name, e_measureMode mode, e_buttonLoc location, uint8_t pin,void (*const action)() ) :
@@ -64,12 +76,7 @@ public:
_actionFn(action), _actionFn(action),
_physButton(pin, (uint8_t)mode) _physButton(pin, (uint8_t)mode)
{ {
_xpos = 1; setDefaults();
_ypos = 1;
_visible = false;
_pressed = false;
_state = false;
_displayState = false;
_mode = mode; _mode = mode;
_location = location; _location = location;
} }
@@ -81,12 +88,7 @@ public:
_actionFn(action), _actionFn(action),
_physButton(pin, index) _physButton(pin, index)
{ {
_xpos = 1; setDefaults();
_ypos = 1;
_visible = false;
_pressed = false;
_state = false;
_displayState = false;
_mode = e_measureMode::mNone; _mode = e_measureMode::mNone;
_location = location; _location = location;
} }
@@ -97,11 +99,7 @@ public:
_actionFn(NULL), _actionFn(NULL),
_physButton(NOBUTTON, index) _physButton(NOBUTTON, index)
{ {
_xpos = 1; setDefaults();
_ypos = 1;
_visible = false;
_pressed = false;
_state = false;
_location = location; _location = location;
_mode = e_measureMode::mNone; _mode = e_measureMode::mNone;
@@ -115,6 +113,8 @@ public:
void handle(void); void handle(void);
void setVisible(bool state) { _visible = state; } void setVisible(bool state) { _visible = state; }
bool getVisible(void) { return _visible; } bool getVisible(void) { return _visible; }
void setAltName(String name) { _altName = name; _useAltName = true;}
void clearAltName(void) { _useAltName = false; }
uint8_t getIndex(void) { return _index; } uint8_t getIndex(void) { return _index; }
e_buttonLoc getLocation(void) { return _location; } e_buttonLoc getLocation(void) { return _location; }
}; };
+1
View File
@@ -14,6 +14,7 @@
#define FONT8 u8g2_font_helvR08_tf #define FONT8 u8g2_font_helvR08_tf
#define FONT16 u8g2_font_7x14_tf #define FONT16 u8g2_font_7x14_tf
#define FONT24 u8g2_font_freedoomr25_tn //u8g2_font_logisoso24_tf #define FONT24 u8g2_font_freedoomr25_tn //u8g2_font_logisoso24_tf
#define FONT25 u8g2_font_helvR24_tf
class U8G2_SSD1322 : public U8G2 { class U8G2_SSD1322 : public U8G2 {
public: public:
+8 -6
View File
@@ -6,12 +6,7 @@ uint32_t lastScreenchange = 0;
void setDisplayState(e_displayState newstate) void setDisplayState(e_displayState newstate)
{ {
log_i("setDisplayState to %d", newstate); log_i("setDisplayState to %d", newstate);
uint32_t timeNow = millis();
// if(timeNow - lastScreenchange > MINSCREENSWITCHDELAY)
// {
CurrentScreen = newstate; CurrentScreen = newstate;
lastScreenchange = timeNow;
//}
} }
e_displayState getDisplayState() e_displayState getDisplayState()
@@ -74,10 +69,17 @@ void screen_c::draw(void)
} }
} }
void screen_c::activateModeButton(void) void screen_c::activateModeButton(bool clear)
{ {
for (auto &&item : _items) for (auto &&item : _items)
{
if (!clear)
{ {
item->setDisplayState((item->getIndex() == (uint8_t)getMeasureMode())); item->setDisplayState((item->getIndex() == (uint8_t)getMeasureMode()));
} }
else
{
item->setDisplayState(false);
}
}
} }
+1 -1
View File
@@ -34,7 +34,7 @@ public:
void begin(void); void begin(void);
void handle(void); void handle(void);
void draw(void); void draw(void);
void activateModeButton(void); void activateModeButton(bool clear);
}; };
+9 -10
View File
@@ -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. //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; e_measureMode lastGain = e_measureMode::mA20;
void initGainControl(void) void initGainControl(void)
{ {
gainList.push_back(mode20mA); gainList.push_back(&mode20mA);
gainList.push_back(mode200mA); gainList.push_back(&mode200mA);
gainList.push_back(mode1000mA); gainList.push_back(&mode1000mA);
}
void handleGainControl(void) mode20mA.activate();
{
} }
bool setGain(e_measureMode mode) bool setGain(e_measureMode mode)
@@ -34,11 +32,12 @@ bool setGain(e_measureMode mode)
for (auto &&gain : gainList) for (auto &&gain : gainList)
{ {
if (gain.getMode() == mode) if (gain->getMode() == mode)
{ {
gain.activate(); gain->activate();
found = true; found = true;
lastGain = mode; lastGain = mode;
log_i("set new gain %d", mode);
} }
} }
if(!found) if(!found)
@@ -55,7 +54,7 @@ void resetGain(void)
log_d("reset gain control"); log_d("reset gain control");
for (auto &&gain : gainList) for (auto &&gain : gainList)
{ {
gain.deactivate(); gain->deactivate();
} }
setGain(mA20); setGain(mA20);
} }
+1 -1
View File
@@ -1,7 +1,7 @@
#pragma once #pragma once
#include "Arduino.h" #include "Arduino.h"
#include "measure_mode.h" #include "measure_types.h"
#include "board.h" #include "board.h"
#include <vector> #include <vector>
-68
View File
@@ -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
};
+7 -3
View File
@@ -4,15 +4,18 @@
#include "buttons.h" #include "buttons.h"
#include "display.h" #include "display.h"
#include "gain_control.h" #include "gain_control.h"
#include "tone_hall.hpp"
uint64_t looptime = 0; uint64_t looptime = 0;
void setup() void setup()
{ {
initBoard(); initBoard();
initMeasure();
initDisplay();
initGainControl(); initGainControl();
initMeasure();
//initTone();
initMeasureMode();
initDisplay();
looptime = millis(); looptime = millis();
} }
@@ -21,7 +24,8 @@ void loop()
// put your main code here, to run repeatedly: // put your main code here, to run repeatedly:
looptime = micros(); looptime = micros();
handleMeasure(); handleMeasure();
handleGainControl(); //handleTone();
handleDisplay(); handleDisplay();
setTimer((double)(micros() - looptime)/1000);
log_d("T=%4.2fms\n", (double)(micros() - looptime)/1000); log_d("T=%4.2fms\n", (double)(micros() - looptime)/1000);
} }
+28 -7
View File
@@ -8,35 +8,33 @@ void initMeasure(void)
initMeasureMode(); initMeasureMode();
initMeasureState(); initMeasureState();
log_i("init measure: OK"); log_i("init measure: OK");
} }
void handleMeasure(void) void handleMeasure(void)
{ {
log_d("handle measure"); log_d("handle measure");
handleMeasureHall(); handleMeasureHall();
handleMeasureMode();
handleMeasureState();
} }
double getMin(void) double getMin(void)
{ {
return 14.4; return getADCMin();
} }
double getMax(void) double getMax(void)
{ {
return 234.8; return getADCMax();
} }
double getRms(void) double getRms(void)
{ {
return 146.7; return getADCavg();
} }
uint8_t getBar(void) uint8_t getBar(void)
{ {
return 68; return map(getMeasurement(),getADCMin(),getADCMax(), 0, 100);
} }
float getValue(void) float getValue(void)
@@ -45,3 +43,26 @@ float getValue(void)
return getMeasurement(); return getMeasurement();
} }
String getErrorString()
{
if(getOpenState())
{
return "OPEN";
}
else if(getValue() < 0)
{
return "POL";
}
else
{
return "";
}
}
void clearStats(void)
{
clearAverages();
}
+4 -1
View File
@@ -6,6 +6,8 @@
#include "measure_mode.h" #include "measure_mode.h"
#include "measure_state.h" #include "measure_state.h"
#define DACINTERVAL 10 //ms #define DACINTERVAL 10 //ms
#define DACSTEP 8 //ticks #define DACSTEP 8 //ticks
@@ -17,5 +19,6 @@ double getMax(void);
double getRms(void); double getRms(void);
uint8_t getBar(void); uint8_t getBar(void);
float getValue(void); float getValue(void);
String getErrorString();
void clearStats(void);
+44 -3
View File
@@ -3,7 +3,12 @@
TwoWire wire(); TwoWire wire();
Adafruit_ADS1115 ads; /* Use this for the 12-bit version */ Adafruit_ADS1115 ads; /* Use this for the 12-bit version */
uint64_t lastMeasurement = 0; uint64_t lastMeasurement = 0;
uint32_t lastAverage = 0;
float ADCvolts = 0; float ADCvolts = 0;
uint16_t sampleRate = 10;
RunningAverage samples = RunningAverage(100);
RunningAverage ADCavg = RunningAverage(10);
void initMeasureHall(void) void initMeasureHall(void)
{ {
@@ -28,15 +33,51 @@ void initMeasureHall(void)
void handleMeasureHall(void) void handleMeasureHall(void)
{ {
uint64_t currentmillis = millis(); uint64_t currentmillis = millis();
if (currentmillis - lastMeasurement > MEASUREMENTINTERVAL) if (currentmillis - lastMeasurement > sampleRate)
{ {
ADCvolts = ads.computeVolts(ads.readADC_SingleEnded(MEAS_CHANNEL)); ADCvolts = ads.computeVolts(ads.readADC_SingleEnded(MEAS_CHANNEL));
ADCavg.add(ADCvolts);
lastMeasurement = currentmillis; lastMeasurement = currentmillis;
} }
if(currentmillis - lastAverage > MEASUREAVGINTERVAL)
{
samples.add(ADCavg.getAverage());
lastAverage = currentmillis;
}
} }
float getMeasurement(void) 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;
} }
+10
View File
@@ -4,9 +4,19 @@
#include "board.h" #include "board.h"
#include <Adafruit_ADS1X15.h> #include <Adafruit_ADS1X15.h>
//external libs
#include "RunningAverage.h"
#define MEASUREMENTINTERVAL 10 //ms #define MEASUREMENTINTERVAL 10 //ms
#define MEASUREAVGINTERVAL 100
void handleMeasureHall(void); void handleMeasureHall(void);
void initMeasureHall(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);
+31 -2
View File
@@ -9,6 +9,7 @@ bool measureOpen = false;
void setMeasureMode(e_measureMode newMode) void setMeasureMode(e_measureMode newMode)
{ {
measureMode = newMode; measureMode = newMode;
setGain(measureMode);
} }
e_measureMode getMeasureMode(void) e_measureMode getMeasureMode(void)
@@ -23,20 +24,48 @@ bool getErrorState(void)
bool getOkState(void) bool getOkState(void)
{ {
return measureOK; return measureOK;
} }
bool getOpenState(void) 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) void initMeasureMode(void)
{ {
log_i("init measure mode"); log_i("init measure mode");
setMeasureMode(e_measureMode::mA20);
log_i("init measure mode OK");
} }
void handleMeasureMode(void) void handleMeasureMode(void)
{ {
//nothing to handle
} }
+6 -13
View File
@@ -2,18 +2,9 @@
#include "Arduino.h" #include "Arduino.h"
#include "board.h" #include "board.h"
#include "gain_control.h"
#include "measure_types.h"
enum e_measureMode #include "measure.h"
{
mNone,
mA20,
mA200,
mA1000,
mAuto,
mSetup,
mLast,
};
e_measureMode getMeasureMode( void ); e_measureMode getMeasureMode( void );
@@ -21,6 +12,8 @@ void setMeasureMode(e_measureMode newMode);
bool getErrorState(void); bool getErrorState(void);
bool getOkState(void); bool getOkState(void);
bool getOpenState(void); bool getOpenState(void);
bool getPolarity(void);
void setMeasurementOK();
void setMeasurementNOK();
void initMeasureMode(void); void initMeasureMode(void);
void handleMeasureMode(void); void handleMeasureMode(void);
+12
View File
@@ -0,0 +1,12 @@
#pragma once
enum e_measureMode
{
mNone,
mA20,
mA200,
mA1000,
mAuto,
mSetup,
mLast,
};
+138 -33
View File
@@ -1,45 +1,92 @@
#include "screen_main.h" #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
{
if (WarningActive)
{
screenMainSetWarning(false);
setMeasureMode(e_measureMode::mA1000);
}
else
{ {
setMeasureMode(e_measureMode::mA20); setMeasureMode(e_measureMode::mA20);
} }
}
void setma200(void) void button2(void) // no
{
if (WarningActive)
{
screenMainSetWarning(false);
}
else
{ {
setMeasureMode(e_measureMode::mA200); setMeasureMode(e_measureMode::mA200);
} }
void setma1000(void)
{
setMeasureMode(e_measureMode::mA1000);
} }
void setmAuto(void) void button3(void)
{ {
setMeasureMode(e_measureMode::mAuto); if (!WarningActive)
{
screenMainSetWarning(true);
}
} }
void buttonSetup(void) void button4(void)
{
if (!WarningActive)
{
clearStats();
}
}
void button5(void)
{
if (!WarningActive)
{ {
setDisplayState(e_displayState::setupscreen); setDisplayState(e_displayState::setupscreen);
log_i("Conf button pressed, go to setupscreen"); log_i("Conf button pressed, go to setupscreen");
} }
}
c_onScreenButton ma20("20m", mA20, LocBottom, BUTTON1, &setma20); c_onScreenButton ma20("20m", mA20, LocBottom, BUTTON1, &button1);
c_onScreenButton ma200("200m", mA200, LocBottom, BUTTON2, &setma200); c_onScreenButton ma200("200m", mA200, LocBottom, BUTTON2, &button2);
c_onScreenButton ma1000("1A", mA1000, LocBottom, BUTTON3, &setma1000); c_onScreenButton ma1000("1A", mA1000, LocBottom, BUTTON3, &button3);
c_onScreenButton mauto("Auto", mAuto, LocBottom, BUTTON4, &setmAuto); c_onScreenButton mauto("Reset", 4, LocBottom, BUTTON4, &button4);
c_onScreenButton bsetup("Conf", 5, LocBottom, BUTTON5, &buttonSetup); c_onScreenButton bsetup("Conf", 5, LocBottom, BUTTON5, &button5);
c_onScreenButton errorState("ER", 6, LocRight, &getErrorState); c_onScreenButton errorState("", 6, LocRight, NULL);
c_onScreenButton okState("OK", 7, LocRight, &getOkState); c_onScreenButton okState("OK", 7, LocRight, &getOkState);
c_onScreenButton openState("Open", 8, LocRight, &getOpenState); 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; void screenMainSetWarning(bool warning)
screen_c mainScreen(e_displayState::mainscreen, 5); {
if (warning)
const e_displayState thisScreen = e_displayState::mainscreen; {
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) void initDisplayMain(void)
{ {
@@ -54,38 +101,96 @@ void initDisplayMain(void)
mainScreen.addItem(&errorState); mainScreen.addItem(&errorState);
mainScreen.addItem(&okState); mainScreen.addItem(&okState);
mainScreen.addItem(&openState); mainScreen.addItem(&openState);
mainScreen.addItem(&wifiState); mainScreen.addItem(&polState);
mainScreen.begin(); mainScreen.begin();
log_i("mainscreen OK"); log_i("mainscreen OK");
} }
void ScreenMainDrawValues(void) void screenMainDrawLayout(void)
{ {
if (getDisplay() == NULL)
{
return;
}
drawDashedHLine(0, 12, 220); drawDashedHLine(0, 12, 220);
drawDashedVLine(40, 12, 33); drawDashedVLine(40, 12, 33);
getDisplay()->setFont(FONT8); 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()->setFont(FONT24);
getDisplay()->setCursor(60, 45); getDisplay()->setCursor(60, 45);
getDisplay()->printf("%4.2f", getValue()); String errorstr = getErrorString();
if(errorstr == "")
{
setMeasurementOK();
getDisplay()->printf("%4.3f", getValue());
uint16_t stringwidth = getDisplay()->getStrWidth(drawValue("", getValue(), "").c_str()); uint16_t stringwidth = getDisplay()->getStrWidth(drawValue("", getValue(), "").c_str());
getDisplay()->setFont(u8g2_font_8x13_t_symbols); getDisplay()->setFont(u8g2_font_8x13_t_symbols);
getDisplay()->drawUTF8(60 + stringwidth + 3, 43, "m"); 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) void ScreenMainHandle(void)
{ {
mainScreen.activateModeButton(); if (getDisplay() == NULL)
{
log_e("Display is NULL");
return;
}
mainScreen.activateModeButton(WarningActive);
mainScreen.handle(); mainScreen.handle();
mainScreen.draw(); mainScreen.draw();
ScreenMainDrawValues(); screenMainDrawInfo();
} }
+3
View File
@@ -9,3 +9,6 @@
void initDisplayMain(void); void initDisplayMain(void);
void ScreenMainHandle(void); void ScreenMainHandle(void);
void screenMainSetWarning(bool warning);
void setTimer(uint16_t newtimer);
+21
View File
@@ -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)
{
}
+7
View File
@@ -0,0 +1,7 @@
#pragma once
#include "Arduino.h"
#include "board.h"
void initTone(void);
void handleTone(void);