-
Notifications
You must be signed in to change notification settings - Fork 24
Expand file tree
/
Copy pathChartShield.cpp
More file actions
128 lines (107 loc) · 2.63 KB
/
ChartShield.cpp
File metadata and controls
128 lines (107 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
Project: 1Sheeld Library
File: ChartShield.cpp
Version: 1.12.0
Compiler: Arduino avr-gcc 4.3.2
Author: Integreight
Date: 2016.12
*/
#define FROM_ONESHEELD_LIBRARY
#include "OneSheeld.h"
#include "ChartShield.h"
ChartShield::ChartShield() : ShieldParent(CHART_ID)
{
for(int i=0;i<5;i++){
namesArray[i]=NULL;
floatArray[i]=0;
chartIDArray[i]=0;
}
keysCounter= 0 ;
}
void ChartShield::add(const char * _key,float _value, byte _chartID)
{
byte found = false;
if(_chartID>=5)
{
_chartID=4;
}
for(int i=0 ;i<keysCounter;i++)
{
if(!strcmp(namesArray[i],_key) && chartIDArray[i]==_chartID)
{
floatArray[i]=_value;
found=true;
}
}
byte keyLength=strlen(_key);
if(!keyLength||keysCounter >= 5) return;
if(!found)
{
key = (char*)malloc(sizeof(char)*(keyLength+1));
for (int j=0; j<keyLength; j++)
{
key[j]=_key[j];
}
key[keyLength]='\0';
namesArray[keysCounter]=key;
floatArray[keysCounter]=_value;
chartIDArray[keysCounter]=_chartID;
keysCounter++;
}
}
void ChartShield::plot()
{
if(keysCounter>0)
{
FunctionArg **arguments =(FunctionArg**)malloc(sizeof(FunctionArg *)*(keysCounter*3));
byte stepCounter =0;
for(int i=0 ;i<keysCounter*3;i+=3)
{
byte floatBytes[4];
OneSheeld.convertFloatToBytes(floatArray[stepCounter],floatBytes);
arguments[i]= new FunctionArg(strlen(namesArray[stepCounter]),(byte*)(namesArray[stepCounter]));
arguments[i+1]= new FunctionArg(4,floatBytes,true);
arguments[i+2]= new FunctionArg(1,&chartIDArray[stepCounter]);
stepCounter++;
}
OneSheeld.sendShieldFrame(CHART_ID,0,CHART_PLOT,keysCounter*3,arguments);
for(int i=0;i<keysCounter*3;i++)
{
delete arguments[i];
}
free(arguments);
for(int i=0 ;i<keysCounter;i++)
{
if(namesArray[i]!=0)
{
free(namesArray[i]);
namesArray[i]=NULL;
floatArray[i]=0;
chartIDArray[i]=0;
}
}
keysCounter=0;
}
}
void ChartShield::saveCsv(const char * fileName,byte _chartID)
{
if(_chartID <5)
{
OneSheeld.sendShieldFrame(CHART_ID,0,CHART_SAVE_CSV,2,new FunctionArg(strlen(fileName),(byte*)fileName),new FunctionArg(1,&_chartID));
}
}
void ChartShield::saveScreenshot(byte _chartID)
{
OneSheeld.sendShieldFrame(CHART_ID,0,CHART_SAVE_SCREENSHOT,1,new FunctionArg(1,&_chartID));
}
void ChartShield::clear(byte _chartID)
{
if(_chartID <5)
{
OneSheeld.sendShieldFrame(CHART_ID,0,CHART_CLEAR,1,new FunctionArg(1,&_chartID));
}
}
void ChartShield::autoScroll(byte state)
{
OneSheeld.sendShieldFrame(CHART_ID,0,CHART_AUTO_SCROLL,1,new FunctionArg(1,&state));
}