Skip to content

Commit

Permalink
Merge pull request #1 from tobozo/0.2.0
Browse files Browse the repository at this point in the history
0.2.0
  • Loading branch information
tobozo authored May 18, 2022
2 parents 7cb540b + 043e61e commit cd0f906
Show file tree
Hide file tree
Showing 11 changed files with 395 additions and 174 deletions.
46 changes: 37 additions & 9 deletions ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ This library was inspired by [ICSMeter](https://github.com/armel/ICSMeter).
```C++
#include <M5Unified.h>
#include <LGFXMeter.h>
void setup()
Expand Down Expand Up @@ -141,7 +143,6 @@ void setup()
ICSGauge = new Gauge_Class( cfg );
ICSGauge->pushGauge(); // render empty gauge (no needle yet)
}
Expand All @@ -154,10 +155,17 @@ void loop()
// map() it to the gauge angular range [0...90]
float my_angle = utils::mapFloat( mySensorValue, 0, 4095, 0.0, 90.0 );
// either animate (300ms blocking) ...
// Either animate (300ms blocking) ...
ICSGauge->animateNeedle( my_angle );
// .. or just update
// .. or use eased drawing (300ms non blocking) ...
ICSGauge->setNeedle( my_angle );
ICSGauge->easeNeedle( 300 );
// ICSGauge->easeNeedle( 300, easing::easeOutBounce );
// /!\ See lgfxmeter_types.hpp for complete list of available easing function
// Function names
// .. or just render the needle without easing or animation
ICSGauge->drawNeedle( my_angle );
}
Expand All @@ -171,20 +179,21 @@ void loop()

Background, needle and needle shadow images can be any of the following formats:

- PNG
- QOI
- JPG
- BMP
- PNG: `IMAGE_PNG`
- QOI: `IMAGE_QOI`
- JPG: `IMAGE_JPG`
- BMP: `IMAGE_BMP`
- RAW: `IMAGE_RAW` (e.g. Sprite, untested)


As seen in the examples, image data should be stored in byte arrays.
As seen in the examples, image data can be stored in byte arrays.

```C++

const image_t bgImg = { 16, bg_png, bg_png_len, IMAGE_PNG, 320, 240 };
const image_t vuMeterArrow = { 16, clock_arrow_png, clock_arrow_png_len, IMAGE_PNG, 16, 144 };
const image_t vuMeterShadow = { 16, clock_arrow_shadow_png, clock_arrow_shadow_png_len, IMAGE_PNG, 16, 144 };


```
Custom background, needle and shadow can be setup as follows:
Expand All @@ -198,6 +207,7 @@ Custom background, needle and shadow can be setup as follows:
cfg.needleCfg.needleImg = &vuMeterArrow;
cfg.needleCfg.shadowImg = &vuMeterShadow;
//cfg.needleCfg.scaleX = 0.5; // scaling down a stretched image to produce nicer antialiased result
//cfg.needle.axis = { GaugeWidth/2, GaugePosY + GaugeHeight }; // will be automatically positioned with a clunky calculation otherwise
// Optionally share a background image between TFT and the gauge sprite
Expand All @@ -210,7 +220,25 @@ Custom background, needle and shadow can be setup as follows:
```

Background can eventually be changed after gauge creation, but it will remove any previously drawn rulers.
However if the gauge is built without rulers and uses a simple background image, then custom modes (e.g. dark/light) are possible.

```C++

// firt create your image entity
const image_t alternateBgImage = { 16, my_image_data, my_image_data_len, IMAGE_PNG, GaugeWidth, GaugeWidth };

// overwrite the gauge background (will also remove the rulers !)
utils::drawImage( ICSGauge->getGaugeSprite(), alternateBgImage, 0, 0 );

// eventually change the transparency color depending on the saturation
needle::cfg.transparent_color = is_background_dark ? 0x000000U : 0xffffffU;

// or toggle needle shadow in dark mode
needle::cfg.drop_shadow = is_background_dark ? false : true;


```
Expand Down
20 changes: 10 additions & 10 deletions examples/IC705Gauge/main/IC705.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,22 @@ namespace LGFXMeter
// [ S..3..5..7..8..+10..+30..+60 ]
const ruler_unit_t Units_S[] = {
/*{ idx, angle, label, size, distance, fontFace, fontSize, textDatum }*/
{ 0, 0.0f, "S", 10, 12, &FreeSansBold18pt7b, 1.0f, MC_DATUM },
{ 0, 0.0f, "S", 10, 12, &FreeSansBold12pt7b, 1.0f, MC_DATUM },
{ 1, 0.5f, nullptr, 10, 0, nullptr, 0.0f, MC_DATUM },
{ 2, 1.0f*_14th, nullptr, 5, 0, nullptr, 0.0f, MC_DATUM },
{ 3, 2.0f*_14th, "3", 10, 12, &FreeSansBold12pt7b, 0.95f, MC_DATUM },
{ 3, 2.0f*_14th, "3", 10, 12, &FreeSans12pt7b, 1.0f, MC_DATUM },
{ 4, 3.0f*_14th, nullptr, 5, 0, nullptr, 0.0f, MC_DATUM },
{ 5, 4.0f*_14th, "5", 10, 12, &FreeSansBold12pt7b, 0.95f, MC_DATUM },
{ 5, 4.0f*_14th, "5", 10, 12, &FreeSans12pt7b, 1.0f, MC_DATUM },
{ 6, 5.0f*_14th, nullptr, 5, 0, nullptr, 0.0f, MC_DATUM },
{ 7, 6.0f*_14th, "7", 10, 12, &FreeSansBold12pt7b, 0.95f, MC_DATUM },
{ 7, 6.0f*_14th, "7", 10, 12, &FreeSans12pt7b, 1.0f, MC_DATUM },
{ 8, 7.0f*_14th, nullptr, 5, 0, nullptr, 0.0f, MC_DATUM },
{ 9, 8.0f*_14th, "9", 10, 12, &FreeSansBold12pt7b, 0.95f, MC_DATUM },
{ 10, 9.0f*_14th, "+10", 10, 13, &FreeSansBold9pt7b, 0.8f, MC_DATUM },
{ 9, 8.0f*_14th, "9", 10, 12, &FreeSans12pt7b, 1.0f, MC_DATUM },
{ 10, 9.0f*_14th, "+10", 10, 13, &FreeSans9pt7b, 1.0f, MC_DATUM },
{ 11, 10.0f*_14th, nullptr, 0, 0, nullptr, 0.0f, MC_DATUM },
{ 12, 11.0f*_14th, "+30", 10, 13, &FreeSansBold9pt7b, 0.8f, MC_DATUM },
{ 12, 11.0f*_14th, "+30", 10, 13, &FreeSans9pt7b, 1.0f, MC_DATUM },
{ 13, 12.0f*_14th, nullptr, 0, 0, nullptr, 0.0f, MC_DATUM },
{ 14, 13.0f*_14th, nullptr, 0, 0, nullptr, 0.0f, MC_DATUM },
{ 15, 14.0f*_14th, "+60", 10, 13, &FreeSansBold9pt7b, 0.8f, MC_DATUM },
{ 15, 14.0f*_14th, "+60", 10, 13, &FreeSans9pt7b, 1.0f, MC_DATUM },
};

// in between +10+20+60 red rulers for Units_S
Expand Down Expand Up @@ -94,7 +94,7 @@ namespace LGFXMeter
};

