Welcome to mirror list, hosted at ThFree Co, Russian Federation.

RemoteFan.cpp « Fans « src - github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d48401d9e1a7651d7aff04d5f500291881e25e10 (plain)
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
/*
 * RemoteFan.cpp
 *
 *  Created on: 3 Sep 2019
 *      Author: David
 */

#include "RemoteFan.h"

#if SUPPORT_CAN_EXPANSION

#include "CanMessageBuffer.h"
#include "CAN/CanInterface.h"
#include "CAN/CanMessageGenericConstructor.h"

RemoteFan::RemoteFan(unsigned int fanNum, CanAddress boardNum) noexcept
	: Fan(fanNum),
	  lastRpm(-1), whenLastRpmReceived(0), boardNumber(boardNum), thermostaticFanRunning(false)
{
}

RemoteFan::~RemoteFan() noexcept
{
	CanMessageGenericConstructor cons(M950FanParams);
	cons.AddUParam('F', fanNumber);
	cons.AddStringParam('C', "nil");
	String<1> dummy;
	(void)cons.SendAndGetResponse(CanMessageType::m950Fan, boardNumber, dummy.GetRef());
}

bool RemoteFan::Check() noexcept
{
	return thermostaticFanRunning;
}

bool RemoteFan::IsEnabled() const noexcept
{
	return true;
}

GCodeResult RemoteFan::SetPwmFrequency(PwmFrequency freq, const StringRef& reply) noexcept
{
	CanMessageGenericConstructor cons(M950FanParams);
	cons.AddUParam('F', fanNumber);
	cons.AddUParam('Q', freq);
	return cons.SendAndGetResponse(CanMessageType::m950Fan, boardNumber, reply);
}

void RemoteFan::UpdateRpmFromRemote(CanAddress src, int32_t rpm) noexcept
{
	if (src == boardNumber)
	{
		lastRpm = rpm;
		whenLastRpmReceived = millis();
	}
}

int32_t RemoteFan::GetRPM() noexcept
{
	if (millis() - whenLastRpmReceived > RpmReadingTimeout)
	{
		lastRpm = -1;
	}
	return lastRpm;
}

GCodeResult RemoteFan::ReportPortDetails(const StringRef& str) const noexcept
{
	CanMessageGenericConstructor cons(M950FanParams);
	cons.AddUParam('F', fanNumber);
	return cons.SendAndGetResponse(CanMessageType::m950Fan, boardNumber, str);
}

bool RemoteFan::UpdateFanConfiguration(const StringRef& reply) noexcept
{
	CanMessageBuffer *buf = CanMessageBuffer::Allocate();
	if (buf == nullptr)
	{
		reply.copy("No CAN buffer available");
		return false;
	}

	const CanRequestId rid = CanInterface::AllocateRequestId(boardNumber);
	auto msg = buf->SetupRequestMessage<CanMessageFanParameters>(rid, CanId::MasterAddress, boardNumber);
	msg->fanNumber = fanNumber;
	msg->blipTime = blipTime;
	msg->val = val;
	msg->minVal = minVal;
	msg->maxVal = maxVal;
	msg->triggerTemperatures[0] = triggerTemperatures[0];
	msg->triggerTemperatures[1] = triggerTemperatures[1];
	msg->sensorsMonitored = sensorsMonitored;

	return CanInterface::SendRequestAndGetStandardReply(buf, rid, reply) == GCodeResult::ok;
}

// Update the hardware PWM
GCodeResult RemoteFan::Refresh(const StringRef& reply) noexcept
{
	CanMessageBuffer *buf = CanMessageBuffer::Allocate();
	if (buf == nullptr)
	{
		reply.copy("No CAN buffer available");
		return GCodeResult::error;
	}

	const CanRequestId rid = CanInterface::AllocateRequestId(boardNumber);
	auto msg = buf->SetupRequestMessage<CanMessageSetFanSpeed>(rid, CanId::MasterAddress, boardNumber);
	msg->fanNumber = fanNumber;
	msg->pwm = val;
	return CanInterface::SendRequestAndGetStandardReply(buf, rid, reply);
}

GCodeResult RemoteFan::ConfigurePort(const char* pinNames, PwmFrequency freq, const StringRef& reply) noexcept
{
	CanMessageGenericConstructor cons(M950FanParams);
	cons.AddUParam('F', fanNumber);
	cons.AddUParam('Q', freq);
	cons.AddStringParam('C', pinNames);
	return cons.SendAndGetResponse(CanMessageType::m950Fan, boardNumber, reply);
}

#endif

// End