ESP_IOT v2.5
IOT ESP Coding
Sonic_I2CSensorClass.cpp
Go to the documentation of this file.
1
2
4
5#include "../../defines.h"
6#if defined(ESP_M5) && !defined(ESP_M5_MINIMAL_SENSORS)
7//#include <iostream>
8#include <string.h>
9#include <stdio.h>
10
11#ifdef ESP_M5
12#ifdef M5CORE2_MODULE
13#include <M5Display.h>
14#else
15
16#ifdef M5STICKCPLUS2
17#include <M5StickCPlus.h>
18#endif
19
20#include <Unit_Sonic.h>
21//!@see https://github.com/m5stack/M5Unit-Sonic/blob/master/examples/Unit_SonicI2C_M5StickCPlus/Unit_SonicI2C_M5StickCPlus.ino
22#endif
23#endif
24
26{
27
28 printf("Sonic_I2CSensorClass init %s\n", config);
29
30}
31
33{
34 printf("Sonic_I2CSensorClass destroy\n");
35}
36
37
38
39//#define USE_LED_BREATH //not working, (working for M5button and Core2)
40//! for ATOM (maybe change the priority and see what happens)
41
42
43//!wrapper static method
44void Sonic_I2CSensorClass::startTaskImpl(void* _this)
45{
46 SerialDebug.printf(" startTaskImpl == %p\n", _this);
47
48}
49 //!setup the Sonic_I2C
50void Sonic_I2CSensorClass::setupSonic_I2C()
51{
52 SerialDebug.printf(" setupSonic_I2C == %p\n", this);
53
54 //!start the sensor
55 _sensor.begin();
56}
57
58
59//! loop the key unit (after other called M5.updfate)
60void Sonic_I2CSensorClass::loopSonic_I2C()
61{
62 static float sensorValue = 0;
63 sensorValue = _sensor.getDistance();
64 if (sensorValue < 3000 && sensorValue > 20)
65 {
66
67 SerialDebug.printf("Sensor Value %f\n", sensorValue);
68
69 //!call the callback VALUE
70 callCallbackValue((char*)"sonic",(int)sensorValue);
71
72 }
73}
74
75
76
77
78//! error: https://stackoverflow.com/questions/3065154/undefined-reference-to-vtable
79//!@see https://www.w3schools.com/cpp/cpp_class_methods.asp
81{
82 //!setup the Sonic_I2C
83 loopSonic_I2C();
84
85 //delay(100);
86}
87
89{
90 printf("Sonic_I2CSensorClass::setup()\n");
91
92 setupSonic_I2C();
93}
94
95
96#ifdef NOT_DEFINED
97
98
99//! adding the messages as well
100//! 5.14.25 (Laura/Paul flying). 5.14.74 great Dead
101//! 8.28.23 Adding a way for others to get informed on messages that arrive
102//! for the set,val
103//! 12.27.23 support setName == "socket"
104//! 1.10.24 if deviceNameSpecified then this matches this device, otherwise for all.
105//! It's up to the receiver to decide if it has to be specified
106void Sonic_I2CSensorClass::messageSetVal_SensorClassType(char *setName, char* valValue, boolean deviceNameSpecified)
107{
108
109}
110
111//! 12.28.23, 8.28.23 Adding a way for others to get informed on messages that arrive
112//! for the send -
114{
115
116}
117
118//! 12.28.23, 8.28.23 Adding a way for others to get informed on messages that arrive
119//! for the cmd
121{
122
123}
124//! 5.15.25 try a special command local to this class
126{
127
128}
129
130#endif
131
132
133#endif
virtual void messageCmd_SensorClassType(char *cmdValue)
virtual void messageSend_SensorClassType(char *sendValue)
virtual void messageSetVal_SensorClassType(char *setName, char *valValue, boolean deviceNameSpecified)
void callCallbackValue(char *info, int value)
call the callback
virtual void messageLocal_SensorClassType(char *message)
5.15.25 try a special command local to this class
Sonic_I2CSensorClass(char *config)
constructor
void loop()
Pure Virtual Function.
void setup()
Pure Virtual Function.