Skip to content

Commit 8159545

Browse files
authored
Merge pull request #63 from glopesdev/interface-gen
Embed device metadata as part of interface project
2 parents c92023c + 2b87c1b commit 8159545

File tree

5 files changed

+42
-3
lines changed

5 files changed

+42
-3
lines changed

interface/Device.tt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,41 @@ foreach (var register in deviceRegisters)
6868
}
6969
#>
7070
};
71+
72+
/// <summary>
73+
/// Gets the contents of the metadata file describing the <see cref="<#= deviceName #>"/>
74+
/// device registers.
75+
/// </summary>
76+
public static readonly string Metadata = GetDeviceMetadata();
77+
78+
static string GetDeviceMetadata()
79+
{
80+
var deviceType = typeof(Device);
81+
using var metadataStream = deviceType.Assembly.GetManifestResourceStream($"{deviceType.Namespace}.device.yml");
82+
using var streamReader = new System.IO.StreamReader(metadataStream);
83+
return streamReader.ReadToEnd();
84+
}
85+
}
86+
87+
/// <summary>
88+
/// Represents an operator that returns the contents of the metadata file
89+
/// describing the <see cref="<#= deviceName #>"/> device registers.
90+
/// </summary>
91+
[Description("Returns the contents of the metadata file describing the <#= deviceName #> device registers.")]
92+
public partial class GetMetadata : Source<string>
93+
{
94+
/// <summary>
95+
/// Returns an observable sequence with the contents of the metadata file
96+
/// describing the <see cref="<#= deviceName #>"/> device registers.
97+
/// </summary>
98+
/// <returns>
99+
/// A sequence with a single <see cref="string"/> object representing the
100+
/// contents of the metadata file.
101+
/// </returns>
102+
public override IObservable<string> Generate()
103+
{
104+
return Observable.Return(Device.Metadata);
105+
}
71106
}
72107

73108
/// <summary>

interface/Harp.Generators.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<VersionPrefix>0.2.0</VersionPrefix>
4+
<VersionPrefix>0.3.0</VersionPrefix>
55
<VersionSuffix></VersionSuffix>
66
<PackageId>Harp.Generators</PackageId>
77
<Title>Harp Generators</Title>

template/Bonsai.DeviceTemplate/Generators/Generators.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<FirmwarePath>..\Firmware\$projectname$</FirmwarePath>
1616
</PropertyGroup>
1717
<ItemGroup>
18-
<PackageReference Include="Harp.Generators" Version="0.1.0" GeneratePathProperty="true" />
18+
<PackageReference Include="Harp.Generators" Version="0.3.0" GeneratePathProperty="true" />
1919
</ItemGroup>
2020
<Target Name="TextTransform" BeforeTargets="AfterBuild">
2121
<PropertyGroup>

template/Bonsai.DeviceTemplate/Interface/DeviceTemplate/DeviceTemplate.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@
2323
<PackageReference Include="Bonsai.Harp" Version="3.5.0" />
2424
</ItemGroup>
2525

26+
<ItemGroup>
27+
<EmbeddedResource Include="..\..\device.yml" />
28+
</ItemGroup>
29+
2630
</Project>

template/Harp.Templates.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<PropertyGroup>
44
<PackageType>Template</PackageType>
5-
<VersionPrefix>0.1.2</VersionPrefix>
5+
<VersionPrefix>0.2.0</VersionPrefix>
66
<VersionSuffix></VersionSuffix>
77
<PackageId>Harp.Templates</PackageId>
88
<Title>Harp Templates</Title>

0 commit comments

Comments
 (0)