Close and reopen
This commit is contained in:
Родитель
666333013f
Коммит
085f16539e
|
@ -67,6 +67,12 @@ void setup() {
|
|||
SerialPnPSchema::SchemaFloat,
|
||||
"pH");
|
||||
|
||||
SerialPnP::NewEvent("ambient_light",
|
||||
"Ambient Light",
|
||||
"Ambient Light on plant",
|
||||
SerialPnPSchema::SchemaFloat,
|
||||
"%");
|
||||
|
||||
SerialPnP::NewProperty("sample_rate",
|
||||
"Sample Rate",
|
||||
"Sample rate for sensors",
|
||||
|
@ -173,15 +179,15 @@ float getPhSensor() {
|
|||
// return val;
|
||||
// }
|
||||
|
||||
// float getLightSensor()
|
||||
// {
|
||||
// float val = 1024 - analogRead(LIGHT_SENSOR_1);
|
||||
// if (val != 0) {
|
||||
// val /= 1024;
|
||||
// }
|
||||
float getLightSensor()
|
||||
{
|
||||
float val = 1024 - analogRead(LIGHT_SENSOR_1);
|
||||
if (val != 0) {
|
||||
val /= 1024;
|
||||
}
|
||||
|
||||
// return val;
|
||||
// }
|
||||
return val;
|
||||
}
|
||||
|
||||
// void setLightSwitch(uint8_t *in, uint8_t *out)
|
||||
// {
|
||||
|
@ -235,6 +241,8 @@ void loop() {
|
|||
|
||||
SerialPnP::SendEvent("ec", getEcSensor());
|
||||
SerialPnP::SendEvent("ph", getPhSensor());
|
||||
SerialPnP::SendEvent("ambient_light", getLightSensor());
|
||||
|
||||
// String ecstr = String(rep, 4);
|
||||
// Serial.write("EC : ");
|
||||
// Serial.write(ecstr.c_str());
|
||||
|
|
|
@ -167,6 +167,11 @@ namespace PnpGateway.Serial
|
|||
this.Operational = true;
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
this.PacketInterface.Close();
|
||||
}
|
||||
|
||||
private async Task RegisterWithPnP()
|
||||
{
|
||||
var interf = this.Interfaces[0];
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace SerialPnPUtility
|
|||
static void Main(string[] args)
|
||||
{
|
||||
SerialPnPDevice dev = null;
|
||||
PnpDeviceClient dclient = new PnpDeviceClient();
|
||||
PnpDeviceClient dclient = null;
|
||||
|
||||
while (true) {
|
||||
string command = Console.ReadLine();
|
||||
|
@ -19,6 +19,7 @@ namespace SerialPnPUtility
|
|||
|
||||
if (cmd[0].Equals("open"))
|
||||
{
|
||||
dclient = new PnpDeviceClient();
|
||||
dev = new SerialPnPDevice(cmd[1], dclient);
|
||||
dev.Start();
|
||||
}
|
||||
|
@ -81,6 +82,13 @@ namespace SerialPnPUtility
|
|||
Console.WriteLine("RET : " + res);
|
||||
});
|
||||
}
|
||||
|
||||
else if (cmd[0].Equals("close"))
|
||||
{
|
||||
dev.Stop();
|
||||
dev = null;
|
||||
dclient = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче