added schematics Henk

This commit is contained in:
2022-02-08 19:29:52 +01:00
parent 10bb73cdef
commit d43ba0a879
82 changed files with 46368 additions and 0 deletions

View File

@@ -0,0 +1,100 @@
// Arduino Button Library
// https://github.com/JChristensen/JC_Button
// Copyright (C) 2018 by Jack Christensen and licensed under
// GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
#include "JC_Button.h"
/*----------------------------------------------------------------------*
/ initialize a Button object and the pin it's connected to. *
/-----------------------------------------------------------------------*/
void Button::begin()
{
pinMode(m_pin, m_puEnable ? INPUT_PULLUP : INPUT);
m_state = digitalRead(m_pin);
if (m_invert) m_state = !m_state;
m_time = millis();
m_lastState = m_state;
m_changed = false;
m_lastChange = m_time;
}
/*----------------------------------------------------------------------*
/ returns the state of the button, true if pressed, false if released. *
/ does debouncing, captures and maintains times, previous state, etc. *
/-----------------------------------------------------------------------*/
bool Button::read()
{
uint32_t ms = millis();
bool pinVal = digitalRead(m_pin);
if (m_invert) pinVal = !pinVal;
if (ms - m_lastChange < m_dbTime)
{
m_changed = false;
}
else
{
m_lastState = m_state;
m_state = pinVal;
m_changed = (m_state != m_lastState);
if (m_changed) m_lastChange = ms;
}
m_time = ms;
return m_state;
}
/*----------------------------------------------------------------------*
* isPressed() and isReleased() check the button state when it was last *
* read, and return false (0) or true (!=0) accordingly. *
* These functions do not cause the button to be read. *
*----------------------------------------------------------------------*/
bool Button::isPressed()
{
return m_state;
}
bool Button::isReleased()
{
return !m_state;
}
/*----------------------------------------------------------------------*
* wasPressed() and wasReleased() check the button state to see if it *
* changed between the last two reads and return false (0) or *
* true (!=0) accordingly. *
* These functions do not cause the button to be read. *
*----------------------------------------------------------------------*/
bool Button::wasPressed()
{
return m_state && m_changed;
}
bool Button::wasReleased()
{
return !m_state && m_changed;
}
/*----------------------------------------------------------------------*
* pressedFor(ms) and releasedFor(ms) check to see if the button is *
* pressed (or released), and has been in that state for the specified *
* time in milliseconds. Returns false (0) or true (!=0) accordingly. *
* These functions do not cause the button to be read. *
*----------------------------------------------------------------------*/
bool Button::pressedFor(uint32_t ms)
{
return m_state && m_time - m_lastChange >= ms;
}
bool Button::releasedFor(uint32_t ms)
{
return !m_state && m_time - m_lastChange >= ms;
}
/*----------------------------------------------------------------------*
* lastChange() returns the time the button last changed state, *
* in milliseconds. *
*----------------------------------------------------------------------*/
uint32_t Button::lastChange()
{
return m_lastChange;
}

View File

@@ -0,0 +1,111 @@
// Arduino Button Library
// https://github.com/JChristensen/JC_Button
// Copyright (C) 2018 by Jack Christensen and licensed under
// GNU GPL v3.0, https://www.gnu.org/licenses/gpl.html
#ifndef JC_BUTTON_H_INCLUDED
#define JC_BUTTON_H_INCLUDED
#include <Arduino.h>
class Button
{
public:
// Button(pin, dbTime, puEnable, invert) instantiates a button object.
//
// Required parameter:
// pin The Arduino pin the button is connected to
//
// Optional parameters:
// dbTime Debounce time in milliseconds (default 25ms)
// puEnable true to enable the AVR internal pullup resistor (default true)
// invert true to interpret a low logic level as pressed (default true)
Button(uint8_t pin, uint32_t dbTime=25, uint8_t puEnable=true, uint8_t invert=true)
: m_pin(pin), m_dbTime(dbTime), m_puEnable(puEnable), m_invert(invert) {}
// Initialize a Button object and the pin it's connected to
void begin();
// Returns the current debounced button state, true for pressed,
// false for released. Call this function frequently to ensure
// the sketch is responsive to user input.
bool read();
// Returns true if the button state was pressed at the last call to read().
// Does not cause the button to be read.
bool isPressed();
// Returns true if the button state was released at the last call to read().
// Does not cause the button to be read.
bool isReleased();
// Returns true if the button state at the last call to read() was pressed,
// and this was a change since the previous read.
bool wasPressed();
// Returns true if the button state at the last call to read() was released,
// and this was a change since the previous read.
bool wasReleased();
// Returns true if the button state at the last call to read() was pressed,
// and has been in that state for at least the given number of milliseconds.
bool pressedFor(uint32_t ms);
// Returns true if the button state at the last call to read() was released,
// and has been in that state for at least the given number of milliseconds.
bool releasedFor(uint32_t ms);
// Returns the time in milliseconds (from millis) that the button last
// changed state.
uint32_t lastChange();
private:
uint8_t m_pin; // arduino pin number connected to button
uint32_t m_dbTime; // debounce time (ms)
bool m_puEnable; // internal pullup resistor enabled
bool m_invert; // if true, interpret logic low as pressed, else interpret logic high as pressed
bool m_state; // current button state, true=pressed
bool m_lastState; // previous button state
bool m_changed; // state changed since last read
uint32_t m_time; // time of current state (ms from millis)
uint32_t m_lastChange; // time of last state change (ms)
};
// a derived class for a "push-on, push-off" (toggle) type button.
// initial state can be given, default is off (false).
class ToggleButton : public Button
{
public:
// constructor is similar to Button, but includes the initial state for the toggle.
ToggleButton(uint8_t pin, bool initialState=false, uint32_t dbTime=25, uint8_t puEnable=true, uint8_t invert=true)
: Button(pin, dbTime, puEnable, invert), m_toggleState(initialState) {}
// read the button and return its state.
// should be called frequently.
bool read()
{
Button::read();
if (wasPressed())
{
m_toggleState = !m_toggleState;
m_changed = true;
}
else
{
m_changed = false;
}
return m_toggleState;
}
// has the state changed?
bool changed() {return m_changed;}
// return the current state
bool toggleState() {return m_toggleState;}
private:
bool m_toggleState;
bool m_changed;
};
#endif

