void commandline_addchar(char c) { wdt_reset(); if ( c == '\r' || c == '\n' ) { if (current_pos != current_line) processinput(); } else if ( c == 0x08 && current_pos > current_line ) *current_pos-- = '\0'; else if ( current_pos < current_line + MAX_LINE ) *current_pos++ = c; }
void loop() { static uint16_t code(0); static uint8_t cnt(0); static inductiveloop::STATUS previls(inductiveloop::NONE); static bool prevconflict(false); inductiveloop::STATUS ils; bool conflict; bool dtupdated(false); if( getlinefromserial( g_iobuf, sizeof( g_iobuf ), g_inidx) ) processinput(); conflict = g_loop.update( ils ); if( ils != previls || conflict != prevconflict ) { updatedt(dtupdated); updateloopstatus(ils, conflict); #ifdef VERBOSE Serial.print(CMNT); serialoutsepln(", ", "ilschange", (int)ils, (int)previls, conflict, prevconflict ); #endif // VERBOSE g_logger.log(logwriter::DEBUG, g_time, F("ILS"), (uint16_t)ils); if( ils == inductiveloop::NONE ) { g_outputs.set( PIN_IN_YELLOW, RELAY_OFF ); g_outputs.set( PIN_OUT_YELLOW, RELAY_OFF ); g_outputs.set( PIN_IN_RED, RELAY_OFF ); g_outputs.set( PIN_OUT_RED, RELAY_OFF ); } else if( ils == inductiveloop::INNER ) { g_outputs.set( PIN_IN_YELLOW, RELAY_ON ); g_outputs.set( PIN_OUT_RED, RELAY_ON ); g_outputs.set( PIN_IN_RED, RELAY_OFF ); g_outputs.set( PIN_OUT_YELLOW, RELAY_OFF ); } else { g_outputs.set( PIN_IN_RED, RELAY_ON ); g_outputs.set( PIN_OUT_YELLOW, RELAY_ON ); g_outputs.set( PIN_IN_YELLOW, RELAY_OFF ); g_outputs.set( PIN_OUT_RED, RELAY_OFF ); } previls = ils; prevconflict = conflict; } if( g_codeready && ils != inductiveloop::NONE ) { uint16_t id( getid( g_code )); uint8_t btn( getbutton( g_code )); bool inner(ils == inductiveloop::INNER); if( code != g_code ) { if( cnt ) { updatedt(dtupdated); g_logger.log( logwriter::DEBUG, g_time, F("Abort"), id, btn ); #ifdef VERBOSE Serial.print( F(" Aborting ") ); Serial.print( code ); Serial.print( ' ' ); Serial.println( g_code ); #endif } code = g_code; cnt = 0; } else if( cnt++ > 1 ) { database::dbrecord rec; #ifdef VERBOSE Serial.print(' '); Serial.print( id ); #endif updatedt(dtupdated); g_db.getParams( id, rec ); bool enabled(rec.enabled()); g_display.updatedt(g_time, 0xff, true); //TODO: time validity g_display.updatelastdecision( enabled ? '+' : 'X', id ); g_outputs.set( inner ? PIN_IN_YELLOW : PIN_OUT_YELLOW, RELAY_OFF ); g_outputs.set( enabled? (inner ? PIN_IN_GREEN : PIN_OUT_GREEN) : (inner ? PIN_IN_RED : PIN_OUT_RED), RELAY_ON ); unsigned long timeout; if( enabled ) { g_logger.log( logwriter::INFO, g_time, F("Ack"), id, btn ); #ifdef VERBOSE Serial.println(F(" -> opening gate.")); #endif g_outputs.set( PIN_GATE, RELAY_ON ); delay(1000); g_outputs.set( PIN_GATE, RELAY_OFF ); timeout = 60000; } else { g_logger.log( logwriter::INFO, g_time, F("Deny"), id, btn ); #ifndef ENFORCE_REG g_outputs.set( PIN_GATE, RELAY_ON ); delay(1000); g_outputs.set( PIN_GATE, RELAY_OFF ); #endif // __HARD__ #ifdef VERBOSE Serial.println(F(" -> ignoring.")); #endif timeout = 10000; } inductiveloop::STATUS ilstmp(ils); bool conflicttmp(conflict); unsigned long waitstart(millis()); while(conflict == conflicttmp && ils == ilstmp && millis()-waitstart < timeout ) conflicttmp = g_loop.update(ilstmp); updateloopstatus(ilstmp, conflicttmp ); if(enabled) { g_outputs.set(inner ? PIN_IN_GREEN : PIN_OUT_GREEN, RELAY_OFF); if(ilstmp != inductiveloop::NONE) g_outputs.set(inner ? PIN_IN_RED : PIN_OUT_RED, RELAY_ON); } while(ilstmp != inductiveloop::NONE && millis()-waitstart < timeout ) conflicttmp = g_loop.update(ilstmp); updateloopstatus(ilstmp, conflicttmp); g_outputs.set( PIN_IN_RED, RELAY_OFF ); g_outputs.set( PIN_OUT_RED, RELAY_OFF ); previls = inductiveloop::NONE; prevconflict = false; cnt = 0; } #ifdef VERBOSE else { if(cnt == 1) Serial.print(CMNT); Serial.print(id); Serial.print('.'); } #endif // VERBOSE g_codeready = false; } if( g_codedisplayed != g_lrcode ) { updatedt(dtupdated); g_display.updatelastreceivedid( getid( g_lrcode )); g_logger.log( logwriter::DEBUG, g_time, F("NewCode"), getid(g_lrcode)); g_codedisplayed = g_lrcode; } }
int main (int argc, char **argv) { Tobj co; Psrc_t src; #ifdef MTRACE extern int Mt_certify; Mt_certify = 1; #endif #ifdef STATS stime = time (NULL); #endif idlerunmode = 0; exprstr = NULL; fp = NULL; init (argv[0]); Minit (GFXprune); Ginit (); FD_SET (Gxfd, &inputfds); Eerrlevel = 1; Estackdepth = 2; Eshowbody = 1; Eshowcalls = 1; processstr (leftyoptions); argv++, argc--; processargs (argc, argv); if (setjmp (exitljbuf)) goto eop; Cinit (); IOinit (); Tinit (); Pinit (); Einit (); Sinit (); Dinit (); Iinit (); TXTinit (txtcoords); GFXinit (); #ifdef FEATURE_GMAP gmapon = TRUE, G2Linit (); #endif if (exprstr) { src.flag = CHARSRC, src.s = exprstr, src.fp = NULL; src.tok = -1, src.lnum = 1; while ((co = Punit (&src))) Eunit (co); } if (fp) { src.flag = FILESRC, src.s = NULL, src.fp = fp; src.tok = -1, src.lnum = 1; while ((co = Punit (&src))) Eunit (co); } if (endflag) goto eop; TXTupdate (); Gneedredraw = FALSE; for (;;) { if (Gneedredraw) GFXredraw (), Gneedredraw = FALSE; if (Gbuttonsdown > 0) { GFXmove (), Gprocessevents (FALSE, G_ONEEVENT); processinput (FALSE); } else { if (Mcouldgc) { if (!processinput (FALSE)) Mdogc (M_GCINCR); } if (idlerunmode) { if (!processinput (FALSE)) GFXidle (); #ifdef FEATURE_GMAP } else if (GMAPneedupdate) { processinput (FALSE); #endif } else processinput (TRUE); } #ifdef FEATURE_GMAP if (gmapon) GMAPupdate (); #endif if (Erun) TXTupdate (), Erun = FALSE; } eop: #ifdef PARANOID #ifdef FEATURE_GMAP if (gmapon) G2Lterm (); #endif GFXterm (); TXTterm (); Iterm (); Dterm (); Sterm (); Eterm (); Pterm (); Tterm (); IOterm (); Cterm (); Gterm (); Mterm (); FD_CLR (Gxfd, &inputfds); term (); #endif printusage (); return 0; }
int APIENTRY WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow ) { Tobj co; Psrc_t src; hinstance = hInstance; hprevinstance = hPrevInstance; idlerunmode = 0; exprstr = NULL; fp = NULL; init (NULL); Ginit (); #ifndef FEATURE_MS FD_SET (Gxfd, &inputfds); #endif Eerrlevel = 1; Estackdepth = 2; Eshowbody = 1; Eshowcalls = 1; processstr (leftyoptions); __argv++, __argc--; processargs (__argc, __argv); if (setjmp (exitljbuf)) goto eop; Cinit (); IOinit (); Minit (GFXprune); Tinit (); Pinit (); Einit (); Sinit (); Dinit (); Iinit (); TXTinit (txtcoords); GFXinit (); if (exprstr) { src.flag = CHARSRC, src.s = exprstr, src.fp = NULL; src.tok = -1, src.lnum = 1; while ((co = Punit (&src))) Eunit (co); } if (fp) { src.flag = FILESRC, src.s = NULL, src.fp = fp; src.tok = -1, src.lnum = 1; while ((co = Punit (&src))) Eunit (co); } if (endflag) goto eop; TXTupdate (); Gneedredraw = FALSE; for (;;) { if (Gneedredraw) GFXredraw (), Gneedredraw = FALSE; if (Gbuttonsdown > 0) GFXmove (), Gprocessevents (FALSE, G_ONEEVENT); else { if (Mcouldgc) { if (!processinput (FALSE)) Mdogc (M_GCINCR); } else if (idlerunmode) { if (!processinput (FALSE)) GFXidle (); } else processinput (TRUE); } if (Erun) TXTupdate (), Erun = FALSE; } eop: #ifdef PARANOID GFXterm (); TXTterm (); Iterm (); Dterm (); Sterm (); Eterm (); Pterm (); Tterm (); Mterm (); IOterm (); Cterm (); Gterm (); term (); #endif printusage (); exit (0); }