diff options
| author | Manuel Traut <manut@mecka.net> | 2013-01-15 01:41:38 +0100 |
|---|---|---|
| committer | Manuel Traut <manut@mecka.net> | 2013-01-15 01:41:38 +0100 |
| commit | 33a7f9331cbce18c5f706ed614cbd7c04ef7a9da (patch) | |
| tree | 563f7fe6cd4db2860b22f0c7d8120ff5a919c4eb | |
| parent | 7dd28a3fa96564bb4135a1c4dc936e5824c4c2e7 (diff) | |
improve gpio.conf config format
make it easier for humans to read and bette parseable
Signed-off-by: Manuel Traut <manut@mecka.net>
| -rw-r--r-- | io/bin/generic_gpio/generic_gpio.cpp | 20 | ||||
| -rw-r--r-- | io/bin/generic_gpio/gpio.conf | 14 | ||||
| -rw-r--r-- | io/bin/generic_gpio/ini.c | 10 | ||||
| -rw-r--r-- | io/bin/generic_gpio/ini.h | 2 |
4 files changed, 31 insertions, 15 deletions
diff --git a/io/bin/generic_gpio/generic_gpio.cpp b/io/bin/generic_gpio/generic_gpio.cpp index 06b9f59..f0e2145 100644 --- a/io/bin/generic_gpio/generic_gpio.cpp +++ b/io/bin/generic_gpio/generic_gpio.cpp @@ -18,13 +18,13 @@ static void err (const char *s) class GPIO : public Distrio_Digital_i { public: - GPIO (std::string io_name, int value, ::Distrio::Direction dir) : - Distrio_Digital_i (io_name, dir) { + GPIO (int _id, std::string name, ::Distrio::Direction dir) : + Distrio_Digital_i (name, dir) { int ret = -1; if (dir == ::Distrio::OUTPUT) - ret = gpio_open_dir (&p, value, GPIO_OUT); + ret = gpio_open_dir (&p, _id, GPIO_OUT); if (dir == ::Distrio::INPUT) - ret = gpio_open_dir (&p, value, GPIO_IN); + ret = gpio_open_dir (&p, _id, GPIO_IN); if (ret) { id(-1); err ("open gpio failed\n"); @@ -93,16 +93,22 @@ ACE_TMAIN (int argc, ACE_TCHAR *argv[]) for (i = 0; i < num; i++) { ::Distrio::Direction dir; + char tmp [255]; char *name = _iniparser_getsecname (d, i); - char *direction = _iniparser_getstring (d, "direction", "unknown"); - int value = _iniparser_getint (d, "value", -1); + int id; + char *direction; + sprintf (tmp, "%s:id", name); + id = _iniparser_getint (d, tmp, -1); + sprintf (tmp, "%s:direction", name); + direction = _iniparser_getstring (d, tmp, "unknown"); if (strcmp (direction, "in") == 0) dir = ::Distrio::INPUT; else dir = ::Distrio::OUTPUT; - GPIO *g = new GPIO (std::string (name), value, dir); + std::cout << " new gpio: " << id << ": " << name << std::endl; + GPIO *g = new GPIO (id, std::string (name), dir); if (g->id () == -1) { err ("create gpio object failed - hw error?\n"); diff --git a/io/bin/generic_gpio/gpio.conf b/io/bin/generic_gpio/gpio.conf index 2408983..44068de 100644 --- a/io/bin/generic_gpio/gpio.conf +++ b/io/bin/generic_gpio/gpio.conf @@ -1,11 +1,11 @@ -[0] +[led0] + id = 0; direction = out; - value = 1; -[1] +[led1] + id = 11; direction = out; - value = 0; -[332] - direction = out; - value = 0; +[keyboard] + id = 272; + direction = in; diff --git a/io/bin/generic_gpio/ini.c b/io/bin/generic_gpio/ini.c index 2472c54..25ac0c9 100644 --- a/io/bin/generic_gpio/ini.c +++ b/io/bin/generic_gpio/ini.c @@ -1,5 +1,5 @@ #include "ini.h" -int init (){;} + dictionary *_iniparser_load (const char *conf) { return iniparser_load (conf); } @@ -15,3 +15,11 @@ char *_iniparser_getsecname (dictionary *d, int i) { void _iniparser_freedict (dictionary *d) { iniparser_freedict (d); } + +char *_iniparser_getstring(dictionary * d, const char * key, char * def) { + return iniparser_getstring(d, key, def); +} + +int _iniparser_getint(dictionary * d, const char * key, int notfound) { + return iniparser_getint(d, key, notfound); +} diff --git a/io/bin/generic_gpio/ini.h b/io/bin/generic_gpio/ini.h index accc454..39b7255 100644 --- a/io/bin/generic_gpio/ini.h +++ b/io/bin/generic_gpio/ini.h @@ -9,6 +9,8 @@ dictionary * _iniparser_load (const char *conf); int _iniparser_getnsec (dictionary *d); char *_iniparser_getsecname (dictionary *d, int i); void _iniparser_freedict (dictionary *d); +char *_iniparser_getstring(dictionary * d, const char * key, char * def); +int _iniparser_getint(dictionary * d, const char * key, int notfound); #ifdef __cplusplus } #endif |
