Skip to content

Commit

Permalink
Merge pull request #63 from glopesdev/interface-gen
Browse files Browse the repository at this point in the history
Embed device metadata as part of interface project
  • Loading branch information
glopesdev authored Nov 6, 2024
2 parents c92023c + 2b87c1b commit 8159545
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
35 changes: 35 additions & 0 deletions interface/Device.tt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,41 @@ foreach (var register in deviceRegisters)
}
#>
};

/// <summary>
/// Gets the contents of the metadata file describing the <see cref="<#= deviceName #>"/>
/// device registers.
/// </summary>
public static readonly string Metadata = GetDeviceMetadata();

static string GetDeviceMetadata()
{
var deviceType = typeof(Device);
using var metadataStream = deviceType.Assembly.GetManifestResourceStream($"{deviceType.Namespace}.device.yml");
using var streamReader = new System.IO.StreamReader(metadataStream);
return streamReader.ReadToEnd();
}
}

/// <summary>
/// Represents an operator that returns the contents of the metadata file
/// describing the <see cref="<#= deviceName #>"/> device registers.
/// </summary>
[Description("Returns the contents of the metadata file describing the <#= deviceName #> device registers.")]
public partial class GetMetadata : Source<string>
{
/// <summary>
/// Returns an observable sequence with the contents of the metadata file
/// describing the <see cref="<#= deviceName #>"/> device registers.
/// </summary>
/// <returns>
/// A sequence with a single <see cref="string"/> object representing the
/// contents of the metadata file.
/// </returns>
public override IObservable<string> Generate()
{
return Observable.Return(Device.Metadata);
}
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion interface/Harp.Generators.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<VersionPrefix>0.2.0</VersionPrefix>
<VersionPrefix>0.3.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<PackageId>Harp.Generators</PackageId>
<Title>Harp Generators</Title>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<FirmwarePath>..\Firmware\$projectname$</FirmwarePath>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Harp.Generators" Version="0.1.0" GeneratePathProperty="true" />
<PackageReference Include="Harp.Generators" Version="0.3.0" GeneratePathProperty="true" />
</ItemGroup>
<Target Name="TextTransform" BeforeTargets="AfterBuild">
<PropertyGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,8 @@
<PackageReference Include="Bonsai.Harp" Version="3.5.0" />
</ItemGroup>

<ItemGroup>
<EmbeddedResource Include="..\..\device.yml" />
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion template/Harp.Templates.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<PackageType>Template</PackageType>
<VersionPrefix>0.1.2</VersionPrefix>
<VersionPrefix>0.2.0</VersionPrefix>
<VersionSuffix></VersionSuffix>
<PackageId>Harp.Templates</PackageId>
<Title>Harp Templates</Title>
Expand Down

0 comments on commit 8159545

Please sign in to comment.