update code, fix samplerate display, init io

This commit is contained in:
2022-04-25 15:09:18 +02:00
parent d9a4dc8565
commit ebdbb04041
7 changed files with 45 additions and 11 deletions

View File

@@ -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

View File

@@ -5,7 +5,7 @@ void initSerial(void)
{
Serial.begin(115200);
Serial.flush();
delay(2000);
delay(500);
log_i("Init serial: OK");
}

View File

@@ -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<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);
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);
}

View File

@@ -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);

View File

@@ -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");

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)
{
}

View File

@@ -0,0 +1,7 @@
#pragma once
#include "Arduino.h"
#include "board.h"
void initTone(void);
void handleTone(void);