Skip to content

Commit 3f486e0

Browse files
committed
add gauge block
1 parent 94e432a commit 3f486e0

File tree

4 files changed

+87
-0
lines changed

4 files changed

+87
-0
lines changed

src/AdafruitIO_Dashboard.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,8 @@ SliderBlock* AdafruitIO_Dashboard::addSliderBlock(AdafruitIO_Feed *feed)
7373
{
7474
return new SliderBlock(this, feed);
7575
}
76+
77+
GaugeBlock* AdafruitIO_Dashboard::addGaugeBlock(AdafruitIO_Feed *feed)
78+
{
79+
return new GaugeBlock(this, feed);
80+
}

src/AdafruitIO_Dashboard.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "blocks/ToggleBlock.h"
1818
#include "blocks/MomentaryBlock.h"
1919
#include "blocks/SliderBlock.h"
20+
#include "blocks/GaugeBlock.h"
2021

2122
// forward declaration
2223
class AdafruitIO;
@@ -36,6 +37,7 @@ class AdafruitIO_Dashboard {
3637
ToggleBlock* addToggleBlock(AdafruitIO_Feed *feed);
3738
MomentaryBlock* addMomentaryBlock(AdafruitIO_Feed *feed);
3839
SliderBlock* addSliderBlock(AdafruitIO_Feed *feed);
40+
GaugeBlock* addGaugeBlock(AdafruitIO_Feed *feed);
3941

4042
private:
4143
AdafruitIO *_io;

src/blocks/GaugeBlock.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//
2+
// Adafruit invests time and resources providing this open source code.
3+
// Please support Adafruit and open source hardware by purchasing
4+
// products from Adafruit!
5+
//
6+
// Copyright (c) 2015-2016 Adafruit Industries
7+
// Authors: Tony DiCola, Todd Treece
8+
// Licensed under the MIT license.
9+
//
10+
// All text above must be included in any redistribution.
11+
//
12+
#include "GaugeBlock.h"
13+
14+
GaugeBlock::GaugeBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f) : AdafruitIO_Block(d, f)
15+
{
16+
min = 0;
17+
max = 100;
18+
width = "THIN";
19+
label = "Value";
20+
}
21+
22+
GaugeBlock::~GaugeBlock(){}
23+
24+
String GaugeBlock::properties()
25+
{
26+
int w = 0;
27+
28+
if(width == "THIN") {
29+
w = 25;
30+
} else {
31+
w = 50;
32+
}
33+
34+
String props = "{\"minValue\":\"";
35+
props += min;
36+
props += "\",\"maxValue\":\"";
37+
props += max;
38+
props += "\",\"ringWidth\":\"";
39+
props += w;
40+
props += "\",\"label\":\"";
41+
props += label;
42+
props += "\"}";
43+
44+
return props;
45+
}

src/blocks/GaugeBlock.h

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// Adafruit invests time and resources providing this open source code.
3+
// Please support Adafruit and open source hardware by purchasing
4+
// products from Adafruit!
5+
//
6+
// Copyright (c) 2015-2016 Adafruit Industries
7+
// Authors: Tony DiCola, Todd Treece
8+
// Licensed under the MIT license.
9+
//
10+
// All text above must be included in any redistribution.
11+
//
12+
#ifndef ADAFRUITIO_GAUGEBLOCK_H
13+
#define ADAFRUITIO_GAUGEBLOCK_H
14+
15+
#include "AdafruitIO_Block.h"
16+
17+
class GaugeBlock : public AdafruitIO_Block {
18+
19+
public:
20+
GaugeBlock(AdafruitIO_Dashboard *d, AdafruitIO_Feed *f);
21+
~GaugeBlock();
22+
23+
int min;
24+
int max;
25+
const char *width;
26+
const char *label;
27+
28+
String properties();
29+
30+
private:
31+
const char *_visual_type = "gauge";
32+
33+
};
34+
35+
#endif // ADAFRUITIO_GAUGEBLOCK_H

0 commit comments

Comments
 (0)