diff --git a/z21emu/z21emu.cc b/z21emu/z21emu.cc index e9ddefd..b850bda 100644 --- a/z21emu/z21emu.cc +++ b/z21emu/z21emu.cc @@ -18,6 +18,7 @@ void i2cloop(I2C *i2c); void i2cscan(I2C *i2c); void i2ccfgprint(); int i2ccfgload(const char *fname); +int debug = 0; void help(); @@ -40,6 +41,10 @@ int main (int argc, char **argv) { i2ccfgprint(); exit (0); } + + if (strcmp (argv[i], "-debug") == 0) { + debug = 1; + } if (strcmp (argv[i], "-config") == 0) { i++; @@ -85,8 +90,13 @@ void i2cloop (I2C *i2c) { // digital in for (index = 0; index < RBUS_MAXSENSORBYTES; index++) { if (rbus[index].i2c_addr != 0) { - if (!i2c->ReadByte(rbus[index].i2c_addr, rbus[index].i2c_reg, &rbus[index].status)) + if (!i2c->ReadByte(rbus[index].i2c_addr, rbus[index].i2c_reg, &rbus[index].status)) { + if (debug) printf ("i2cloop: Read ADDR:%02x REG:%02x Value:%2x Error\n", rbus[index].i2c_addr, rbus[index].i2c_reg, rbus[index].status); rbus[index].status = 0xFF; // error + } + else if (debug) { + printf ("i2cloop: Read ADDR:%02x REG:%02x Value:%2x\n", rbus[index].i2c_addr, rbus[index].i2c_reg, rbus[index].status); + } } } @@ -268,6 +278,7 @@ void help () { printf ("parameters: without any parameters the config will be read from file.\n"); printf (" if no file is found, autoscan is used first.\n"); printf (" -scan scanning i2c bus and print out a sample device config\n"); + printf (" -debug enabling debugging\n"); printf (" -config FILE finename used for configuration (default %s/\n", DEFAULT_CONFIG); printf ("\n"); } diff --git a/z21emu/z21emu.h b/z21emu/z21emu.h index dea348f..7abecfb 100644 --- a/z21emu/z21emu.h +++ b/z21emu/z21emu.h @@ -44,7 +44,7 @@ struct s_xlanturnout { }; extern struct s_xlanturnout xlturn[XLAN_TURNOUT_MAX]; - +extern int debug; void xlan_turnout (int addr, bool enable);