Skip to content

Conversation

@222448082Ashen
Copy link

Description

This PR adds comprehensive C# language support (both Top-level Statements and Object-Oriented Programming styles) to the "Modify PWM through button presses" Raspberry Pi GPIO tutorial. The tutorial previously only included C++ examples, and this update ensures consistency with other SplashKit tutorials by providing complete C# implementations.

Related Documentation: This implements the requirements from the Tutorial Style Guide to include both C# coding styles in all tutorials.

Context: The SplashKit documentation aims to support multiple programming languages, with C# being a primary language alongside C++. This tutorial demonstrates advanced GPIO concepts including PWM control, button debouncing, and timer management, making it crucial for C# developers learning hardware programming.

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Documentation (update or new)

Changes Made

Modified Files:

  1. src/content/docs/guides/raspberry-gpio/3-pwm-button-control.mdx

    • Added C# Top-level Statements version to all code blocks (7 total)
    • Added C# Object-Oriented version to all code blocks (7 total)
    • Implemented nested tab structure with syncKey="csharp-style"
    • Maintained all existing C++ code unchanged
  2. scripts/json-files/guides/Raspberry-GPIO/raspberry-gpio.json

    • Removed unused function raspi_set_pwm_frequency from tutorial entry
    • Verified all 15 listed functions are actually used in the tutorial

Auto-Regenerated Files:

  • scripts/json-files/guides.json - Updated with corrected function list
  • src/content/docs/api/*.mdx - All 21 API documentation pages regenerated with tutorial links

How Has This Been Tested?

Code Validation

  1. Created standalone test files for both C# versions
  2. Verified both versions compile without syntax errors
  3. Confirmed proper IntelliSense support in VS Code

Site Build Testing

  1. Ran npm run setup successfully
    • All JSON files generated successfully
    • All 21 API MDX files regenerated without errors
  2. Verified tutorial appears in API documentation:
    • Raspberry GPIO functions (6 occurrences)
    • Timer functions (5 occurrences)
    • Window functions (2 occurrences)

Code Review

  1. Variable naming follows C# conventions (camelCase for local variables, PascalCase for functions)
  2. Comments match exactly across all language versions
  3. Proper use of SplashKit namespaces and type conversions
  4. Nested tab structure follows official style guide

Code Examples

C# Top-level Statements Version

using static SplashKitSDK.SplashKit;

int brightness = 128;
const int maxBrightness = 255;
ulong lastReadTime = 0;
const ulong readInterval = 400;

RaspiInit();
Pins ledPin = Pins.Pin11;
// ... direct function calls without SplashKit prefix

C# Object-Oriented Version

using SplashKitSDK;

namespace PwmButtonControlExample
{
    public class Program
    {
        public static void Main()
        {
            int brightness = 128;
            const int maxBrightness = 255;
            // ... all functions prefixed with SplashKit.
            SplashKit.RaspiInit();
        }
    }
}

Variable & Type Conversions

C++ C#
brightness brightness
max_brightness maxBrightness
last_read_time lastReadTime
read_interval readInterval
led_pin ledPin
increase_btn_pin increaseBtnPin
decrease_btn_pin decreaseBtnPin
run_timer runTimer
current_time currentTime
unsigned long ulong
gpio_pin Pins
timer Timer
GPIO_OUTPUT PinModes.GpioOutput
GPIO_INPUT PinModes.GpioInput
GPIO_HIGH PinValues.GpioHigh
PUD_DOWN PullUpDown.PudDown

Checklist

Code Quality

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings

Testing

  • Tested in latest Chrome
  • Tested in latest Firefox
  • npm run setup (successful)
  • npm run preview

Configuration Files

  • No changes to package.json
  • No changes to astro.config.mjs
  • No changes to netlify.toml
  • No changes to docker-compose.yml
  • No changes to custom.css

Additional Notes

Why This Matters

This tutorial is particularly important because it:

  1. Demonstrates advanced GPIO programming concepts (PWM, debouncing, timers)
  2. Shows integration between hardware control and software timing
  3. Serves as a foundation for more complex Raspberry Pi projects
  4. Provides beginner-friendly examples for C# developers entering embedded programming

Compliance

  • Follows Tutorial Style Guide
  • Follows Tutorial JSON File documentation
  • Uses proper SplashKit naming conventions
  • Maintains consistency with existing tutorials
  • Comments synchronized across all language versions

Breaking Changes

None. This is a pure addition of C# code examples to an existing tutorial. All existing C++ code remains unchanged, and the tutorial structure is preserved.

Future Work

  • Physical Raspberry Pi hardware testing recommended
  • Screenshots of both C# versions running on hardware would enhance documentation
  • Verification that both styles produce identical LED behavior

Added C# code samples (both top-level statements and object-oriented styles) to the Raspberry Pi PWM button control guide. Also removed 'raspi_set_pwm_frequency' from the guides.json and raspberry-gpio.json lists to reflect updated content.
@netlify
Copy link

netlify bot commented Dec 13, 2025

Deploy Preview for splashkit failed.

Name Link
🔨 Latest commit 97794bc
🔍 Latest deploy log https://app.netlify.com/projects/splashkit/deploys/693d404ef36df400080372f5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant