+#if 1
+ /*
+ * User interface
+ */
+ if(state == 0) {
+ /* Display temperature */
+ if(ktok) {
+ ktok = 0;
+ if((tempk >= 273) && (tempk <= 372)) {
+ display(tempk - 273, 0, run);
+ } else {
+ dsp[0] = SEGG;
+ dsp[1] = SEGG | (run?SEGP:0);
+ }
+ }
+ if(pval != 0)
+ state = 1;
+ if(sstate == 2) {
+ sstate = 0;
+ if(stime > 10)
+ state = 2;
+ else
+ run = !run;
+ }
+ } else if(state == 1) {
+ /* Temp setting */
+ if(pval != 0) {
+ cur += pval;
+ pval = 0;
+ if(cur < 0)
+ cur = 0;
+ if(cur > 100)
+ cur = 100;
+ utime = mnow;
+ }
+ if(mnow - utime > 2000000) {
+ state = 0;
+ eeprom_write_byte(0, cur);
+ }
+ if(sstate == 2) {
+ run = !run;
+ sstate = 0;
+ }
+ if(cur < 100) {
+ display(cur, 0, run);
+ } else {
+ dsp[0] = SEGG;
+ dsp[1] = SEGG | (run?SEGP:0);
+ }
+ } else if(state == 2) {
+ /* Display raw temp time reading */
+ if(ttimea < 20000) {
+ display((ttimea / 100) % 100, 1, ttimea >= 10000);
+ } else {
+ display(ttimea / 1000, 0, 0);
+ }
+ if(sstate == 2) {
+ state = 0;
+ sstate = 0;
+ }
+ }
+ /*
+ * Set Triac to match temperature
+ */
+ if(run) {
+ delta = cur - (tempk - 273);
+ if(rstate == 0) {
+ if(delta > 0) {
+ tron = 1;
+ if(delta > 8) {
+ /* For some reason, the Triac currently doesn't
+ * trigger on one of the AC half-cycles below 0.7
+ * ms. */
+ trdelay = 7;
+ } else {
+ trdelay = 75 - (delta * 5);
+ }
+ } else {
+ tron = 0;
+ rstate = 1;
+ }
+ } else if(rstate == 1) {
+ tron = 0;
+ if(delta >= 2)
+ rstate = 0;
+ }
+ } else {
+ tron = 0;
+ }
+#endif