View File

@@ -0,0 +1,115 @@
#include "buttons.h"
std::vector<c_button *> buttonlist;
c_button button1(BUTTON1, 1);
c_button button2(BUTTON2, 2);
c_button button3(BUTTON3, 3);
c_button button4(BUTTON4, 4);
c_button button5(BUTTON5, 5);
void buttonbegin(c_button *thisbutton)
{
thisbutton->begin();
buttonlist.push_back(thisbutton);
}
void initButtons(void)
{
Serial.print("Init buttons:");
buttonbegin(&button1);
buttonbegin(&button2);
buttonbegin(&button3);
buttonbegin(&button4);
buttonbegin(&button5);
Serial.println("OK");
}
void handleButtons(void)
{
for (auto &&i : buttonlist)
{
i->read();
}
}
bool anybutton(void)
{
handleButtons();
for (auto &&i : buttonlist)
{
if (i->isPressed())
{
return true;
}
}
return false;
}
bool anyButtonChanged(void)
{
handleButtons();
for (auto &&i : buttonlist)
{
if (i->isChanged())
{
return true;
}
}
return false;
}
bool allButtons(void)
{
for (auto &&thisbutton : buttonlist)
{
if (!thisbutton->isPressed())
{
return false;
}
}
return true;
}
bool buttonIsPressed(uint16_t index)
{
c_button *thisbutton = getButton(index);
if (thisbutton == NULL)
{
return false;
}
else
{
return thisbutton->isPressed();
}
}
c_button *getButton(unsigned int index)
{
if (index > buttonlist.size())
{
return NULL;
}
return buttonlist[index - 1];
}
std::vector<c_button *> *getButtonlist(void)
{
return &buttonlist;
}
uint8_t buttonPressedCount(void)
{
uint8_t count = 0;
for (auto &&button : buttonlist)
{
if (button != NULL)
{
if (button->isPressed())
{
count++;
}
}
}
return count;
}

View File

@@ -0,0 +1,31 @@
#pragma once
#include "Arduino.h"
#include <vector>
#include "JC_Button.h"
#include "board.h"
class c_button : public ToggleButton
{
const uint8_t _index;
public:
c_button(uint8_t pin, uint8_t index )
: ToggleButton(pin), _index(index) {}
uint8_t getIndex( void ) {return _index;}
bool isChanged( void ) {return changed();}
};
void initButtons(void);
void handleButtons(void);
bool anybutton(void);
bool anyButtonChanged(void);
bool allButtons(void);
c_button *getButton(unsigned int index);
bool buttonIsPressed(uint16_t index);
uint8_t buttonPressedCount( void );
std::vector<c_button *>* getButtonlist(void);

View File