// [ SWR..1..1.5..2...3...4..5.10.∞ ]
const char* copyright = "ICSMeter V0.0.2 by F4HWN";
const char* copyright = "LGFXMeter demo by tobozo";
const ruler_unit_t Units_SWR[] = {
/*{ idx, angle, label, size, distance, fontFace, fontSize, textDatum }*/
{ 0, -5.0f, "SWR", 0, 10, &FreeSans12pt7b, 0.5f, TC_DATUM },
Expand All @@ -109,7 +109,7 @@ namespace LGFXMeter
{ 9, 66.0f, "10", 8, 10, &FreeSans12pt7b, 0.5f, MC_DATUM },
{ 10, 79.5f, "", 8, 10, &FreeSans12pt7b, 0.5f, MC_DATUM },
{ 11, 45.0f, "IC-705", 0, -1, &FreeSansBold18pt7b, 0.65f, TC_DATUM }, // main title ruler
{ 11, 45.0f, "F4HWN", 0, -25, &Orbitron_Light_24, 0.50f, TC_DATUM }, // vanity ruler
{ 11, 45.0f,"@tobozo", 0, -25, &Orbitron_Light_24, 0.50f, TC_DATUM }, // vanity ruler
{ 12, 45.0f, copyright, 0, -40, &Roboto_Thin_24, 0.50f, TC_DATUM }, // copyright ruler
};

