Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 108 additions & 0 deletions .github/agents/nanoframework.agent.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
---
name: .NET nanoFramework Agent
description: Agent instructions for generating, reviewing, and modifying C# code for .NET nanoFramework samples on constrained embedded devices.
tools:
- search/codebase
- search
- web/fetch
- web/githubRepo
- read/readFile
- search/fileSearch
- search/textSearch
- search/listDirectory
- edit/createDirectory
- edit/createFile
- edit/editFiles
- execute/runInTerminal
---

# Copilot Instructions for .NET nanoFramework

This repository targets **.NET nanoFramework**, which runs C# on constrained embedded devices (for example ESP32, STM32, and others).

When generating, reviewing, or modifying code in this repo, follow these rules:

## 1 - Validate API availability first

- Do **not** assume an API exists just because it is available in desktop/main .NET.
- Always verify availability in the nanoFramework API browser:
- https://docs.nanoframework.net/api/index.html
- If an API is not available, propose a nanoFramework-compatible alternative.

## 2 - Prefer patterns already used in this repository

- Use existing samples in this repo as the primary source for implementation patterns, coding style, and project structure.
- Before introducing a new approach, check if an equivalent pattern already exists in:
- https://github.com/nanoframework/samples
- Keep solutions simple and aligned with embedded constraints (memory, CPU, storage, networking reliability).

## 3 - Account for nanoFramework differences from main .NET

- Assume APIs are simplified even when naming aligns with main .NET.
- Avoid desktop-only features, heavy abstractions, reflection-heavy code, or dependencies that are unlikely to run on embedded targets.
- Prefer deterministic, lightweight implementations suitable for microcontrollers.
- Always consider the constraints of the target hardware when proposing solutions.
- Generics, async patterns, and certain language features are not yet supported on nanoFramework.

## 4 - Use device bindings when applicable

- nanoFramework supports many IoT device bindings.
- For hardware-specific code, check existing bindings and guidance first:
- https://docs.nanoframework.net/devicesdetails/README.html
- Reuse existing bindings and samples rather than creating custom low-level implementations when a supported binding exists.

## 5 - Practical coding expectations

- Keep allocations and background work minimal.
- Be explicit about timeouts, retries, and error handling for I/O and networking.
- Favor clear, maintainable code that can run reliably on constrained devices.
- When in doubt, choose the simpler implementation.

## 6 - If uncertain, state assumptions

- Explicitly mention when a proposal depends on API availability or board-specific capabilities.
- Add concise notes about what should be verified on target hardware.

## 7 - Build and solution validation workflow

- Always include a build step when changes affect code, project files, or package references.
- Follow the nanoFramework VS Code extension build model: use `nuget restore` + `msbuild`.
- Build scope selection:
- If a matching `*.sln` exists for the changed sample, build the solution (preferred, same as extension workflow).
- If no solution exists, build the target `*.nfproj` directly.
- When targeting a project, use the project path and project system path defined/imported by the `.nfproj`.
- Preferred command sequence (PowerShell):
- `nuget restore <path-to-solution-or-project>`
- `msbuild <path-to-solution-or-project> /p:platform="Any CPU" /p:Configuration=Release /verbosity:minimal`
- If `msbuild` is not on `PATH`, resolve it first (for example with `vswhere` on Windows), then run the same restore/build steps.
- Windows example to resolve `MSBuild.exe` with `vswhere` and build:
- `$msbuild = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -products * -latest -prerelease -requires Microsoft.Component.MSBuild -find "MSBuild\**\Bin\amd64\MSBuild.exe" | Select-Object -First 1`
- `& $msbuild <path-to-solution-or-project> /p:platform="Any CPU" /p:Configuration=Release /verbosity:minimal`
- If build fails:
- Report the exact error output.
- Propose a minimal fix.
- Re-run the same `nuget restore` + `msbuild` sequence after the fix.
- In final results, summarize:
- Which solution/project was built.
- Whether `nuget restore` + `msbuild` succeeded.
- Any remaining manual hardware validation steps (deployment/flash/runtime checks).