@@ -0,0 +1,119 @@
#include "gui.h"
c_onScreenButton ma20("20m", (uint8_t)mA20, LocBottom);
c_onScreenButton ma200("200m", (uint8_t)mA200, LocBottom);
c_onScreenButton ma1000("1A", (uint8_t)mA1000, LocBottom);
c_onScreenButton mauto("Auto", (uint8_t)mAuto, LocBottom);
c_onScreenButton bsetup("Conf", 5, LocBottom);
c_onScreenButton errorState("ER", 6, LocRight, &getErrorState);
c_onScreenButton okState("OK", 7, LocRight, &getOkState);
c_onScreenButton openState("Open", 8, LocRight, &getOpenState);
c_onScreenButton wifiState("Wifi", 9, LocRight, &getWifiState);
std::vector<c_onScreenButton> MainScreen;
displayState CurrentGuiState;
void initGui(void)
{
Serial.print("Init GUI: ");
uint16_t screenwidth = getDisplayWidth() - 1;
uint16_t buttonwidth = ((screenwidth / mLast) - CONTROLLOFFSET * 2) - 1;
uint16_t currentWidth = 0;
uint16_t ypos = getDisplayHeight() - 1 - CONTROLSLINE_H + 2;
//setup bottom buttons
ma20.begin(currentWidth, ypos, buttonwidth, CONTROLSLINE_H + 6, CONTROLRADIUS);
ma200.begin(currentWidth += (buttonwidth - 1), ypos, buttonwidth, CONTROLSLINE_H + CONTROLRADIUS, CONTROLRADIUS);
ma1000.begin(currentWidth += (buttonwidth - 1), ypos, buttonwidth, CONTROLSLINE_H + CONTROLRADIUS, CONTROLRADIUS);
mauto.begin(currentWidth += (buttonwidth - 1), ypos, buttonwidth, CONTROLSLINE_H + CONTROLRADIUS, CONTROLRADIUS);
bsetup.begin(currentWidth += (buttonwidth - 1), ypos, buttonwidth, CONTROLSLINE_H + CONTROLRADIUS, CONTROLRADIUS);
//setup right side indicators
uint16_t currentYpos = 0;
uint16_t IndicatorXpos = screenwidth - INDICATORWIDTH - (INDICATORWIDTH / 2);
errorState.begin(IndicatorXpos, currentYpos, INDICATORWIDTH, INDICATORHEIGHT, INDICATORRADIUS);
okState.begin(IndicatorXpos, currentYpos += (INDICATORHEIGHT - 1), INDICATORWIDTH, INDICATORHEIGHT, INDICATORRADIUS);
openState.begin(IndicatorXpos, currentYpos += (INDICATORHEIGHT - 1), INDICATORWIDTH, INDICATORHEIGHT, INDICATORRADIUS);
wifiState.begin(IndicatorXpos, currentYpos += (INDICATORHEIGHT - 1), INDICATORWIDTH, INDICATORHEIGHT, INDICATORRADIUS);
//fill vector
Serial.print("Store");
MainScreen.push_back(ma20);
MainScreen.push_back(ma200);
MainScreen.push_back(ma1000);
MainScreen.push_back(mauto);
MainScreen.push_back(bsetup);
MainScreen.push_back(errorState);
MainScreen.push_back(okState);
MainScreen.push_back(openState);
MainScreen.push_back(wifiState);
for (auto &&button : MainScreen)
{
button.setVisible(true);
}
CurrentGuiState = mainscreen;
Serial.println("OK");
}
void drawMainSceenButtons()
{
//draw controlstrip indicators
for (auto &&thismode : MainScreen)
{
thismode.setState((thismode.getIndex() == (uint8_t)getMeasureMode()));
thismode.drawButton();
}
}
void drawMainscreenValues()
{
if (getDisplay() == NULL)
{
return;
}
drawDashedHLine(0, 12, 220);
drawDashedVLine(40, 12, 33);
getDisplay()->setFont(FONT8);
getDisplay()->drawStr(5, 8, "Fs:100Hz LP");
getDisplay()->setFont(FONT24);
//display.drawStr(60, 45, String(getValue()).c_str());
getDisplay()->setCursor(60, 45);
getDisplay()->printf("%4.2f", getValue());
uint16_t stringwidth = getDisplay()->getStrWidth(showValue("", getValue(), "").c_str());
getDisplay()->setFont(u8g2_font_8x13_t_symbols);
getDisplay()->drawUTF8(60 + stringwidth + 3, 43, "mΩ");
//drawProgressBar(0, 40, 127, 5, getBar());
}
void drawMainScreen()
{
drawMainSceenButtons();
drawMainscreenValues();
}
void handleGui(void)
{
clearDisplay();
switch (CurrentGuiState)
{
case mainscreen:
{
drawMainScreen();
}
break;
case setupscreen:
{
}
break;
}
}

View File

@@ -0,0 +1,16 @@
#pragma once
#include "Arduino.h"
#include "display.h"
#include "measure.h"
typedef enum
{
mainscreen,
setupscreen
} displayState;
void initGui(void);
void handleGui(void);
displayState getDisplayState(void);