diff --git a/MilliOhmMeter_FW/platformio.ini b/MilliOhmMeter_FW/platformio.ini index e3276b5..b00ef8f 100644 --- a/MilliOhmMeter_FW/platformio.ini +++ b/MilliOhmMeter_FW/platformio.ini @@ -17,5 +17,6 @@ lib_ldf_mode = deep+ lib_deps = adafruit/Adafruit ADS1X15@^2.2.0 robtillaart/RunningAverage@^0.4.2 + fabianoriccardi/Melody Player@^2.2.2 build_flags = -DCORE_DEBUG_LEVEL=3 diff --git a/MilliOhmMeter_FW/src/board.cpp b/MilliOhmMeter_FW/src/board.cpp index 4af3428..ba9d3fb 100644 --- a/MilliOhmMeter_FW/src/board.cpp +++ b/MilliOhmMeter_FW/src/board.cpp @@ -5,7 +5,7 @@ void initSerial(void) { Serial.begin(115200); Serial.flush(); - delay(2000); + delay(500); log_i("Init serial: OK"); } diff --git a/MilliOhmMeter_FW/src/gain_control.cpp b/MilliOhmMeter_FW/src/gain_control.cpp index 67e4d0c..bd9322b 100644 --- a/MilliOhmMeter_FW/src/gain_control.cpp +++ b/MilliOhmMeter_FW/src/gain_control.cpp @@ -9,15 +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 gainList; +std::vector 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); + + mode20mA.activate(); } bool setGain(e_measureMode mode) @@ -30,9 +32,9 @@ 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); @@ -52,7 +54,7 @@ void resetGain(void) log_d("reset gain control"); for (auto &&gain : gainList) { - gain.deactivate(); + gain->deactivate(); } setGain(mA20); } \ No newline at end of file diff --git a/MilliOhmMeter_FW/src/main.cpp b/MilliOhmMeter_FW/src/main.cpp index 14632f2..1170bdd 100644 --- a/MilliOhmMeter_FW/src/main.cpp +++ b/MilliOhmMeter_FW/src/main.cpp @@ -4,6 +4,7 @@ #include "buttons.h" #include "display.h" #include "gain_control.h" +#include "tone_hall.hpp" uint64_t looptime = 0; @@ -12,6 +13,7 @@ void setup() initBoard(); initGainControl(); initMeasure(); + //initTone(); initMeasureMode(); initDisplay(); looptime = millis(); @@ -22,6 +24,7 @@ void loop() // put your main code here, to run repeatedly: looptime = micros(); handleMeasure(); + //handleTone(); handleDisplay(); setTimer((double)(micros() - looptime)/1000); log_d("T=%4.2fms\n", (double)(micros() - looptime)/1000); diff --git a/MilliOhmMeter_FW/src/screen_main.cpp b/MilliOhmMeter_FW/src/screen_main.cpp index 9e5051d..3f6d23a 100644 --- a/MilliOhmMeter_FW/src/screen_main.cpp +++ b/MilliOhmMeter_FW/src/screen_main.cpp @@ -113,9 +113,9 @@ void screenMainDrawLayout(void) drawDashedHLine(0, 12, 220); drawDashedVLine(40, 12, 33); getDisplay()->setFont(FONT8); - uint16_t rate = float(1 / getSampleRate()); + float rate = getSampleRate(); getDisplay()->setCursor(5, 8); - getDisplay()->printf("Fs:%dHz", rate); + getDisplay()->printf("Fs:%4.0fHz", rate); getDisplay()->setCursor(170, 8); getDisplay()->printf("loop=%dms", timer); } @@ -127,7 +127,7 @@ void ScreenMainDrawValues(void) getDisplay()->printf("%4.3f", getValue()); uint16_t stringwidth = getDisplay()->getStrWidth(drawValue("", getValue(), "").c_str()); getDisplay()->setFont(u8g2_font_8x13_t_symbols); - getDisplay()->drawUTF8(78 + stringwidth + 3, 43, "Ω"); + getDisplay()->drawUTF8(78 + stringwidth + 4, 43, "Ω"); getDisplay()->setFont(FONT8); // getDisplay()->drawUTF8(60 + stringwidth + 3, 43, "v"); diff --git a/MilliOhmMeter_FW/src/tone_hall.cpp b/MilliOhmMeter_FW/src/tone_hall.cpp new file mode 100644 index 0000000..9e7740c --- /dev/null +++ b/MilliOhmMeter_FW/src/tone_hall.cpp @@ -0,0 +1,21 @@ +#include "tone_hall.hpp" + +#include +#include + + +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) +{ + +} \ No newline at end of file diff --git a/MilliOhmMeter_FW/src/tone_hall.hpp b/MilliOhmMeter_FW/src/tone_hall.hpp new file mode 100644 index 0000000..37892c7 --- /dev/null +++ b/MilliOhmMeter_FW/src/tone_hall.hpp @@ -0,0 +1,7 @@ +#pragma once + +#include "Arduino.h" +#include "board.h" + +void initTone(void); +void handleTone(void); \ No newline at end of file