## 8 - Testing workflow for nanoFramework

- Do not default to `dotnet test` for nanoFramework projects.
- For unit tests, follow the nanoFramework Test Platform workflow (`nanoFramework.TestFramework`, `nanoFramework.UnitTestLauncher`, `nanoFramework.TestAdapter`).
- Identify unit test projects by checking `.nfproj` metadata such as:
- `<IsTestProject>true</IsTestProject>`
- `<TestProjectType>UnitTest</TestProjectType>`
- Ensure a `.runsettings` file exists (often `nano.runsettings`) and includes nanoFramework adapter settings.
- Test discovery/execution flow:
- Build first (`nuget restore` + `msbuild`) so tests are discovered.
- Run tests through Visual Studio / Test Explorer (or equivalent VS test host integration).
- For hardware execution, set `<IsRealHardware>True</IsRealHardware>` in `.runsettings`.
- Pipeline/automation flow:
- Use `vstest.Console.exe` with `nanoFramework.TestAdapter.dll`.
- Keep test adapter and test framework package versions aligned.
- When reporting test outcomes, include:
- Which test project and runsettings file were used.
- Whether tests ran on emulator/simulated mode or real hardware.
- Pass/fail/skip summary and any device-specific constraints.
30 changes: 30 additions & 0 deletions devices/Ltr553AlsWa/AlsGain.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Iot.Device.Ltr553AlsWa
{
/// <summary>
/// ALS gain setting for the LTR-553ALS-WA.
/// Controls the sensitivity of the ambient light sensor.
/// </summary>
public enum AlsGain : byte
{
/// <summary>1X gain (default).</summary>
Gain1X = 0x00,

/// <summary>2X gain.</summary>
Gain2X = 0x01,

/// <summary>4X gain.</summary>
Gain4X = 0x02,

/// <summary>8X gain.</summary>
Gain8X = 0x03,

/// <summary>48X gain.</summary>
Gain48X = 0x06,

/// <summary>96X gain.</summary>
Gain96X = 0x07,
}
}
36 changes: 36 additions & 0 deletions devices/Ltr553AlsWa/AlsIntegrationTime.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Iot.Device.Ltr553AlsWa
{
/// <summary>
/// ALS integration time setting for the LTR-553ALS-WA.
/// Longer integration times give higher resolution but slower updates.
/// </summary>
public enum AlsIntegrationTime : byte
{
/// <summary>50 ms integration time.</summary>
Integration50Ms = 0x01,

/// <summary>100 ms integration time (default).</summary>
Integration100Ms = 0x00,

/// <summary>150 ms integration time.</summary>
Integration150Ms = 0x04,

/// <summary>200 ms integration time.</summary>
Integration200Ms = 0x02,

/// <summary>250 ms integration time.</summary>
Integration250Ms = 0x05,

/// <summary>300 ms integration time.</summary>
Integration300Ms = 0x06,

/// <summary>350 ms integration time.</summary>
Integration350Ms = 0x07,

/// <summary>400 ms integration time.</summary>
Integration400Ms = 0x03,
}
}
30 changes: 30 additions & 0 deletions devices/Ltr553AlsWa/AlsMeasurementRate.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Iot.Device.Ltr553AlsWa
{
/// <summary>
/// ALS measurement rate setting for the LTR-553ALS-WA.
/// Must be equal to or larger than the integration time.
/// </summary>
public enum AlsMeasurementRate : byte
{
/// <summary>50 ms measurement rate.</summary>
Rate50Ms = 0x00,

/// <summary>100 ms measurement rate.</summary>
Rate100Ms = 0x01,

/// <summary>200 ms measurement rate.</summary>
Rate200Ms = 0x02,

/// <summary>500 ms measurement rate (default).</summary>
Rate500Ms = 0x03,

/// <summary>1000 ms measurement rate.</summary>
Rate1000Ms = 0x04,

/// <summary>2000 ms measurement rate.</summary>
Rate2000Ms = 0x05,
}
}
23 changes: 23 additions & 0 deletions devices/Ltr553AlsWa/InterruptMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Iot.Device.Ltr553AlsWa
{
/// <summary>
/// Interrupt mode setting for the LTR-553ALS-WA.
/// </summary>
public enum InterruptMode : byte
{
/// <summary>Interrupt pin inactive (default).</summary>
Inactive = 0x00,

/// <summary>Only proximity sensor triggers interrupt.</summary>
PsOnly = 0x01,

/// <summary>Only ambient light sensor triggers interrupt.</summary>
AlsOnly = 0x02,

/// <summary>Both PS and ALS can trigger interrupt.</summary>
Both = 0x03,
}
}
17 changes: 17 additions & 0 deletions devices/Ltr553AlsWa/InterruptPolarity.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Iot.Device.Ltr553AlsWa
{
/// <summary>
/// Interrupt polarity setting for the LTR-553ALS-WA.
/// </summary>
public enum InterruptPolarity : byte
{
/// <summary>Active low (default). INT pin requires pull-up resistor.</summary>
ActiveLow = 0x00,

/// <summary>Active high. INT pin requires pull-down resistor.</summary>
ActiveHigh = 0x01,
}
}
23 changes: 23 additions & 0 deletions devices/Ltr553AlsWa/LedDutyCycle.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Iot.Device.Ltr553AlsWa
{
/// <summary>
/// PS LED duty cycle setting for the LTR-553ALS-WA.
/// </summary>
public enum LedDutyCycle : byte
{
/// <summary>25% duty cycle.</summary>
DutyCycle25Percent = 0x00,

/// <summary>50% duty cycle.</summary>
DutyCycle50Percent = 0x01,

/// <summary>75% duty cycle.</summary>
DutyCycle75Percent = 0x02,

/// <summary>100% duty cycle (default).</summary>
DutyCycle100Percent = 0x03,
}
}
26 changes: 26 additions & 0 deletions devices/Ltr553AlsWa/LedPeakCurrent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Iot.Device.Ltr553AlsWa
{
/// <summary>
/// PS LED peak current setting for the LTR-553ALS-WA.
/// </summary>
public enum LedPeakCurrent : byte
{
/// <summary>5 mA peak current.</summary>
Current5mA = 0x00,

/// <summary>10 mA peak current.</summary>
Current10mA = 0x01,

/// <summary>20 mA peak current.</summary>
Current20mA = 0x02,

/// <summary>50 mA peak current.</summary>
Current50mA = 0x03,

/// <summary>100 mA peak current (default).</summary>
Current100mA = 0x04,
}
}
35 changes: 35 additions & 0 deletions devices/Ltr553AlsWa/LedPulseFrequency.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Iot.Device.Ltr553AlsWa
{
/// <summary>
/// PS LED pulse frequency setting for the LTR-553ALS-WA.
/// </summary>
public enum LedPulseFrequency : byte
{
/// <summary>30 kHz pulse frequency.</summary>
Frequency30kHz = 0x00,

/// <summary>40 kHz pulse frequency.</summary>
Frequency40kHz = 0x01,

/// <summary>50 kHz pulse frequency.</summary>
Frequency50kHz = 0x02,

/// <summary>60 kHz pulse frequency (default).</summary>
Frequency60kHz = 0x03,

/// <summary>70 kHz pulse frequency.</summary>
Frequency70kHz = 0x04,

/// <summary>80 kHz pulse frequency.</summary>
Frequency80kHz = 0x05,

/// <summary>90 kHz pulse frequency.</summary>
Frequency90kHz = 0x06,

/// <summary>100 kHz pulse frequency.</summary>
Frequency100kHz = 0x07,
}
}
Loading
Loading