-
-
Notifications
You must be signed in to change notification settings - Fork 386
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add UserInputs and basic structure for M66 in GCode
- Loading branch information
Showing
9 changed files
with
237 additions
and
22 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
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,58 @@ | ||
// Copyright (c) 2024 - Dylan Knutson | ||
// Use of this source code is governed by a GPLv3 license that can be found in the LICENSE file. | ||
|
||
#include "UserInputs.h" | ||
|
||
namespace Machine { | ||
UserInputs::UserInputs() {} | ||
UserInputs::~UserInputs() {} | ||
|
||
void UserInputs::group(Configuration::HandlerBase& handler) { | ||
char item_name[64]; | ||
for (size_t i = 0; i < MaxUserAnalogPin; i++) { | ||
snprintf(item_name, sizeof(item_name), "analog%d_pin", i); | ||
handler.item(item_name, _analogInput[i]); | ||
} | ||
for (size_t i = 0; i < MaxUserDigitalPin; i++) { | ||
snprintf(item_name, sizeof(item_name), "digital%d_pin", i); | ||
handler.item(item_name, _digitalInput[i]); | ||
} | ||
} | ||
|
||
void UserInputs::init() { | ||
for (auto& input : _digitalInput) { | ||
if (input.defined()) { | ||
input.setAttr(Pin::Attr::Input); | ||
} | ||
} | ||
for (auto& input : _analogInput) { | ||
if (input.defined()) { | ||
input.setAttr(Pin::Attr::Input); | ||
} | ||
} | ||
} | ||
|
||
UserInputs::ReadInputResult UserInputs::readDigitalInput(uint8_t input_number) { | ||
if (input_number >= MaxUserDigitalPin) { | ||
return Error::PParamMaxExceeded; | ||
} | ||
auto& pin = _digitalInput[input_number]; | ||
if (!pin.defined()) { | ||
return Error::InvalidValue; | ||
} | ||
return pin.read(); | ||
} | ||
|
||
UserInputs::ReadInputResult UserInputs::readAnalogInput(uint8_t input_number) { | ||
// TODO - analog pins are read the same as digital. | ||
if (input_number >= MaxUserAnalogPin) { | ||
return Error::PParamMaxExceeded; | ||
} | ||
auto& pin = _analogInput[input_number]; | ||
if (!pin.defined()) { | ||
return Error::InvalidValue; | ||
} | ||
return pin.read(); | ||
} | ||
|
||
} // namespace Machine |
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,34 @@ | ||
// Copyright (c) 2024 - Dylan Knutson | ||
// Use of this source code is governed by a GPLv3 license that can be found in the LICENSE file. | ||
|
||
#pragma once | ||
|
||
#include "../Configuration/Configurable.h" | ||
#include "../GCode.h" | ||
|
||
#include <variant> | ||
#include <array> | ||
|
||
namespace Machine { | ||
|
||
class UserInputs : public Configuration::Configurable { | ||
std::array<Pin, MaxUserDigitalPin> _digitalInput; | ||
|
||
// TODO - analog pins are read the same as digital. The Pin | ||
// API should either be extended to support analog reads, or | ||
// a new AnalogPin class should be created. | ||
std::array<Pin, MaxUserAnalogPin> _analogInput; | ||
|
||
public: | ||
UserInputs(); | ||
virtual ~UserInputs(); | ||
|
||
void init(); | ||
void group(Configuration::HandlerBase& handler) override; | ||
|
||
using ReadInputResult = std::variant<bool, Error>; | ||
ReadInputResult readDigitalInput(uint8_t input_number); | ||
ReadInputResult readAnalogInput(uint8_t input_number); | ||
}; | ||
|
||
} // namespace Machine |
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