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
|
/*
* RemoteZProbe.cpp
*
* Created on: 14 Sep 2019
* Author: David
*/
#include "RemoteZProbe.h"
#if SUPPORT_CAN_EXPANSION
#include <CanMessageBuffer.h>
#include <CAN/CanInterface.h>
#include <CAN/CanMessageGenericConstructor.h>
#include <Platform/RepRap.h>
#include <Platform/Platform.h>
#include <GCodes/GCodeBuffer/GCodeBuffer.h>
// Members of class RemoteZProbe
RemoteZProbe::~RemoteZProbe()
{
String<StringLength100> reply;
const GCodeResult rslt = CanInterface::DeleteHandle(boardAddress, handle, reply.GetRef());
if (rslt != GCodeResult::ok)
{
reply.cat('\n');
reprap.GetPlatform().Message(GetGenericMessageType(rslt), reply.c_str());
}
}
GCodeResult RemoteZProbe::AppendPinNames(const StringRef& str) noexcept
{
String<StringLength100> reply;
const GCodeResult rslt = CanInterface::GetHandlePinName(boardAddress, handle, state, reply.GetRef());
if (rslt == GCodeResult::ok)
{
str.cat(", input pin ");
str.cat(reply.c_str());
}
else
{
str.copy(reply.c_str());
}
return rslt;
}
uint16_t RemoteZProbe::GetRawReading() const noexcept
{
return (state) ? 1000 : 0;
}
bool RemoteZProbe::SetProbing(bool isProbing) noexcept
{
String<StringLength100> reply;
const GCodeResult rslt = CanInterface::ChangeHandleResponseTime(boardAddress, handle, (isProbing) ? ActiveProbeReportInterval : InactiveProbeReportInterval, state, reply.GetRef());
if (rslt != GCodeResult::ok)
{
reply.cat('\n');
reprap.GetPlatform().Message(GetGenericMessageType(rslt), reply.c_str());
}
return rslt == GCodeResult::ok;
}
// Create a remote Z probe
GCodeResult RemoteZProbe::Create(const StringRef& pinNames, const StringRef& reply) noexcept
{
if (type != ZProbeType::unfilteredDigital && type != ZProbeType::blTouch)
{
reply.copy("M558: only Z probe types 8 and 9 are supported on expansion boards");
return GCodeResult::error;
}
if (strchr(pinNames.c_str(), '+') != nullptr)
{
reply.copy("M558: output port not supported on expansion boards");
return GCodeResult::error;
}
RemoteInputHandle h;
h.Set(RemoteInputHandle::typeZprobe, number, 0);
const GCodeResult rc = CanInterface::CreateHandle(boardAddress, h, pinNames.c_str(), 0, ActiveProbeReportInterval, state, reply);
if (rc < GCodeResult::error) // don't set the handle unless it is valid, or we will get an error when this probe is deleted
{
handle = h;
}
return rc;
}
// Configure an existing remote Z probe
GCodeResult RemoteZProbe::Configure(GCodeBuffer& gb, const StringRef &reply, bool& seen) THROWS(GCodeException)
{
if (gb.Seen('P'))
{
seen = true;
const uint32_t newType = gb.GetUIValue();
if (newType != (uint32_t)ZProbeType::unfilteredDigital && newType != (uint32_t)ZProbeType::blTouch)
{
reply.copy("M558: only Z probe types 8 and 9 are supported on expansion boards");
return GCodeResult::error;
}
type = (ZProbeType)newType;
}
// No other configuration items affect remote probes differently from others, so just call the base class function
return ZProbe::Configure(gb, reply, seen);
}
GCodeResult RemoteZProbe::SendProgram(const uint32_t zProbeProgram[], size_t len, const StringRef& reply) noexcept
{
//TODO
reply.copy("Programming remote Z probes not supported");
return GCodeResult::error;
}
void RemoteZProbe::HandleRemoteInputChange(CanAddress src, uint8_t handleMinor, bool newState) noexcept
{
if (src == boardAddress)
{
state = newState;
}
}
#endif
// End
|