Procházet zdrojové kódy

display routines with U8g2

master
Flo Smilari před 3 roky
rodič
revize
2441ae81cc
8 změnil soubory, kde provedl 129 přidání a 17 odebrání
  1. 3
    0
      .cproject
  2. 5
    0
      .project
  3. 2
    0
      .settings/org.eclipse.core.resources.prefs
  4. 30
    16
      Display.cpp
  5. 2
    0
      Display.h
  6. 53
    0
      RotaryControler.cpp
  7. 33
    0
      RotaryControler.h
  8. 1
    1
      sloeber.ino.cpp

+ 3
- 0
.cproject Zobrazit soubor

@@ -36,6 +36,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_SSD1306}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_GFX_Library}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_BusIO}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Fraestisch_SFTools/libraries/U8g2_for_Adafruit_GFX/src}&quot;"/>
</option>
<inputType id="io.sloeber.compiler.cpp.sketch.input.1777418047" name="CPP source files" superClass="io.sloeber.compiler.cpp.sketch.input"/>
</tool>
@@ -58,6 +59,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_SSD1306}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_GFX_Library}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_BusIO}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Fraestisch_SFTools/libraries/U8g2_for_Adafruit_GFX/src}&quot;"/>
</option>
<inputType id="io.sloeber.compiler.c.sketch.input.1282698896" name="C Source Files" superClass="io.sloeber.compiler.c.sketch.input"/>
</tool>
@@ -81,6 +83,7 @@
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_SSD1306}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_GFX_Library}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Fraestisch_SFTools/libraries/Adafruit_BusIO}&quot;"/>
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/Fraestisch_SFTools/libraries/U8g2_for_Adafruit_GFX/src}&quot;"/>
</option>
<inputType id="io.sloeber.compiler.S.sketch.input.1238595277" name="Assembly source files" superClass="io.sloeber.compiler.S.sketch.input"/>
</tool>

+ 5
- 0
.project Zobrazit soubor

@@ -91,6 +91,11 @@
<type>2</type>
<locationURI>ECLIPSE_HOME/arduinoPlugin/libraries/Simple_Repository_IO/1.0.3</locationURI>
</link>
<link>
<name>libraries/U8g2_for_Adafruit_GFX</name>
<type>2</type>
<locationURI>ECLIPSE_HOME/arduinoPlugin/libraries/U8g2_for_Adafruit_GFX/1.8.0</locationURI>
</link>
<link>
<name>libraries/Wire</name>
<type>2</type>

+ 2
- 0
.settings/org.eclipse.core.resources.prefs Zobrazit soubor

@@ -0,0 +1,2 @@
eclipse.preferences.version=1
encoding/<project>=UTF-8

+ 30
- 16
Display.cpp Zobrazit soubor

