started gain control modes
This commit is contained in:
@@ -1,12 +1,45 @@
|
|||||||
#include "board.h"
|
#include "board.h"
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
|
|
||||||
#include <Wire.h> //include Wire.h library
|
void initSerial(void)
|
||||||
|
|
||||||
void initBoard(void)
|
|
||||||
{
|
{
|
||||||
Serial.begin(115200);
|
Serial.begin(115200);
|
||||||
Serial.flush();
|
Serial.flush();
|
||||||
delay(2000);
|
delay(2000);
|
||||||
log_i("Init serial: OK");
|
log_i("Init serial: OK");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void initBuzzer(void)
|
||||||
|
{
|
||||||
|
pinMode(BUZZER1, OUTPUT);
|
||||||
|
digitalWrite(BUZZER1, HIGH);
|
||||||
|
delay(500);
|
||||||
|
digitalWrite(BUZZER1, LOW);
|
||||||
|
log_i("Init Buzzer: OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
void initInputs(void)
|
||||||
|
{
|
||||||
|
pinMode(LEVEL_IN, INPUT);
|
||||||
|
pinMode(ERROR_IN, INPUT);
|
||||||
|
log_i("Init Inputs: OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
void initOutputs(void)
|
||||||
|
{
|
||||||
|
pinMode(UC01, OUTPUT);
|
||||||
|
pinMode(UC02, OUTPUT);
|
||||||
|
pinMode(UC03, OUTPUT);
|
||||||
|
pinMode(UC04, OUTPUT);
|
||||||
|
pinMode(UC05, OUTPUT);
|
||||||
|
pinMode(UC06, OUTPUT);
|
||||||
|
log_i("Init Outputs: OK");
|
||||||
|
}
|
||||||
|
|
||||||
|
void initBoard(void)
|
||||||
|
{
|
||||||
|
initSerial();
|
||||||
|
initBuzzer();
|
||||||
|
initInputs();
|
||||||
|
initOutputs();
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,13 +6,13 @@ void scanI2C(void);
|
|||||||
#define HAS_DISPLAY
|
#define HAS_DISPLAY
|
||||||
#define HAS_SSD1322
|
#define HAS_SSD1322
|
||||||
|
|
||||||
#define OLED_CS gpio_num_t(26)
|
#define OLED_CS 26
|
||||||
#define OLED_DC gpio_num_t(27)
|
#define OLED_DC 27
|
||||||
#define OLED_RST gpio_num_t(25)
|
#define OLED_RST 25
|
||||||
#define OLED_MOSI 14 // gpio_num_t(14)
|
#define OLED_MOSI 14
|
||||||
#define OLED_SCK 13 // gpio_num_t(13)
|
#define OLED_SCK 13
|
||||||
|
|
||||||
#define ADC_SDA 4
|
#define ADC_SDA 4
|
||||||
#define ADC_SCL 15
|
#define ADC_SCL 15
|
||||||
|
|
||||||
#define MEAS_CHANNEL 0
|
#define MEAS_CHANNEL 0
|
||||||
@@ -21,4 +21,16 @@ void scanI2C(void);
|
|||||||
#define BUTTON2 32
|
#define BUTTON2 32
|
||||||
#define BUTTON3 35
|
#define BUTTON3 35
|
||||||
#define BUTTON4 34
|
#define BUTTON4 34
|
||||||
#define BUTTON5 39
|
#define BUTTON5 39
|
||||||
|
|
||||||
|
#define BUZZER1 23
|
||||||
|
|
||||||
|
#define ERROR_IN 36
|
||||||
|
#define LEVEL_IN 33
|
||||||
|
|
||||||
|
#define UC01 16
|
||||||
|
#define UC02 17
|
||||||
|
#define UC03 5
|
||||||
|
#define UC04 18
|
||||||
|
#define UC05 19
|
||||||
|
#define UC06 22
|
||||||
@@ -3,6 +3,8 @@
|
|||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#include "JC_Button.h"
|
#include "JC_Button.h"
|
||||||
|
|
||||||
|
#define NOBUTTON (255)
|
||||||
|
|
||||||
class c_button : public Button
|
class c_button : public Button
|
||||||
{
|
{
|
||||||
const uint8_t _index;
|
const uint8_t _index;
|
||||||
@@ -13,5 +15,6 @@ public:
|
|||||||
|
|
||||||
uint8_t getIndex( void ) {return _index;}
|
uint8_t getIndex( void ) {return _index;}
|
||||||
bool isChanged( void ) {return wasPressed();}
|
bool isChanged( void ) {return wasPressed();}
|
||||||
|
bool isValid(void){ return (getPin() != NOBUTTON);}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ void drawMainscreenValues()
|
|||||||
|
|
||||||
getDisplay()->setCursor(60, 45);
|
getDisplay()->setCursor(60, 45);
|
||||||
getDisplay()->printf("%4.2f", getValue());
|
getDisplay()->printf("%4.2f", getValue());
|
||||||
uint16_t stringwidth = getDisplay()->getStrWidth(showValue("", 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(60 + stringwidth + 3, 43, "mΩ");
|
||||||
//drawProgressBar(0, 40, 127, 5, getBar());
|
//drawProgressBar(0, 40, 127, 5, getBar());
|
||||||
|
|||||||
@@ -63,15 +63,20 @@ void c_onScreenButton::drawButton()
|
|||||||
getDisplay()->setDrawColor(1);
|
getDisplay()->setDrawColor(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String showValue(String designator, float value, String unit)
|
void c_onScreenButton::handle()
|
||||||
{
|
{
|
||||||
String text;
|
if (_physButton.isValid())
|
||||||
text.clear();
|
|
||||||
if (designator != "")
|
|
||||||
{
|
{
|
||||||
text = designator;
|
_pressed = _physButton.read();
|
||||||
|
if (_pressed)
|
||||||
|
{
|
||||||
|
if(_mode != e_measureMode::mNone)
|
||||||
|
{
|
||||||
|
setMeasureMode(_mode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log_d("read_button(%d) = %d", _physButton.getPin(), _pressed);
|
||||||
}
|
}
|
||||||
text += value;
|
|
||||||
text += unit;
|
|
||||||
return text;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -80,7 +80,7 @@ public:
|
|||||||
c_onScreenButton(String name, uint8_t index, e_buttonLoc location, bool (*stateFn)()) : _name(name),
|
c_onScreenButton(String name, uint8_t index, e_buttonLoc location, bool (*stateFn)()) : _name(name),
|
||||||
_index(index),
|
_index(index),
|
||||||
_stateFn(stateFn),
|
_stateFn(stateFn),
|
||||||
_physButton(-1, index)
|
_physButton(NOBUTTON, index)
|
||||||
{
|
{
|
||||||
_xpos = 1;
|
_xpos = 1;
|
||||||
_ypos = 1;
|
_ypos = 1;
|
||||||
@@ -104,19 +104,7 @@ public:
|
|||||||
}
|
}
|
||||||
return _state;
|
return _state;
|
||||||
}
|
}
|
||||||
void handle()
|
void handle();
|
||||||
{
|
|
||||||
|
|
||||||
if (_physButton.getPin() != -1)
|
|
||||||
{
|
|
||||||
_pressed = _physButton.read();
|
|
||||||
if (_physButton.isChanged())
|
|
||||||
{
|
|
||||||
log_i("button(%d) %d = %d", _index, _physButton.getIndex(), _pressed);
|
|
||||||
}
|
|
||||||
log_d("read_button(%d) = %d", _index, _pressed);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
void setVisible(bool state) { _visible = state; }
|
void setVisible(bool state) { _visible = state; }
|
||||||
bool getVisible(void) { return _visible; }
|
bool getVisible(void) { return _visible; }
|
||||||
uint8_t getIndex(void) { return _index; }
|
uint8_t getIndex(void) { return _index; }
|
||||||
|
|||||||
@@ -34,4 +34,17 @@ uint16_t getStringWidth(String str, const uint8_t *font)
|
|||||||
{
|
{
|
||||||
getDisplay()->setFont(font);
|
getDisplay()->setFont(font);
|
||||||
return getDisplay()->getStrWidth(str.c_str());
|
return getDisplay()->getStrWidth(str.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
String drawValue(String designator, float value, String unit)
|
||||||
|
{
|
||||||
|
String text;
|
||||||
|
text.clear();
|
||||||
|
if (designator != "")
|
||||||
|
{
|
||||||
|
text = designator;
|
||||||
|
}
|
||||||
|
text += value;
|
||||||
|
text += unit;
|
||||||
|
return text;
|
||||||
}
|
}
|
||||||
@@ -7,3 +7,4 @@ void drawProgressBar(uint16_t x, uint16_t y, uint16_t width, uint16_t height, ui
|
|||||||
void drawDashedHLine(uint16_t x, uint16_t y, uint16_t len);
|
void drawDashedHLine(uint16_t x, uint16_t y, uint16_t len);
|
||||||
void drawDashedVLine(uint16_t x, uint16_t y, uint16_t len);
|
void drawDashedVLine(uint16_t x, uint16_t y, uint16_t len);
|
||||||
uint16_t getStringWidth(String str, const uint8_t *font);
|
uint16_t getStringWidth(String str, const uint8_t *font);
|
||||||
|
String drawValue(String designator, float value, String unit);
|
||||||
|
|||||||
@@ -38,8 +38,6 @@ void handleDisplayHall(void);
|
|||||||
|
|
||||||
void clearDisplay(void);
|
void clearDisplay(void);
|
||||||
|
|
||||||
String showValue(String designator, float value, String unit);
|
|
||||||
|
|
||||||
uint16_t getDisplayWidth(void);
|
uint16_t getDisplayWidth(void);
|
||||||
uint16_t getDisplayHeight(void);
|
uint16_t getDisplayHeight(void);
|
||||||
|
|
||||||
|
|||||||
13
MilliOhmMeter_FW/src/gain_control.cpp
Normal file
13
MilliOhmMeter_FW/src/gain_control.cpp
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#include "gain_control.h"
|
||||||
|
|
||||||
|
c_gainControl mode20mA(e_measureMode::mA20, 1, 1, 0, 0, 1, 1);
|
||||||
|
|
||||||
|
void initGainControl(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleGainControl(void)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
42
MilliOhmMeter_FW/src/gain_control.h
Normal file
42
MilliOhmMeter_FW/src/gain_control.h
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "Arduino.h"
|
||||||
|
#include "measure_mode.h"
|
||||||
|
#include "board.h"
|
||||||
|
|
||||||
|
#define UCCONTROLIO 6
|
||||||
|
|
||||||
|
class c_gainControl
|
||||||
|
{
|
||||||
|
const e_measureMode _mode;
|
||||||
|
|
||||||
|
bool _uc[UCCONTROLIO];
|
||||||
|
uint8_t _ucPin[UCCONTROLIO] = {UC01, UC02, UC03, UC04, UC05, UC06};
|
||||||
|
|
||||||
|
public:
|
||||||
|
c_gainControl(e_measureMode mode, bool uc01, bool uc02, bool uc03, bool uc04, bool uc05, bool uc06) : _mode(mode)
|
||||||
|
{
|
||||||
|
_uc[0] = uc01;
|
||||||
|
_uc[1] = uc02;
|
||||||
|
_uc[02] = uc03;
|
||||||
|
_uc[03] = uc04;
|
||||||
|
_uc[04] = uc05;
|
||||||
|
_uc[05] = uc06;
|
||||||
|
}
|
||||||
|
|
||||||
|
void activate(void)
|
||||||
|
{
|
||||||
|
for(int i = 0; i < UCCONTROLIO-1;i++)
|
||||||
|
{
|
||||||
|
digitalWrite(_ucPin[i], _uc[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
e_measureMode getMode(void)
|
||||||
|
{
|
||||||
|
return _mode;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void initGainControl(void);
|
||||||
|
void handleGainControl(void);
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
#include "measure.h"
|
#include "measure.h"
|
||||||
#include "buttons.h"
|
#include "buttons.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
|
#include "gain_control.h"
|
||||||
|
|
||||||
uint64_t looptime = 0;
|
uint64_t looptime = 0;
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ void setup()
|
|||||||
initBoard();
|
initBoard();
|
||||||
initMeasure();
|
initMeasure();
|
||||||
initDisplay();
|
initDisplay();
|
||||||
|
initGainControl();
|
||||||
looptime = millis();
|
looptime = millis();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,6 +21,7 @@ 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();
|
||||||
handleDisplay();
|
handleDisplay();
|
||||||
log_i("T=%4.2fms\n", (double)(micros() - looptime)/1000);
|
log_i("T=%4.2fms\n", (double)(micros() - looptime)/1000);
|
||||||
}
|
}
|
||||||
@@ -5,15 +5,6 @@ bool measureOK = true;
|
|||||||
bool measureError = false;
|
bool measureError = false;
|
||||||
bool measureOpen = false;
|
bool measureOpen = false;
|
||||||
|
|
||||||
void initMeasureMode(void)
|
|
||||||
{
|
|
||||||
log_i("init measure mode");
|
|
||||||
}
|
|
||||||
|
|
||||||
void handleMeasureMode(void)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void setMeasureMode(e_measureMode newMode)
|
void setMeasureMode(e_measureMode newMode)
|
||||||
{
|
{
|
||||||
@@ -38,4 +29,15 @@ bool getOkState(void)
|
|||||||
bool getOpenState(void)
|
bool getOpenState(void)
|
||||||
{
|
{
|
||||||
return measureOpen;
|
return measureOpen;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void initMeasureMode(void)
|
||||||
|
{
|
||||||
|
log_i("init measure mode");
|
||||||
|
}
|
||||||
|
|
||||||
|
void handleMeasureMode(void)
|
||||||
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user