-
-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
151 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Copyright (c) 2023 - Bart Dring | ||
// Use of this source code is governed by a GPLv3 license that can be found in the LICENSE file. | ||
|
||
/* | ||
This is a class for status "Idle,Run,Hold,Alarm" pins. | ||
This can be used for Tower lights,etc. | ||
*/ | ||
#include "Status_outputs.h" | ||
|
||
#include "Machine/MachineConfig.h" | ||
|
||
void Status_Outputs::afterParse() {} | ||
|
||
void Status_Outputs::init() { | ||
if (_error) { | ||
return; | ||
} | ||
|
||
if (_Idle_pin.defined()) { | ||
_Idle_pin.setAttr(Pin::Attr::Output); | ||
} | ||
|
||
if (_Run_pin.defined()) { | ||
_Run_pin.setAttr(Pin::Attr::Output); | ||
} | ||
|
||
if (_Hold_pin.defined()) { | ||
_Hold_pin.setAttr(Pin::Attr::Output); | ||
} | ||
|
||
if (_Alarm_pin.defined()) { | ||
_Alarm_pin.setAttr(Pin::Attr::Output); | ||
} | ||
|
||
log_info("Status outputs: " | ||
<< " Idle:" << _Idle_pin.name() << " Cycle:" << _Run_pin.name() << " Hold:" << _Hold_pin.name() | ||
<< " Alarm:" << _Alarm_pin.name()); | ||
|
||
allChannels.registration(this); | ||
setReportInterval(500); | ||
} | ||
|
||
void Status_Outputs::parse_report() { | ||
if (_report.rfind("<", 0) == 0) { | ||
parse_status_report(); | ||
return; | ||
} | ||
} | ||
|
||
// This is how the OLED driver receives channel data | ||
size_t Status_Outputs::write(uint8_t data) { | ||
char c = data; | ||
if (c == '\r') { | ||
return 1; | ||
} | ||
if (c == '\n') { | ||
parse_report(); | ||
_report = ""; | ||
return 1; | ||
} | ||
_report += c; | ||
return 1; | ||
} | ||
|
||
Channel* Status_Outputs::pollLine(char* line) { | ||
autoReport(); | ||
return nullptr; | ||
} | ||
|
||
void Status_Outputs::parse_status_report() { | ||
if (_report.back() == '>') { | ||
_report.pop_back(); | ||
} | ||
// Now the string is a sequence of field|field|field | ||
size_t pos = 0; | ||
auto nextpos = _report.find_first_of("|", pos); | ||
_state = _report.substr(pos + 1, nextpos - pos - 1); | ||
|
||
log_info("State:" << _state); | ||
|
||
_Idle_pin.write(_state == "Idle"); | ||
_Run_pin.write(_state == "Run"); | ||
_Hold_pin.write(_state.substr(0, 4) == "Hold"); | ||
_Alarm_pin.write(_state == "Alarm"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#pragma once | ||
|
||
#include "Config.h" | ||
|
||
#include "Configuration/Configurable.h" | ||
|
||
#include "Channel.h" | ||
|
||
typedef const uint8_t* font_t; | ||
|
||
class Status_Outputs : public Channel, public Configuration::Configurable { | ||
Pin _Idle_pin; | ||
Pin _Run_pin; | ||
Pin _Hold_pin; | ||
Pin _Alarm_pin; | ||
|
||
public: | ||
private: | ||
std::string _report; | ||
std::string _state; | ||
|
||
void parse_report(); | ||
void parse_status_report(); | ||
|
||
bool _error = false; | ||
|
||
public: | ||
Status_Outputs() : Channel("status_outputs") {} | ||
|
||
Status_Outputs(const Status_Outputs&) = delete; | ||
Status_Outputs(Status_Outputs&&) = delete; | ||
Status_Outputs& operator=(const Status_Outputs&) = delete; | ||
Status_Outputs& operator=(Status_Outputs&&) = delete; | ||
|
||
virtual ~Status_Outputs() = default; | ||
|
||
void init(); | ||
|
||
size_t write(uint8_t data) override; | ||
|
||
Channel* pollLine(char* line) override; | ||
void flushRx() override {} | ||
|
||
bool lineComplete(char*, char) override { return false; } | ||
size_t timedReadBytes(char* buffer, size_t length, TickType_t timeout) override { return 0; } | ||
|
||
// Configuration handlers: | ||
void validate() override {} | ||
|
||
void afterParse() override; | ||
|
||
void group(Configuration::HandlerBase& handler) override { | ||
handler.item("idle_pin", _Idle_pin); | ||
handler.item("run_pin", _Run_pin); | ||
handler.item("hold_pin", _Hold_pin); | ||
handler.item("alarm_pin", _Alarm_pin); | ||
} | ||
}; |