diff options
-rw-r--r-- | src/command.c | 43 | ||||
-rw-r--r-- | src/nanolight.c | 3 | ||||
-rw-r--r-- | src/nanolight.h | 1 |
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; |