diff --git a/backend/src/driver_db/categories.rs b/backend/src/driver_db/categories.rs index a8536e8..06cbe01 100644 --- a/backend/src/driver_db/categories.rs +++ b/backend/src/driver_db/categories.rs @@ -70,8 +70,60 @@ pub enum Category { Oled, // Timer + /// Chips measuring time Timer, #[serde(rename = "Timer::RTC")] + /// Clocks that keep track of wall time + /// + /// Often allow to measure time with an external battery. Rtc, } + +impl Category { + /// Get a list of all categories that contain this category + pub fn parents(&self) -> Vec { + let mut parents = vec![]; + + let mut me = *self; + while let Some(parent) = me.parent() { + parents.push(parent); + me = parent; + } + + parents + } + + fn parent(&self) -> Option { + Some(match self { + Self::Analog => { + return None; + } + Self::Adc => Self::Analog, + Self::Dac => Self::Analog, + Self::Sensor => { + return None; + } + Self::PowerMeter => Self::Sensor, + Self::Accelerometer => Self::Sensor, + Self::Gyroscope => Self::Sensor, + Self::Magnetometer => Self::Sensor, + Self::IoExpander => { + return None; + } + Self::PwmExpander => Self::IoExpander, + Self::Actor => { + return None; + } + Self::MotorController => Self::Actor, + Self::Display => { + return None; + } + Self::Oled => Self::Display, + Self::Timer => { + return None; + } + Self::Rtc => Self::Timer, + }) + } +} diff --git a/backend/src/website_db/indexes.rs b/backend/src/website_db/indexes.rs index 3511616..270f8e9 100644 --- a/backend/src/website_db/indexes.rs +++ b/backend/src/website_db/indexes.rs @@ -44,9 +44,12 @@ impl From<&[FullCrate]> for Indexes { let mut has_dev_board = BTreeSet::new(); for (i, krate) in value.iter().enumerate() { - // TODO also match sub categories for cat in &krate.chip_meta.categories { category.add(*cat, i); + + for parent in cat.parents() { + category.add(parent, i); + } } for l in krate.licenses() { diff --git a/driver-db-schema.json b/driver-db-schema.json index 93f8980..96776a1 100644 --- a/driver-db-schema.json +++ b/driver-db-schema.json @@ -48,13 +48,6 @@ }, "Category": { "oneOf": [ - { - "type": "string", - "enum": [ - "Timer", - "Timer::RTC" - ] - }, { "description": "Devices interacting with analog signals", "type": "string", @@ -124,6 +117,16 @@ "description": "OLED Screens", "type": "string", "const": "Display::OLED" + }, + { + "description": "Chips measuring time", + "type": "string", + "const": "Timer" + }, + { + "description": "Clocks that keep track of wall time\n\n Often allow to measure time with an external battery.", + "type": "string", + "const": "Timer::RTC" } ] }, diff --git a/frontend/src/App.svelte b/frontend/src/App.svelte index 72b1724..50da466 100644 --- a/frontend/src/App.svelte +++ b/frontend/src/App.svelte @@ -14,6 +14,7 @@ const t_crates = crates as FullCrate[]; let t_indexes = indexes as Indexes; + let selected_c: number[][] = []; let selected_d: number[][] = []; let selected_l: number[][] = []; let selected_r: number[][] = []; @@ -42,7 +43,7 @@ } } - $: selected_crates = combine_filters(t_crates.length, [selected_d, selected_l, selected_r, selected_i, selected_f]); + $: selected_crates = combine_filters(t_crates.length, [selected_c, selected_d, selected_l, selected_r, selected_i, selected_f]); @@ -53,8 +54,9 @@

{selected_crates.length} awesome drivers waiting for you!

- + +