-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsoftatadevice_urange.cpp
More file actions
96 lines (85 loc) · 2.26 KB
/
softatadevice_urange.cpp
File metadata and controls
96 lines (85 loc) · 2.26 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
#include "SoftataDevice_environsensors.h"
#include <arduino.h>
#include "Ultrasonic.h"
#include <float.h>
#include "SoftataDeviceInfo.h"
Ultrasonic * ultrasonic;
SoftataDevice_URangeSensor::SoftataDevice_URangeSensor(int SetupPin)
{
ultrasonic = new Ultrasonic(SetupPin);
SoftataDevice_Sensor::num_properties = NUM_URANGE_PROPERTIES;
SoftataDevice_Sensor::sensorType = UltrasonicRanger;
}
bool SoftataDevice_URangeSensor::Setup(byte * settings, byte numSettings)
{
return true;
}
bool SoftataDevice_URangeSensor::Setup()
{
return true;
}
String SoftataDevice_URangeSensor::GetPins()
{
String msg = "Ultrasonic Range Sensor Pins:";
msg.concat(URANGE_PINOUT);
return msg;
}
CallbackInfo * SoftataDevice_URangeSensor::GetCallbackInfo()
{
info.period = 314159;
info.next = 137;
info.SensorIndex = 123456;
info.sendBT = false;
info.isSensor=false;
info.isRunning=false;
return &info;
}
Tristate SoftataDevice_URangeSensor::ReadAll(double* values)
{
values[0] = (double)ultrasonic->MeasureInMillimeters();
if(values[0]==0)
values[0] = (double)ultrasonic->MeasureInMillimeters();
values[1] = (double)ultrasonic->MeasureInCentimeters();
if(values[1]==0)
values[1] = (double)ultrasonic->MeasureInCentimeters();
values[2] = (double)ultrasonic->MeasureInInches();
if(values[2]==0)
values[2] = (double)ultrasonic->MeasureInInches();
return (Tristate)true;
}
String SoftataDevice_URangeSensor::GetTelemetry()
{
double values[3];
if(ReadAll(values))
{
String msg ="{\"MeasureInMillimeters\":";
msg.concat(values[0]);
msg.concat(',');
msg.concat("\"MeasureInCentimeters\":");
msg.concat(values[1]);
msg.concat(',');
msg.concat("\"MeasureInInches\":");
msg.concat(values[2]);
msg.concat('}');
return msg;
}
else
return "ERRORDBL";
}
double SoftataDevice_URangeSensor::Read(int property)
{
if(property==0)
{
return (double)ultrasonic->MeasureInMillimeters();
}
else if(property==1)
{
return (double)ultrasonic->MeasureInCentimeters();
}
else if(property==2)
{
return (double)ultrasonic->MeasureInInches();
}
else
return DBL_MAX;
}