@@ -9,11 +9,13 @@
#include "Display.h"
/*****************
** Constructors.
****************/
Display::Display() {
ssd1306 = Adafruit_SSD1306(SCREEN_WIDTH, SCREEN_HEIGHT);
u8g2_gfx.begin(ssd1306);
}
/******************
@@ -87,7 +89,7 @@ void Display::showFrame(Status status) {
case CONFIGURATION:
ssd1306.drawLine(37, SCREEN_HEIGHT / 2 - 1, SCREEN_WIDTH - 1, SCREEN_HEIGHT / 2 - 1, SSD1306_WHITE);
drawStatusText (STATUS_TXT_CFG);
drawConfigText("Steigung");
drawConfigText("Höhe WLS");
drawConfigOption("03.00 mm");
break;
case IDLE:
@@ -115,26 +117,38 @@ void Display::calculateWH(String units, uint16_t &w, uint16_t &h) {
h = h1;
}
void Display::drawStatusText(String txt) {
uint16_t w = 0, h = 0;
ssd1306.setFont(&titillium_web_regular8pt7b);
calculateWH(txt, w, h);
ssd1306.setCursor((37 - w) / 2, 11);
ssd1306.println(txt);
char *s;
s = &txt[0];
int16_t w = 0;
u8g2_gfx.setFont(u8g2_font_helvR08_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
w = u8g2_gfx.getUTF8Width(s);
u8g2_gfx.setCursor((37 - w) / 2, 12);
u8g2_gfx.println(F(s));
}
void Display::drawConfigText(String txt) {
uint16_t w = 0, h = 0;
ssd1306.setFont(&titillium_web_semibold12pt7b);
calculateWH(txt, w, h);
ssd1306.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 + h / 2 - 1);
ssd1306.println(txt);
char *s;
s = &txt[0];
int16_t w = 0, h = 0;
u8g2_gfx.setFont(u8g2_font_helvB12_tf); // select u8g2 font from here: https://github.com/olikraus/u8g2/wiki/fntlistall
w = u8g2_gfx.getUTF8Width(s);
h = u8g2_gfx.getFontAscent() - u8g2_gfx.getFontDescent();
u8g2_gfx.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 + h / 2 - 1); // start writing at this position
u8g2_gfx.println(F(s));
}
void Display::drawConfigOption(String txt) {
uint16_t w = 0, h = 0;
ssd1306.setFont(&titillium_web_semibold12pt7b);
calculateWH(txt, w, h);
ssd1306.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 * 3 + h / 2 - 1);
ssd1306.println(txt);
char *s;
s = &txt[0];
int16_t w = 0, h = 0;
u8g2_gfx.setFont(u8g2_font_helvB12_tf);
w = u8g2_gfx.getUTF8Width(s);
h = u8g2_gfx.getFontAscent() - u8g2_gfx.getFontDescent();
u8g2_gfx.setCursor((SCREEN_WIDTH + 37 - w) / 2, SCREEN_HEIGHT / 4 * 3 + h / 2 - 1);
u8g2_gfx.println(F(s));
}

+ 2
- 0
Display.h Zobrazit soubor

@@ -11,6 +11,7 @@
#define DISPLAY_H_
#include <Adafruit_SSD1306.h>
#include <U8g2_for_Adafruit_GFX.h>
#include <stdint.h>
#include "fonts/titillium_web_6pt7b.h"
#include "fonts/titillium_web_8pt7b.h"
@@ -33,6 +34,7 @@
class Display {
private:
Adafruit_SSD1306 ssd1306;
U8G2_FOR_ADAFRUIT_GFX u8g2_gfx;
void calculateWH(String units, uint16_t &w, uint16_t &h);
void drawStatusText(String txt);
void drawConfigText(String txt);

+ 53
- 0
RotaryControler.cpp Zobrazit soubor

@@ -0,0 +1,53 @@
/*
* RotaryControler.cpp
*
* Created on: 04.02.2022
* Author: FSmilari
*/
#include "RotaryControler.h"
/*****************
** Constructors.
****************/
RotaryControler::RotaryControler(int RotEnc_Dta_Pin, int RotEnc_Clk_Pin, int RotEnc_Switch_Pin) : Encoder(RotEnc_Dta_Pin, RotEnc_Clk_Pin,
RotaryEncoder::LatchMode::FOUR3), RotarySwitch(RotEnc_Switch_Pin, true, 2000) {
}
/******************
** Public methods
*****************/
void RotaryControler::tick(void) {
Encoder.tick();
}
void RotaryControler::resetPosition(void) {
Encoder.setPosition(0L);
}
long RotaryControler::getPosition(void) {
return Encoder.getPosition();
}
int RotaryControler::getDirection(void) {
return (int) Encoder.getPosition();
}
bool RotaryControler::isSwitchPressed(void) {
return RotarySwitch.isPressed();
}
bool RotaryControler::isSwitchLongPressed(void) {
return RotarySwitch.isLongPressed();
}
void RotaryControler::setDebounceTime(unsigned long time) {
RotarySwitch.setDebounceTime(time);
}
void RotaryControler::loop(void) {
RotarySwitch.loop();
Encoder.tick();
}

+ 33
- 0
RotaryControler.h Zobrazit soubor

@@ -0,0 +1,33 @@
/*
* RotaryControler.h
*
* Created on: 04.02.2022
* Author: FSmilari
*/
#ifndef ROTARYCONTROLER_H_
#define ROTARYCONTROLER_H_
#include "RotaryEncoder.h"
#include "ExEzButton.h"
class RotaryControler {
private:
RotaryEncoder Encoder;
ExEzButton RotarySwitch;
public:
RotaryControler(int RotEnc_Dta_Pin, int RotEnc_Clk_Pin, int RotEnc_Switch_Pin);
void tick(void);
void resetPosition(void);
bool isSwitchPressed(void);
bool isSwitchLongPressed(void);
long getPosition(void);
int getDirection(void);
void setDebounceTime(unsigned long time);
void loop(void);
};
#endif /* ROTARYCONTROLER_H_ */

+ 1
- 1
sloeber.ino.cpp Zobrazit soubor

@@ -2,7 +2,7 @@
//This is a automatic generated file
//Please do not modify this file
//If you touch this file your change will be overwritten during the next build
//This file has been generated on 2022-02-04 21:44:36
//This file has been generated on 2022-02-05 01:05:00

#include "Arduino.h"
#include <Arduino.h>

Načítá se…
Zrušit
Uložit