Skip to content

A Hardware Hacking Tool with Web-Based CLI That Speaks Every Protocol

add methods to get configured pull pins

Geobc6b6509f9f3
diff --git a/src/Controllers/DioController.cpp b/src/Controllers/DioController.cpp
index 4eb03b5b..e405ef6c 100644
--- a/src/Controllers/DioController.cpp
+++ b/src/Controllers/DioController.cpp
@@ -471,3 +471,37 @@ bool DioController::isPinAllowed(uint8_t pin, const std::string& context) {
return true;
}
+
+std::vector<std::string> DioController::buildPullConfigLines() {
+ std::vector<std::string> lines;
+
+ auto pins = pinService.getConfiguredPullPins();
+ std::sort(pins.begin(), pins.end());
+
+ size_t total = 0;
+
+ for (uint8_t pin : pins) {
+ auto pull = pinService.getPullType(pin);
+
+ if (pull == PinService::PULL_UP) {
+ lines.push_back("GPIO " + std::to_string(pin) + " PULLUP");
+ }
+ else if (pull == PinService::PULL_DOWN) {
+ lines.push_back("GPIO " + std::to_string(pin) + " PULLDOWN");
+ } else {
+ continue;
+ }
+
+ ++total;
+
+ // Limit to 4 displayable lines
+ if (lines.size() == 4) {
+ if (pins.size() > total) {
+ lines.back() += " ...";
+ }
+ break;
+ }
+ }
+
+ return lines;
+}
diff --git a/src/Controllers/DioController.h b/src/Controllers/DioController.h
index 05a4e0ad..86631757 100644
--- a/src/Controllers/DioController.h
+++ b/src/Controllers/DioController.h
@@ -17,6 +17,9 @@ public:
// Entry point to handle a DIO command
void handleCommand(const TerminalCommand& cmd);
+ // Build GPIO and pull configuration lines
+ std::vector<std::string> buildPullConfigLines();
+
private:
ITerminalView& terminalView;
IInput& terminalInput;
diff --git a/src/Services/PinService.cpp b/src/Services/PinService.cpp
index 3af43968..60e13c89 100644
--- a/src/Services/PinService.cpp
+++ b/src/Services/PinService.cpp
@@ -121,4 +121,15 @@ bool PinService::isPwmFeasible(uint32_t freq, uint8_t resolutionBits) {
PinService::pullType PinService::getPullType(uint8_t pin){
return(pullState[pin]);
-}
\ No newline at end of file
+}
+
+std::vector<uint8_t> PinService::getConfiguredPullPins() {
+ std::vector<uint8_t> pins;
+ pins.reserve(pullState.size());
+
+ for (const auto& entry : pullState) {
+ pins.push_back(entry.first);
+ }
+
+ return pins;
+}
diff --git a/src/Services/PinService.h b/src/Services/PinService.h
index 1fec36b6..91f5daf3 100644
--- a/src/Services/PinService.h
+++ b/src/Services/PinService.h
@@ -2,6 +2,7 @@
#include <Arduino.h>
#include <unordered_map>
+#include <vector>
class PinService {
public:
@@ -19,6 +20,7 @@ public:
void setServoAngle(uint8_t pin, uint8_t angle);
typedef enum pullType { NOPULL = 0, PULL_UP, PULL_DOWN} pullType;
pullType getPullType(uint8_t pin);
+ std::vector<uint8_t> getConfiguredPullPins();
private:
bool isPwmFeasible(uint32_t freq, uint8_t resolutionBits);
std::unordered_map<uint8_t, pullType> pullState;