Expand Down
8 changes: 5 additions & 3 deletions examples/IC705Gauge/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,16 @@ void setup()
// - 320*160 gauge with cfg.zoomAA=1.0 will use a 320*160 mask with NO antialias
//
// cfg.zoomAA = psramInit() ? 0.5 : 1.0;
//cfg.zoomAA = 1.0;

// Optionally use pre-rendered arrow and custom shadow
// - Image can be any size (scale will constrained) but smaller is faster, transparent png works
// - Pointy end of the arrow goes on the top
// - Shadow image must have same dimensions as arrow image
//cfg.needleCfg.needleImg = &pixelArrow;
//cfg.needleCfg.shadowImg = &shadowArrow;
//cfg.needleCfg.scaleX = 0.5; // scaling down a stretched image to produce nicer antialiased result
//cfg.needle.img = &pixelArrow;
//cfg.needle.shadow = &shadowArrow;
//cfg.needle.scaleX = 0.5; // scaling down a stretched image to produce nicer antialiased result
//cfg.needle.axis = { GaugeWidth/2, GaugePosY+GaugeHeight }; // will be automatically positioned with a clunky calculation otherwise

// Optionally share a background image between TFT and the gauge sprite
// - Image must be png/jpg/bmp/qoi or byte array
Expand Down
2 changes: 1 addition & 1 deletion examples/VUMeter/main/VUMeter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace LGFXMeter
{ 13, 70.0f, "+1", 12, 15, &FreeSans12pt7b, 0.8f, MC_DATUM },
{ 14, 80.0f, "+2", 12, 15, &FreeSans12pt7b, 0.8f, MC_DATUM },
{ 15, 90.0f, "+3", 12, 15, &FreeSans12pt7b, 0.8f, MC_DATUM },
{ 16, 45.0f, "VU", 0, -20, &Orbitron_Light_24, 1.5f, TC_DATUM }, // vanity ruler
{ 16, 45.0f, "VU", 0, -20, &Orbitron_Light_24, 1.5f, TC_DATUM }, // main title ruler
};


Expand Down
14 changes: 9 additions & 5 deletions examples/VUMeter/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,10 +303,9 @@ void gfxSetup(LGFX_Device* gfx)
.w = GaugeWidth,
.h = GaugeHeight
};

cfg.needleCfg.needleImg = &vuMeterArrow;
cfg.bgImage = &bgImg;

cfg.needle.img = &vuMeterArrow;
cfg.needle.axis = { GaugeWidth/2, GaugePosY+GaugeHeight };
cfg.bgImage = &bgImg;
VUMeterGauge = new Gauge_Class( cfg );
}

Expand Down Expand Up @@ -363,6 +362,7 @@ void gfxLoop(LGFX_Device* gfx)
{
static int prev_x[2];
static int peak_x[2];
float avglevel=0, lastavglevel=0;

auto buf = out.getBuffer();
if (buf)
Expand Down Expand Up @@ -409,7 +409,11 @@ void gfxLoop(LGFX_Device* gfx)
}
}

VUMeterGauge->drawNeedle( (levels[0]+levels[1])*0.5f );
avglevel = (levels[0]+levels[1])*0.5f;
if( avglevel!=lastavglevel ) {
VUMeterGauge->drawNeedle( avglevel );
lastavglevel = avglevel;
}

gfx->display();
gfx->endWrite();
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"type": "git",
"url": "https://github.com/tobozo/LGFXMeter.git"
},
"version": "0.1.1",
"version": "0.2.0",
"frameworks": "arduino",
"platforms": "espressif32",
"headers": "LGFXMeter.h",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=LGFXMeter
version=0.1.1
version=0.2.0
author=tobozo
maintainer=tobozo
sentence=LGFX based Gauge Decoration and Animation library
Expand Down
4 changes: 2 additions & 2 deletions src/LGFXMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

#ifdef __cplusplus

#include "lgfx_meter/Gauge_Class.hpp"
#include "lgfx_meter/Gauge_Class.hpp"

#else

#error LGFXMeter requires a C++ compiler, please change file extension to .cc or .cpp
#error "LGFXMeter requires a C++ compiler, please change file extension to .cc or .cpp"

#endif

Loading

0 comments on commit cd0f906

Please sign in to comment.