summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2019-06-03 21:01:26 +0200
committerThomas White <taw@physics.org>2019-06-04 23:05:59 +0200
commit855d860ca8bc4c34adb5eebd8e25342342056b8b (patch)
tree17f9c2ffe4bde6c56b6b308577d6d6e8fb69347e
parent1e32c49b4d08b1d517ccda7380c3909986d9d7cd (diff)
Attribute classes in commands
-rw-r--r--src/command.c43
-rw-r--r--src/nanolight.c3
-rw-r--r--src/nanolight.h1
3 files changed, 39 insertions, 8 deletions
diff --git a/src/command.c b/src/command.c
index 7ae36ae..c6b64e7 100644
--- a/src/command.c
+++ b/src/command.c
@@ -45,10 +45,30 @@ struct token
{
enum token_type type;
int fixture_index;
+ enum attr_class attribute;
int val;
};
+/* Tables for converting between attribute class numbers and names */
+
+const char *attr_class_names[] = {
+ "int",
+ "pan",
+ "tilt"
+};
+
+enum attr_class attr_classes[] = {
+ ATT_INTENSITY,
+ ATT_PAN,
+ ATT_TILT
+};
+
+int n_attr_classes = 3;
+
+/* (end of attribute tables) */
+
+
static int stop_char(char c)
{
if ( c == '@' ) return 1;
@@ -110,10 +130,10 @@ static int find_tokens(const char *cmd, struct token *tokens, struct nanolight *
}
/* Is is an attribute name? */
- for ( i=0; i<nl->n_fixtures; i++ ) {
- if ( strcasecmp(nl->fixtures[i].label, word) == 0 ) {
- tokens[n].fixture_index = i;
- tokens[n++].type = TK_FIXTURE;
+ for ( i=0; i<n_attr_classes; i++ ) {
+ if ( strcasecmp(attr_class_names[i], word) == 0 ) {
+ tokens[n].attribute = attr_classes[i];
+ tokens[n++].type = TK_ATTRIBUTE;
done = 1;
break;
}
@@ -136,6 +156,16 @@ static int find_tokens(const char *cmd, struct token *tokens, struct nanolight *
}
+static const char *str_attr(enum attr_class att)
+{
+ switch ( att ) {
+ case ATT_INTENSITY : return "intensity";
+ case ATT_PAN : return "pan";
+ case ATT_TILT : return "tilt";
+ }
+ return "???";
+}
+
static void show_tokens(struct token *tokens, int n, struct nanolight *nl)
{
int i;
@@ -163,6 +193,11 @@ static void show_tokens(struct token *tokens, int n, struct nanolight *nl)
printf(" [value:%i]", tokens[i].val);
break;
+ case TK_ATTRIBUTE:
+ printf(" [attr:%s]", str_attr(tokens[i].attribute));
+ break;
+
+
}
}
diff --git a/src/nanolight.c b/src/nanolight.c
index 6cb06e6..38992d0 100644
--- a/src/nanolight.c
+++ b/src/nanolight.c
@@ -322,17 +322,14 @@ int main(int argc, char *argv[])
cls.n_attrs = 3;
cls.attrs = attrs;
- cls.attrs[0].name = "Intensity";
cls.attrs[0].cls = ATT_INTENSITY;
cls.attrs[0].props = 0;
cls.attrs[0].addr_offset = 50;
- cls.attrs[1].name = "Pan";
cls.attrs[1].cls = ATT_PAN;
cls.attrs[1].props = ATTR_16BIT;
cls.attrs[1].addr_offset = 0;
- cls.attrs[2].name = "Tilt";
cls.attrs[2].cls = ATT_TILT;
cls.attrs[2].props = ATTR_16BIT;
cls.attrs[2].addr_offset = 2;
diff --git a/src/nanolight.h b/src/nanolight.h
index 29cdbfc..9e6f19e 100644
--- a/src/nanolight.h
+++ b/src/nanolight.h
@@ -39,7 +39,6 @@ enum attr_class
struct attribute
{
- char *name;
enum attr_class cls;
int props;
int addr_offset;