Skip to content

Commit 563b6c8

Browse files
authored
Improve device listening generation (#1188)
1 parent af0c091 commit 563b6c8

File tree

6 files changed

+163
-127
lines changed

6 files changed

+163
-127
lines changed

devices/Ld2410/category.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
sonar
2-
presence

devices/Max1704x/category.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
power
21
power

devices/README.md

Lines changed: 62 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Mpu9250.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Mpu9250/) [MPU6050/MPU6500/MPU9250 - Gyroscope, Accelerometer, Temperature and Magnetometer (MPU9250 only)](Mpu9250)
2525
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Mpu6886.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Mpu6886/) [Mpu6886 - accelerometer and gyroscope](Mpu6886)
2626

27+
## Volatile Organic Compound sensors
28+
29+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Ags01db.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Ags01db/) [AGS01DB - MEMS VOC Gas Sensor](Ags01db)
30+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Bmxx80.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Bmxx80/) [BMP280/BME280/BME680 Device Family](Bmxx80)
31+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Ccs811.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Ccs811/) [CCS811 Gas sensor](Ccs811)
32+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Sen5x.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Sen5x/) [Sensirion SEN5x series module](Sen5x)
33+
2734
## Gas sensors
2835

2936
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Ags01db.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Ags01db/) [AGS01DB - MEMS VOC Gas Sensor](Ags01db)
@@ -126,6 +133,11 @@
126133
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Lsm9Ds1.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Lsm9Ds1/) [LSM9DS1 - 3D accelerometer, gyroscope and magnetometer](Lsm9Ds1)
127134
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Mpu9250.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Mpu9250/) [MPU6050/MPU6500/MPU9250 - Gyroscope, Accelerometer, Temperature and Magnetometer (MPU9250 only)](Mpu9250)
128135

136+
## Liquid Crystal Displays
137+
138+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.CharacterLcd.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.CharacterLcd/) [Character LCD (Liquid Crystal Display)](CharacterLcd)
139+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Pcd8544.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Pcd8544/) [PCD8544 - 48 × 84 pixels matrix LCD, famous Nokia 5110 screen](Pcd8544)
140+
129141
## Hygrometers
130142

131143
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Ahtxx.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Ahtxx/) [AHT10/15/20 - Temperature and humidity sensor modules](Ahtxx)
@@ -143,13 +155,19 @@
143155
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Shtc3.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Shtc3/) [SHTC3 - Temperature & Humidity Sensor](Shtc3)
144156
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Si7021.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Si7021/) [Si7021 - Temperature & Humidity Sensor](Si7021)
145157

158+
## Real Time Clocks
159+
160+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Ds1302.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Ds1302/) [DS1302 - Realtime Clock](Ds1302)
161+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Mcp7940xx.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Mcp7940xx/) [Mcp7940xx/MCP79400/MCP79401/MCP79402 - I2C Real-Time Clock/Calendar with SRAM](Mcp7940xx)
162+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Rtc.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Rtc/) [Realtime Clock](Rtc)
163+
146164
## Clocks
147165

148166
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Ds1302.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Ds1302/) [DS1302 - Realtime Clock](Ds1302)
149167
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Mcp7940xx.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Mcp7940xx/) [Mcp7940xx/MCP79400/MCP79401/MCP79402 - I2C Real-Time Clock/Calendar with SRAM](Mcp7940xx)
150168
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Rtc.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Rtc/) [Realtime Clock](Rtc)
151169

152-
## Sonars
170+
## Sonars and presence sensors
153171

154172
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Hcsr04.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Hcsr04/) [HC-SR04 - Ultrasonic Ranging Module](Hcsr04)
155173
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Hcsr04.Esp32.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Hcsr04.Esp32/) [HC-SR04 for ESP32 with RMT - Ultrasonic Ranging Module](Hcsr04.Esp32)
@@ -185,6 +203,10 @@
185203
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Ws28xx.Esp32.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Ws28xx.Esp32/) [Ws28xx/WS2812B/WS2815B/WS2808/SK6812/Neo pixel for ESP32 using RMT - LED drivers](Ws28xx.Esp32)
186204
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Ws28xx.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Ws28xx/) [Ws28xx/WS2812B/WS2815B/WS2808/SK6812/Neo pixel using SPI - LED drivers](Ws28xx)
187205

