Skip to content

Commit

Permalink
Merge pull request #120 from rneswold/pr-issue110
Browse files Browse the repository at this point in the history
✨ add `map` driver
  • Loading branch information
rneswold authored Aug 2, 2024
2 parents 77e830c + c60fc19 commit fbb32a8
Show file tree
Hide file tree
Showing 6 changed files with 451 additions and 2 deletions.
2 changes: 1 addition & 1 deletion drmem-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "drmem-api"
version = "0.4.0"
version = "0.4.1"
authors = ["Rich Neswold <[email protected]>"]
edition = "2021"
description = "Traits and types used internally by the DrMem control system"
Expand Down
13 changes: 13 additions & 0 deletions drmem-api/src/types/device/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ pub enum Value {
Color(palette::LinSrgba<u8>),
}

impl Value {
pub fn is_same_type(&self, o: &Value) -> bool {
match (self, o) {
(Value::Bool(_), Value::Bool(_))
| (Value::Int(_), Value::Int(_))
| (Value::Flt(_), Value::Flt(_))
| (Value::Str(_), Value::Str(_))
| (Value::Color(_), Value::Color(_)) => true,
_ => false,
}
}
}

impl fmt::Display for Value {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
2 changes: 1 addition & 1 deletion drmemd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ palette.workspace = true

lazy_static = "1"

drmem-api = { path = "../drmem-api", version = "0.4" }
drmem-api = { path = "../drmem-api", version = "0.4.1" }

cfgrammar = "0.13"
lrlex = "0.13"
Expand Down
39 changes: 39 additions & 0 deletions drmemd/src/driver/drv_map.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# drmem-drv-map

A map device is a driver that maps a range of integers to a device
value. The driver creates two devices, `index` and `output`. When the
`index` is set, the driver finds the associated value and write both
of them to the backend storage. Every setting will get sent to the
backend -- even if the new value is the same as the old.

## Configuration

The configuration parameters for this driver are:

- `initial` is an optional parameter. It is an integer which specifies
the initial index to use when the driver starts. If no initial value
is specified, the `output` device will be set to the default value.
- `values` is an array of maps. Each map has three key/values: 1)
'start' is an integer specifying the start of the index range, `end`
is an optional parameter specifying the ending range, inclusive (if
omitted, `end` is the same as `start`), and `value` is a value to
output when the index device is set within this range.
- `default` is the value that will be used if the `index` device gets
set to a value that doesn't lie within any range.

NOTE: when the driver starts, it makes sure that no range in the
`values` array overlaps any other range. It also makes sure that all
the values in the array and the default value are of the same type.

## Devices

The driver creates these devices:

| Base Name | Type | Units | Comment |
|-----------|------------|-------|--------------------------------------------------------------|
| index | integer, RW | | The index value used to look up a value in the map. |
| output | VALUE, RO | | This device gets updated everytime the `index` device gets updated. It gets set to the value determined by the map lookup. If the index didn't lie in any range, it gets set to the default value. |

## History

Added in v0.4.0.
Loading

0 comments on commit fbb32a8

Please sign in to comment.