+ if(timer - prev_time >= 14400) { /* 1 sec */
+ prev_time = timer;
+
+ prev_stat = stat;
+ stat = read_status();
+
+ if(stat != prev_stat) {
+ printf("[%s|%s|%dHz|", stat & STAT_ON ? " on" : "off",
+ stat & STAT_SYNC ? "lock" : " ", stat & STAT_60HZ ? 60 : 50);
+
+ switch(stat & STAT_COLOR_MASK) {
+ case STAT_COLOR_PAL:
+ printf(" PAL ]");
+ break;
+ case STAT_COLOR_NTSC:
+ printf(" NTSC]");
+ break;
+ case STAT_COLOR_SECAM:
+ printf("SECAM]");
+ break;
+ default:
+ printf(" ]");
+ }
+
+ printf(" [%s|%s]\n", stat & STAT_EN ? "en" : " ",
+ stat & STAT_BUSHOLD ? "hold" : " ");
+ }
+ /*printf(" %02x %02x %02x\n", data[0], data[1], data[2]);*/
+
+
+ if(enable) {
+ static unsigned char rel_timeout;
+ if(i2c_isheld()) {
+ if(!(stat & STAT_ON) || (stat & STAT_COLOR_MASK)) {
+ /* if we turn the TV off, or if we don't have RGB input
+ * release the i2c bus (after a few seconds to make sure it's not a glitch)
+ */
+ if(++rel_timeout > 3) {
+ i2c_release();
+ printf("rel2\n");
+ rel_timeout = 0;
+ grab_timeout = 10;
+ }
+ } else {
+ rel_timeout = 0;
+ /* handle any pending volume changes */
+ /*
+ if(pend & PEND_VOL) {
+ updhold();
+ }
+ */
+ }
+
+ } else {
+ /* we're not currently holding the bus */
+ if((stat & STAT_ON) && !(stat & STAT_COLOR_MASK)) {
+ /* if the TV is on and we're in RGB mode, grab the bus
+ * (after a few seconds to allow the tv to initialize)
+ */
+ if(grab_timeout > 0) {
+ grab_timeout--;
+ } else {
+ updhold();
+ grab_timeout = 0;
+ }
+ }
+ }
+ }