206+
## Segment displays
207+
208+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Tm1637.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Tm1637/) [TM1637 - Segment Display](Tm1637)
209+
188210
## GPIO Expanders
189211

190212
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Seesaw.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Seesaw/) [Adafruit Seesaw - extension board (ADC, PWM, GPIO expander)](Seesaw)
@@ -217,6 +239,16 @@
217239
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.RadioTransmitter.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.RadioTransmitter/) [Radio Transmitter](RadioTransmitter)
218240
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.SwarmTile.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.SwarmTile/) [Swarm Tile](SwarmTile)
219241

242+
## Radio modules
243+
244+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.RadioReceiver.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.RadioReceiver/) [Radio Receiver](RadioReceiver)
245+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.RadioTransmitter.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.RadioTransmitter/) [Radio Transmitter](RadioTransmitter)
246+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.SwarmTile.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.SwarmTile/) [Swarm Tile](SwarmTile)
247+
248+
## PWM libraries/modules
249+
250+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Seesaw.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Seesaw/) [Adafruit Seesaw - extension board (ADC, PWM, GPIO expander)](Seesaw)
251+
220252
## Color sensors
221253

222254
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Tcs3472x.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Tcs3472x/) [TCS3472x/TCS34721/TCS34723/TCS34725/TCS34727 Sensors](Tcs3472x)
@@ -257,12 +289,6 @@
257289
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.RotaryEncoder.Esp32.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.RotaryEncoder.Esp32/) [Quadrature Rotary Encoder (ESP32)](RotaryEncoder.Esp32)
258290
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Sn74hc595.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Sn74hc595/) [SN74HC595 -- 8-bit shift register](Sn74hc595)
259291

260-
## Protocols providers/libraries
261-
262-
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Seesaw.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Seesaw/) [Adafruit Seesaw - extension board (ADC, PWM, GPIO expander)](Seesaw)
263-
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.DhcpServer.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.DhcpServer/) [DHCP Server](DhcpServer)
264-
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Modbus.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Modbus/) [Modbus - Machine to machine communication protocol](Modbus)
265-
266292
## Power monitors and related devices
267293

268294
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Axp192.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Axp192/) [AXP192 - Enhanced single Cell Li-Battery and Power System Management IC](Axp192)
@@ -272,6 +298,27 @@
272298
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Ip5306.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Ip5306/) [IP5306 - Power management](Ip5306)
273299
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Max1704x.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Max1704x/) [MAX1704x/MAX17043/MAX17044/MAX17048/MAX17049 - Battery gauge](Max1704x)
274300

301+
## Protocols providers/libraries
302+
303+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Seesaw.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Seesaw/) [Adafruit Seesaw - extension board (ADC, PWM, GPIO expander)](Seesaw)
304+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.DhcpServer.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.DhcpServer/) [DHCP Server](DhcpServer)
305+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Modbus.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Modbus/) [Modbus - Machine to machine communication protocol](Modbus)
306+
307+
##
308+
309+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.CharacterLcd.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.CharacterLcd/) [Character LCD (Liquid Crystal Display)](CharacterLcd)
310+
311+
##
312+
313+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Buzzer.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Buzzer/) [Buzzer - Piezo Buzzer Controller](Buzzer)
314+
315+
##
316+
317+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Charlieplex.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Charlieplex/) [Charlieplex Segment binding](Charlieplex)
318+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.ShiftRegister.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.ShiftRegister/) [Generic shift register](ShiftRegister)
319+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Mbi5027.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Mbi5027/) [MBI5027 -- 16-bit shift register with error detection](Mbi5027)
320+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Sn74hc595.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Sn74hc595/) [SN74HC595 -- 8-bit shift register](Sn74hc595)
321+
275322
## Digital/Analog converters
276323

277324
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.AD5328.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.AD5328/) [AD5328 - Digital to Analog Convertor](AD5328)
@@ -312,4 +359,12 @@
312359
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Sen5x.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Sen5x/) [Sensirion SEN5x series module](Sen5x)
313360
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.Sps30.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.Sps30/) [Sensirion SPS30 Particulate Matter Sensor](Sps30)
314361

