{"id":25950170,"url":"https://github.com/byronap/pcgpio","last_synced_at":"2025-03-04T12:53:05.700Z","repository":{"id":279647204,"uuid":"939486310","full_name":"ByronAP/PCGPIO","owner":"ByronAP","description":"Add GPIO to a PC using a microcontroller","archived":false,"fork":false,"pushed_at":"2025-02-26T16:22:35.000Z","size":45,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-26T17:28:24.978Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ByronAP.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-02-26T16:07:22.000Z","updated_at":"2025-02-26T16:24:20.000Z","dependencies_parsed_at":"2025-02-26T17:28:58.657Z","dependency_job_id":"6dfa9be5-e489-429d-b693-216fc1156bd1","html_url":"https://github.com/ByronAP/PCGPIO","commit_stats":null,"previous_names":["byronap/pcgpio"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByronAP%2FPCGPIO","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByronAP%2FPCGPIO/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByronAP%2FPCGPIO/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ByronAP%2FPCGPIO/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ByronAP","download_url":"https://codeload.github.com/ByronAP/PCGPIO/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241852139,"owners_count":20030969,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-04T12:53:04.925Z","updated_at":"2025-03-04T12:53:05.680Z","avatar_url":"https://github.com/ByronAP.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PCGPIO\n\n**A powerful and versatile solution for adding GPIO to a PC by controlling microcontroller-based hardware controllers like Arduino AVR, ESP32, STM32, and Teensy via serial communication.**\n\nPCGPIO simplifies interaction with your hardware, offering a robust and intuitive interface for hobbyists and professionals alike. Whether you're building a custom project or developing industrial automation solutions, PCGPIO empowers you to:\n\n*   Read and write digital and analog pins with ease\n*   Configure pin modes (input, output, input pullup) for flexible hardware control\n*   Attach and detach interrupts to handle real-time events\n*   Control PWM output for precise analog-like functionality\n*   Manage timers for scheduled or periodic tasks\n*   Perform efficient bulk read and write operations on multiple pins\n\nBuilt with asynchronous operations, PCGPIO ensures your applications remain responsive and efficient. It also features auto-detection of serial ports, robust error handling, and advanced configuration options for power users.\n\n## Features\n\n*   **Asynchronous Operations:** All interactions with the controller are asynchronous, enabling concurrent task handling without blocking your application.\n*   **Auto-Detection:** Automatically detects the serial port connected to your PCGPIO controller, streamlining setup.\n*   **Error Handling:** Custom exceptions (`PCGPIOConnectionException` and `PCGPIOCommandException`) deliver clear, actionable error messages.\n*   **Advanced Serial Configuration:** Customize baud rate, parity, stop bits, and data bits to match your hardware needs.\n*   **Interrupt Support:** Attach interrupt handlers to pins with trigger modes (rising, falling, change) for real-time responsiveness.\n*   **Timer Functionality:** Start and stop timers with microsecond precision for accurate timing control.\n*   **Bulk Operations:** Read and write multiple digital pins in a single command, optimizing performance.\n*   **Raw Command Support:** Send custom commands directly to the controller for advanced or proprietary operations.\n\n## Contributing\n\nWe welcome contributions! Please submit issues and pull requests to help improve PCGPIO.\n\n## License\n\nThis project is licensed under the GNU General Public License version 3 (GPLv3). See the [LICENSE](https://www.gnu.org/licenses/gpl-3.0.en.html) file for details.\n- - -\n# Library Usage\n## Table of Contents\n\n*   [API Documentation](#api-documentation)\n    *   [Connection Management](#connection-management)\n    *   [Pin Control](#pin-control)\n    *   [Interrupts](#interrupts)\n    *   [Timers](#timers)\n    *   [Bulk Operations](#bulk-operations)\n    *   [Advanced Features](#advanced-features)\n    *   [Stepper Motor Control](#stepper-motor-control)\n    *   [LED Strip Control](#led-strip-control)\n*   [Examples](#examples)\n\n## API Documentation\n\nThis section covers all public methods in the PCGPIO library, grouped by functionality. Each method includes its signature, description, parameters, return type, and possible exceptions.\n\n### Connection Management\n\n*   #### `public PCGPIO(string? portName = null)`\n    \n    Initializes a new instance of the PCGPIO class.\n    \n    **Parameters:**\n    \n    *   `portName` (string?, optional): The serial port name (e.g., \"COM3\"). If null, auto-detects the port.\n    \n    **Returns:** None (constructor)\n    \n    **Exceptions:** None\n    \n*   #### `public Task ConnectAsync(bool autoNegotiatePortSpeed = true)`\n    \n    Establishes a serial connection to the controller.\n    \n    **Parameters:**\n    \n    *   `autoNegotiatePortSpeed` (bool, optional): If true, negotiates the optimal baud rate (default: true).\n    \n    **Returns:** `Task`\n    \n    **Exceptions:**\n    \n    *   `PCGPIOConnectionException`: Thrown if the connection fails.\n*   #### `public void Disconnect()`\n    \n    Closes the serial connection.\n    \n    **Parameters:** None\n    \n    **Returns:** None\n    \n    **Exceptions:** None\n    \n*   #### `public Task ResetControllerAsync()`\n    \n    Resets the controller via a software or hardware command.\n    \n    **Parameters:** None\n    \n    **Returns:** `Task`\n    \n    **Exceptions:**\n    \n    *   `PCGPIOConnectionException`: Thrown if not connected.\n\n### Pin Control\n\n*   #### `public Task ReadDigitalPinAsync(int pin)`\n    \n    Reads the state of a digital pin.\n    \n    **Parameters:**\n    \n    *   `pin` (int): The pin number.\n    \n    **Returns:** `bool` (true = HIGH, false = LOW)\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If pin number is invalid.\n    *   `PCGPIOCommandException`: If the command fails.\n*   #### `public Task WriteDigitalPinAsync(int pin, bool value)`\n    \n    Writes a value to a digital pin.\n    \n    **Parameters:**\n    \n    *   `pin` (int): The pin number.\n    *   `value` (bool): The value to write (true = HIGH, false = LOW).\n    \n    **Returns:** `Task`\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If pin number is invalid.\n*   #### `public Task SetPinModeAsync(int pin, PinMode mode)`\n    \n    Sets the mode of a pin (e.g., Input, Output).\n    \n    **Parameters:**\n    \n    *   `pin` (int): The pin number.\n    *   `mode` (PinMode): The pin mode (e.g., `PinMode.Input`, `PinMode.Output`).\n    \n    **Returns:** `Task`\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If pin or mode is invalid.\n*   #### `public Task ReadAnalogPinAsync(int analogPin)`\n    \n    Reads the value of an analog pin.\n    \n    **Parameters:**\n    \n    *   `analogPin` (int): The analog pin number.\n    \n    **Returns:** `int` (typically 0-1023)\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If pin number is invalid.\n    *   `PCGPIOCommandException`: If the command fails.\n*   #### `public Task WritePwmAsync(int pin, int value)`\n    \n    Sets the PWM duty cycle on a pin.\n    \n    **Parameters:**\n    \n    *   `pin` (int): The PWM-capable pin number.\n    *   `value` (int): Duty cycle (0-255).\n    \n    **Returns:** `Task`\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If pin or value is invalid.\n\n### Interrupts\n\n*   #### `public Task AttachInterruptAsync(int pin, InterruptMode mode, Action callback)`\n    \n    Attaches an interrupt handler to a pin.\n    \n    **Parameters:**\n    \n    *   `pin` (int): The pin number.\n    *   `mode` (InterruptMode): Trigger mode (e.g., `Rising`, `Falling`, `Change`).\n    *   `callback` (Action): The method to call when the interrupt occurs.\n    \n    **Returns:** `Task`\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If pin or mode is invalid.\n*   #### `public Task DetachInterruptAsync(int pin)`\n    \n    Detaches an interrupt from a pin.\n    \n    **Parameters:**\n    \n    *   `pin` (int): The pin number.\n    \n    **Returns:** `Task`\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If pin is invalid.\n\n### Timers\n\n*   #### `public Task StartTimerAsync(int timerId, uint microseconds, Action callback)`\n    \n    Starts a timer with microsecond precision.\n    \n    **Parameters:**\n    \n    *   `timerId` (int): The timer identifier.\n    *   `microseconds` (uint): Interval in microseconds.\n    *   `callback` (Action): The method to call when the timer triggers.\n    \n    **Returns:** `Task`\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If timerId or microseconds is invalid.\n*   #### `public Task StopTimerAsync(int timerId)`\n    \n    Stops a running timer.\n    \n    **Parameters:**\n    \n    *   `timerId` (int): The timer identifier.\n    \n    **Returns:** `Task`\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If timerId is invalid.\n\n### Bulk Operations\n\n*   #### `public Task ReadDigitalPinsAsync(int[] pins)`\n    \n    Reads the states of multiple digital pins in one command.\n    \n    **Parameters:**\n    \n    *   `pins` (int\\[\\]): Array of pin numbers.\n    \n    **Returns:** `bool[]` (array of pin states)\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If any pin is invalid.\n    *   `PCGPIOCommandException`: If the command fails.\n*   #### `public Task WriteDigitalPinsAsync(Dictionary pinValues)`\n    \n    Writes values to multiple digital pins in one command.\n    \n    **Parameters:**\n    \n    *   `pinValues` (Dictionary): Pin numbers and their values.\n    \n    **Returns:** `Task`\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If any pin is invalid.\n\n### Advanced Features\n\n*   #### `public Task SendRawCommandAsync(string command)`\n    \n    Sends a raw command to the controller and returns its response.\n    \n    **Parameters:**\n    \n    *   `command` (string): The raw command string.\n    \n    **Returns:** `string` (controller’s response)\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If command is null or empty.\n    *   `PCGPIOCommandException`: If the command fails.\n*   #### `public Task SetSerialConfigAsync(int baudRate, Parity parity, int dataBits, StopBits stopBits)`\n    \n    Configures serial communication settings.\n    \n    **Parameters:**\n    \n    *   `baudRate` (int): Baud rate (e.g., 9600, 115200).\n    *   `parity` (Parity): Parity setting (e.g., `Parity.None`).\n    *   `dataBits` (int): Number of data bits (e.g., 8).\n    *   `stopBits` (StopBits): Stop bits (e.g., `StopBits.One`).\n    \n    **Returns:** `Task`\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If parameters are invalid.\n\n### Stepper Motor Control\n\n*   #### `public Task StepMotorAsync(int motorId, int steps, bool direction)`\n    \n    Controls a stepper motor connected to the controller.\n    \n    **Parameters:**\n    \n    *   `motorId` (int): The motor identifier.\n    *   `steps` (int): Number of steps to move.\n    *   `direction` (bool): true = clockwise, false = counterclockwise.\n    \n    **Returns:** `Task`\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If motorId or steps is invalid.\n*   #### `public Task SetMotorSpeedAsync(int motorId, int speed)`\n    \n    Sets the speed of a stepper motor.\n    \n    **Parameters:**\n    \n    *   `motorId` (int): The motor identifier.\n    *   `speed` (int): Speed in steps per second.\n    \n    **Returns:** `Task`\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If motorId or speed is invalid.\n\n### LED Strip Control\n\n*   #### `public Task SetLedColorAsync(int ledIndex, byte r, byte g, byte b)`\n    \n    Sets the color of an LED in a strip (e.g., WS2812).\n    \n    **Parameters:**\n    \n    *   `ledIndex` (int): The LED index in the strip.\n    *   `r` (byte): Red value (0-255).\n    *   `g` (byte): Green value (0-255).\n    *   `b` (byte): Blue value (0-255).\n    \n    **Returns:** `Task`\n    \n    **Exceptions:**\n    \n    *   `ArgumentException`: If ledIndex is invalid.\n*   #### `public Task UpdateLedStripAsync()`\n    \n    Updates the LED strip with the set colors.\n    \n    **Parameters:** None\n    \n    **Returns:** `Task`\n    \n    **Exceptions:** None\n    \n\n## Examples\n\n### Blinking an LED\n\n```\nusing PCGPIOLib;\n\nPCGPIO gpio = new PCGPIO();\nawait gpio.ConnectAsync();\nawait gpio.SetPinModeAsync(13, PinMode.Output);\n\nwhile (true)\n{\n    await gpio.WriteDigitalPinAsync(13, true);  // LED on\n    await Task.Delay(1000);\n    await gpio.WriteDigitalPinAsync(13, false); // LED off\n    await Task.Delay(1000);\n}\n```\n\n### Using an Interrupt\n\n```\nusing PCGPIOLib;\n\nPCGPIO gpio = new PCGPIO();\nawait gpio.ConnectAsync();\n\nawait gpio.SetPinModeAsync(2, PinMode.Input);\nawait gpio.AttachInterruptAsync(2, InterruptMode.Rising, () =\u003e\n{\n    Console.WriteLine(\"Button pressed!\");\n});\n```\n\n© 2025 ByronAP. All rights reserved.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyronap%2Fpcgpio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbyronap%2Fpcgpio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbyronap%2Fpcgpio/lists"}