362+
## E-Paper
363+
364+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.ePaper.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.ePaper/) [ePaper drivers for .NET nanoFramework](ePaper)
365+
366+
## Positioning like GNSS, GPS
367+
368+
* [![NuGet](https://img.shields.io/nuget/v/nanoFramework.IoT.Device.GnssDevice.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.IoT.Device.GnssDevice/) [Global Navigation Satellite System Device NMEA 0183 - Including Generic Serial Module with GPS, GNSS, BeiDou - NEO6-M, NEO-M8P-2, NEO-M9N from u-blox, ATGM336H, Minewsemi, ZED-F9P, ZOE-M8Q, SAM-M8Q, SARA-R5 and many many more](GnssDevice)
369+
315370
</categorizedDevices>

src/device-listing/Program.cs

Lines changed: 31 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -6,122 +6,10 @@
66
using System.IO;
77
using System.Linq;
88
using System.Text;
9-
using System.Threading;
9+
using System.Text.Json;
1010
using Iot.Tools.DeviceListing;
1111

12-
string[] categoriesToDisplay = new string[]
13-
{
14-
"adc",
15-
"accelerometer",
16-
"gas",
17-
"liquid",
18-
"light",
19-
"barometer",
20-
"altimeter",
21-
"thermometer",
22-
"infrared",
23-
"gyroscope",
24-
"compass",
25-
"lego",
26-
"motor",
27-
"imu",
28-
"magnetometer",
29-
"hygrometer",
30-
"clock",
31-
"sonar",
32-
"distance",
33-
"pir",
34-
"motion",
35-
"display",
36-
"io-expander",
37-
"canbus",
38-
"proximity",
39-
"touch",
40-
"wireless",
41-
"joystick",
42-
"color",
43-
"led",
44-
"nfc",
45-
"media",
46-
"usb",
47-
"gpio",
48-
"multi",
49-
"protocol",
50-
"power",
51-
"dac",
52-
"eeprom",
53-
"helper",
54-
"system",
55-
"lidar",
56-
"reader",
57-
"satellite",
58-
"particulatematter",
59-
};
60-
61-
Dictionary<string, string?> categoriesDescriptions = new()
62-
{
63-
{ "adc", "Analog/Digital converters" },
64-
{ "accelerometer", "Accelerometers" },
65-
{ "voc", "Volatile Organic Compound sensors" },
66-
{ "gas", "Gas sensors" },
67-
{ "liquid", "Liquid sensors" },
68-
{ "light", "Light sensor" },
69-
{ "barometer", "Barometers" },
70-
{ "altimeter", "Altimeters" },
71-
{ "thermometer", "Thermometers" },
72-
{ "infrared", "Infrared sensors" },
73-
{ "gyroscope", "Gyroscopes" },
74-
{ "compass", "Compasses" },
75-
{ "lego", "Lego related devices" },
76-
{ "motor", "Motor controllers/drivers" },
77-
{ "imu", "Inertial Measurement Units" },
78-
{ "magnetometer", "Magnetometers" },
79-
{ "lcd", "Liquid Crystal Displays" },
80-
{ "hygrometer", "Hygrometers" },
81-
{ "rtc", "Real Time Clocks" },
82-
{ "clock", "Clocks" },
83-
{ "sonar", "Sonars" },
84-
{ "distance", "Distance sensors" },
85-
{ "pir", "Passive InfraRed (motion) sensors" },
86-
{ "motion", "Motion sensors" },
87-
{ "display", "Displays" },
88-
{ "segment", "Segment displays" },
89-
{ "io-expander", "GPIO Expanders" },
90-
{ "canbus", "CAN BUS libraries/modules" },
91-
{ "proximity", "Proximity sensors" },
92-
{ "touch", "Touch sensors" },
93-
{ "wireless", "Wireless communication modules" },
94-
{ "radio", "Radio modules" },
95-
{ "pwm", "PWM libraries/modules" },
96-
{ "spi", "SPI libraries/modules" },
97-
{ "joystick", "Joysticks" },
98-
{ "color", "Color sensors" },
99-
{ "led", "LED drivers" },
100-
{ "nfc", "RFID/NFC modules" },
101-
{ "media", "Media libraries" },
102-
{ "usb", "USB devices" },
103-
{ "gpio", "GPIO or bit operating devices" },
104-
{ "power", "Power monitors and related devices" },
105-
{ "multi", "Multi-device or robot kit" },
106-
// Bucket for stuff we want mentioned but there is no clear category
107-
// In other words: anything allowing a way to create PWM channel, SPI/I2C/... device
108-
{ "protocol", "Protocols providers/libraries" },
109-
{ "characterlcd", null },
110-
{ "brickpi3", null },
111-
{ "buzzer", null },
112-
{ "gopigo3", null },
113-
{ "grovepi", null },
114-
{ "i2c", null },
115-
{ "multiplexer", null },
116-
{ "dac", "Digital/Analog converters" },
117-
{ "eeprom", "EEPROM" },
118-
{ "helper", "Iot.Device helpers and common" },
119-
{ "system", ".NET System libraries" },
120-
{ "lidar", "Lidar" },
121-
{ "reader", "Readers" },
122-
{ "satellite", " modules" },
123-
{ "particulatematter", "Particulate Matter Sensor" },
124-
};
12+
Dictionary<string, string?> categoriesDescriptions = JsonSerializer.Deserialize<Dictionary<string, string?>>(File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "categories.json")));
12513

12614
HashSet<string> ignoredDeviceDirectories = new()
12715
{
@@ -130,7 +18,16 @@
13018
"Interop",
13119
};
13220

133-
var repoRootPath = Path.Combine(Environment.GetEnvironmentVariable("BUILD_SOURCESDIRECTORY"), "nanoFramework.IoT.Device");
21+
string repoRootPath;
22+
if (!string.IsNullOrEmpty(Environment.GetEnvironmentVariable("BUILD_SOURCESDIRECTORY")))
23+
{
24+
repoRootPath = Path.Combine(Environment.GetEnvironmentVariable("BUILD_SOURCESDIRECTORY"), "nanoFramework.IoT.Device");
25+
}
26+
else
27+
{
28+
// Find the first directory that contains a .git folder
29+
repoRootPath = FindGitRepositoryRoot(Environment.CurrentDirectory);
30+
}
13431

13532
Console.WriteLine($"Finding repository root. Starting point is: {repoRootPath}");
13633

@@ -191,7 +88,7 @@
19188
}
19289
}
19390

194-
beingDisplayed |= !beingDisplayed && categoriesToDisplay.Contains(category);
91+
beingDisplayed |= !beingDisplayed && categoriesDescriptions.Keys.Contains(category);
19592
}
19693

19794
if (!beingDisplayed && device.CategoriesFileExists)
@@ -241,7 +138,7 @@ string GetDeviceListing(string devicesPath, IEnumerable<DeviceInfo> devices)
241138
string GetCategorizedDeviceListing(string devicesPath, IEnumerable<DeviceInfo> devices)
242139
{
243140
var deviceListing = new StringBuilder();
244-
foreach (string categoryToDisplay in categoriesToDisplay)
141+
foreach (string categoryToDisplay in categoriesDescriptions.Keys)
245142
{
246143
if (categoriesDescriptions.TryGetValue(categoryToDisplay, out string? categoryDescription))
247144
{
@@ -331,3 +228,20 @@ void ReplacePlaceholder(string filePath, string placeholderName, string newConte
331228
newContent +
332229
fileContent.Substring(endIdx));
333230
}
231+
232+
string? FindGitRepositoryRoot(string startDirectory)
233+
{
234+
DirectoryInfo? currentDirectory = new DirectoryInfo(startDirectory);
235+
236+
while (currentDirectory != null)
237+
{
238+
if (Directory.Exists(Path.Combine(currentDirectory.FullName, ".git")))
239+
{
240+
return currentDirectory.FullName;
241+
}
242+
243+
currentDirectory = currentDirectory.Parent;
244+
}
245+
246+
return null;
247+
}

0 commit comments

Comments
 (0)