static void setupkeys(void) { options.UP=getbutton ("Press Up"); options.DOWN=getbutton ("Press Down"); options.LEFT=getbutton ("Press Left"); options.RIGHT=getbutton ("Press Right"); options.A=getbutton ("Press A"); options.B=getbutton ("Press B"); options.START=getbutton ("Press Start"); options.SELECT=getbutton("Press Select"); options.MENU=getbutton ("Press Menu"); }
void backTrack (void *v, int device, int mouseDown) { pWmj cW = (pWmj)v, pW = cW->prev; /* WmjAct *Ap = (device == LEFTMOUSE ? cW->lefMouse : cW->midMouse); */ pDmj cD = &cW->D; long bxA, byA, nxA, nyA, oxA,oyA, wx,ww,wy,wh; long widA = winget(); if (! mouseDown) return; getorigin(&wx,&wy); getsize( &ww,&wh); ww -= 1; wh -= 1; oxA = bxA = (getvaluator(MOUSEX) - wx); oyA = byA = (getvaluator(MOUSEY) - wy); cursoff(); drawmode(OVERDRAW); while(getbutton(device)) { nxA = getvaluator(MOUSEX) - wx; if (nxA < 0) nxA = 0; else if (nxA > ww) nxA = ww; nyA = getvaluator(MOUSEY) - wy; if (nyA < 0) nyA = 0; else if (nyA > wh) nyA = wh; if (nxA != oxA || nyA != oyA) { /* winset(widA); */ color(BLACK); /* black erases */ sboxi(bxA,byA,oxA,oyA); /* NB: sbox is faster than rect, but less flex */ color(RED); /* set color of new circle */ sboxi(bxA,byA,nxA,nyA); oxA = nxA, oyA = nyA; } } color(BLACK); sboxi(bxA,byA,oxA,oyA); drawmode(NORMALDRAW); cpack(FcGRN); sboxi(bxA,byA,nxA,nyA); if (pW) { pDmj pD = &pW->D; flt pzX = pW->zX, zX = pzX/cW->zX; flt pzY = pW->zY, zY = pzY/cW->zY; long L = cD->l*pzX, B = cD->b*pzY; wrn("bT: id: %d pD->lb: %3d %3d zXY: %.1f %.1f", pW->id, pD->l, pD->b, zX, zY); wrn("bT: id: %d cD->lb: %3d %3d czXY: %.1f %.1f", cW->id, cD->l, cD->b,cW->zX,cW->zY); winset(pW->id); drawmode(OVERDRAW); color(YELLOW); sboxi(L + bxA*zX, B + byA*zY, L + oxA*zX, B + oyA*zY); drawmode(NORMALDRAW); } winset(widA); curson(); }
void rubberRectZoid (void *v, int device, int mouseDown) { static WmjAct backAct; pWmj cW = (pWmj)v; WmjAct *Ap = (device == LEFTMOUSE ? cW->lefMouse : cW->midMouse); /* Tetra *trp = Ap->data; */ flt zX = cW->zX, zY = cW->zY; long bxA, byA, nxA, nyA, oxA,oyA, wx,ww,wy,wh; long widA = winget(); if (! mouseDown) return; getorigin(&wx,&wy); getsize( &ww,&wh); ww -= 1; wh -= 1; oxA = bxA = (getvaluator(MOUSEX) - wx); oyA = byA = (getvaluator(MOUSEY) - wy); cursoff(); drawmode(OVERDRAW); while(getbutton(device)) { nxA = getvaluator(MOUSEX) - wx; if (nxA < 0) nxA = 0; else if (nxA > ww) nxA = ww; nyA = getvaluator(MOUSEY) - wy; if (nyA < 0) nyA = 0; else if (nyA > wh) nyA = wh; if (nxA != oxA || nyA != oyA) { winset(widA); color(BLACK); /* black erases */ sboxi(bxA,byA,oxA,oyA); color(RED); /* set color of new circle */ sboxi(bxA,byA,nxA,nyA); oxA = nxA, oyA = nyA; } } color(BLACK); sboxi(bxA,byA,oxA,oyA); drawmode(NORMALDRAW); cpack(FcGRN); sboxi(bxA,byA,nxA,nyA); if (bxA > nxA) nxA = bxA, bxA = oxA; if (byA > nyA) nyA = byA, byA = oyA; wrn("rubberRectZ B4 showSub: %4d %4d %4d %4d zX:%.2f zY:%.2f",bxA,byA,nxA,nyA, zX, zY); backAct = *Ap; backAct.func = &testChain; cW->next = showSub(cW, bxA/zX,byA/zY,nxA/zX,nyA/zY,"subA",zX*2.0,zY*2.0,5); cW->next->lefMouse = &backAct; cW->next->prev = cW; winset(widA); curson(); }
void loop() { static uint16_t code(0); static uint8_t cnt(0); if( g_codeready ) { uint16_t id( getid( g_code )); uint8_t btn( getbutton( g_code )); if( code != g_code ) { if( cnt ) { Serial.print( F("Aborting ") ); Serial.print( code ); Serial.print( ' ' ); Serial.println( g_code ); } code = g_code; cnt = 0; } else if( cnt++ > 1 ) { Serial.print( id ); Serial.print(F(", ")); Serial.println((uint16_t) btn ); g_lcd.setCursor(0,0); if(id < 10 ) g_lcd.print(' '); if(id < 100 ) g_lcd.print(' '); if(id < 1000 ) g_lcd.print(' '); g_lcd.print( id ); g_lcd.print('.'); g_lcd.print( getbutton( g_code ) ); cnt = 0; } else Serial.print('.'); g_codeready = false; } }
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; } }
void main() { short val; int menu, pres; float p, mx, my; curmass = 0.5; curdrag = 0.15; prefsize(800,640); initbuzz(); winopen("dynadraw"); glcompat(GLC_OLDPOLYGON,1); subpixel(1); shademodel(FLAT); gconfig(); qdevice(LEFTMOUSE); qdevice(MIDDLEMOUSE); qdevice(MENUBUTTON); qdevice(RIGHTSHIFTKEY); qdevice(UPARROWKEY); qdevice(DOWNARROWKEY); qdevice(RIGHTSHIFTKEY); makeframe(); menu = defpup("dynadraw %t|toggle line style|save PostScript"); width = initwidth; mouse.fixedangle = 1; while(1) { switch(qread(&val)) { case REDRAW: makeframe(); break; case MIDDLEMOUSE: if(val) clearscreen(); break; case UPARROWKEY: if(val) initwidth *= 1.414213; width = initwidth; break; case DOWNARROWKEY: if(val) initwidth /= 1.414213; width = initwidth; break; case MENUBUTTON: if(val) { switch(dopup(menu)) { case 1: mouse.fixedangle = 1-mouse.fixedangle; break; case 2: savepolys(); break; } } break; case LEFTMOUSE: if(val) { my = getmousey(); if(my>0*SLIDERHIGH && my<2*SLIDERHIGH) { if(my>SLIDERHIGH) { while(getbutton(LEFTMOUSE)) { p = paramval(); if(p != curmass) { curmass = p; showsettings(); } } } else { while(getbutton(LEFTMOUSE)) { p = paramval(); if(p != curdrag) { curdrag = p; showsettings(); } } } } else { mx = 1.25*fgetmousex(); my = fgetmousey(); filtersetpos(&mouse,mx,my); odelx = 0.0; odely = 0.0; while(getbutton(LEFTMOUSE)) { mx = 1.25*fgetmousex(); my = fgetmousey(); if(filterapply(&mouse,mx,my)) { drawsegment(&mouse); color(0); buzz(); } } } } break; } } }
void NETHER::draw_status(void) { /* Clear the color and depth buffers. */ glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); /* Draw buttons: */ { List<STATUSBUTTON> l; STATUSBUTTON *b; float angle,cf; l.Instance(buttons); l.Rewind(); while(l.Iterate(b)) { if (b->status>=-16) { angle=(float(b->status)*90.0)/16.0; cf=float((16-abs(b->status)))/16.0; glPushMatrix(); glTranslatef(b->x,b->y,0); glRotatef(angle,0,1,0); /* Draw button: */ glColor3f(b->r*cf,b->g*cf,b->b*cf); glutSolidBox(b->sx/2,b->sy/2,10.0); glTranslatef(0,0,11); glColor3f(1.0,1.0,1.0); if (b->text1[0]!=0) { if (b->text2[0]!=0) { glTranslatef(0,-12,0); scaledglprintf(0.1f,0.1f,b->text2); glTranslatef(0,17,0); scaledglprintf(0.1f,0.1f,b->text1); } else { glTranslatef(0,-3,0); scaledglprintf(0.1f,0.1f,b->text1); } /* if */ } /* if */ glPopMatrix(); } /* if */ } /* while */ } glPushMatrix(); switch(act_menu) { case GENERAL_MENU: { STATUSBUTTON *b; b=getbutton(STATUS_BUTTON); if (b!=0 && b->status==0) { statistics[0][7]=robots[0].Length(); statistics[1][7]=robots[1].Length(); glColor3f(0.5f,0.5f,1.0f); glTranslatef(70,356,0); scaledglprintf(0.1f,0.1f,"%i WARBASES %i",statistics[1][0],statistics[0][0]); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"%i ELECTR'S %i",statistics[1][1],statistics[0][1]); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"%i NUCLEAR %i",statistics[1][2],statistics[0][2]); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"%i PHASERS %i",statistics[1][3],statistics[0][3]); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"%i MISSILES %i",statistics[1][4],statistics[0][4]); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"%i CANNON %i",statistics[1][5],statistics[0][5]); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"%i CHASSIS %i",statistics[1][6],statistics[0][6]); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"%.2i ROBOTS %.2i",statistics[1][7],statistics[0][7]); glColor3f(0.0f,0.8f,0.0f); glTranslatef(0,-65,0); scaledglprintf(0.1f,0.1f,"GENERAL %.2i",resources[0][0]); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"ELECTR' %.2i",resources[0][1]); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"NUCLEAR %.2i",resources[0][2]); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"PHASERS %.2i",resources[0][3]); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"MISSILE %.2i",resources[0][4]); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"CANNON %.2i",resources[0][5]); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"CHASSIS %.2i",resources[0][6]); } /* if */ } break; case ROBOT_MENU: case DIRECTCONTROL_MENU: { STATUSBUTTON *b; b=getbutton(ROBOT1_BUTTON); if (b!=0 && b->status==0) { glTranslatef(70,140,0); glColor3f(1.0f,1.0f,0.0); scaledglprintf(0.1f,0.1f,"-ORDERS-"); glColor3f(0.5f,0.5f,1.0f); switch(controlled->program) { case PROGRAM_STOPDEFEND: glTranslatef(0,-20,0); scaledglprintf(0.1f,0.1f,"STOP"); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"AND"); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"DEFEND"); break; case PROGRAM_ADVANCE: glTranslatef(0,-20,0); scaledglprintf(0.1f,0.1f,"ADVANCE"); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"%.2i",controlled->program_parameter/2); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"MILES"); break; case PROGRAM_RETREAT: glTranslatef(0,-20,0); scaledglprintf(0.1f,0.1f,"RETREAT"); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"%.2i",controlled->program_parameter/2); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"MILES"); break; case PROGRAM_DESTROY: glTranslatef(0,-20,0); scaledglprintf(0.1f,0.1f,"DESTROY"); switch(controlled->program_parameter) { case P_PARAM_ROBOTS: glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"ENEMY"); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"ROBOTS"); break; case P_PARAM_WARBASES: glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"ENEMY"); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"WARBASES"); break; case P_PARAM_NFACTORIES: glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"NEUTRAL"); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"FACTORIES"); break; case P_PARAM_EFACTORIES: glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"ENEMY"); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"FACTORIES"); break; } /* switch */ break; case PROGRAM_CAPTURE: glTranslatef(0,-20,0); scaledglprintf(0.1f,0.1f,"CAPTURE"); switch(controlled->program_parameter) { case P_PARAM_ROBOTS: glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"ENEMY"); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"ROBOTS"); break; case P_PARAM_WARBASES: glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"ENEMY"); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"WARBASES"); break; case P_PARAM_NFACTORIES: glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"NEUTRAL"); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"FACTORIES"); break; case P_PARAM_EFACTORIES: glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"ENEMY"); glTranslatef(0,-18,0); scaledglprintf(0.1f,0.1f,"FACTORIES"); break; } /* switch */ break; } /* switch */ glTranslatef(0,-44,0); glColor3f(1.0f,1.0f,0.0); scaledglprintf(0.1f,0.1f,"STRENGTH"); glTranslatef(0,-18,0); glColor3f(1.0f,1.0f,1.0f); scaledglprintf(0.1f,0.1f,"%.3i%c",controlled->strength,'%'); } /* if */ } break; case COMBATMODE_MENU: case DIRECTCONTROL2_MENU: glTranslatef(70,40,0); glColor3f(1.0f,1.0f,0.0); scaledglprintf(0.1f,0.1f,"STRENGTH"); glTranslatef(0,-18,0); glColor3f(1.0f,1.0f,1.0f); scaledglprintf(0.1f,0.1f,"%.3i%c",controlled->strength,'%'); break; case ORDERS_MENU: { STATUSBUTTON *b; b=getbutton(ORDERS1_BUTTON); if (b!=0 && b->status==0) { glTranslatef(70,400,0); glColor3f(1.0f,1.0f,1.0f); scaledglprintf(0.1f,0.1f,"SELECT"); glTranslatef(0,-20,0); scaledglprintf(0.1f,0.1f,"ORDERS"); glTranslatef(0,-340,0); glColor3f(1.0f,1.0f,0.0); scaledglprintf(0.1f,0.1f,"STRENGTH"); glTranslatef(0,-18,0); glColor3f(1.0f,1.0f,1.0f); scaledglprintf(0.1f,0.1f,"%.3i%c",controlled->strength,'%'); } /* if */ } break; case SELECTDISTANCE_MENU: { STATUSBUTTON *b; b=getbutton(ORDERS_BUTTON); if (b!=0 && b->status==0) { glTranslatef(70,300,0); glColor3f(0.5f,0.5f,1.0f); scaledglprintf(0.1f,0.1f,"SELECT"); glTranslatef(0,-20,0); scaledglprintf(0.1f,0.1f,"DISTANCE"); glColor3f(1.0f,1.0f,0.0); glTranslatef(0,-40,0); scaledglprintf(0.1f,0.1f,"%.2i MILES",controlled->program_parameter/2); glTranslatef(0,-200,0); glColor3f(1.0f,1.0f,0.0); scaledglprintf(0.1f,0.1f,"STRENGTH"); glTranslatef(0,-18,0); glColor3f(1.0f,1.0f,1.0f); scaledglprintf(0.1f,0.1f,"%.3i%c",controlled->strength,'%'); } /* if */ } break; case TARGETD_MENU: case TARGETC_MENU: { STATUSBUTTON *b; b=getbutton(ORDERS_BUTTON); if (b!=0 && b->status==0) { glTranslatef(70,350,0); glColor3f(0.5f,0.5f,1.0f); scaledglprintf(0.1f,0.1f,"SELECT"); glTranslatef(0,-20,0); scaledglprintf(0.1f,0.1f,"TARGET"); glTranslatef(0,-290,0); glColor3f(1.0f,1.0f,0.0); scaledglprintf(0.1f,0.1f,"STRENGTH"); glTranslatef(0,-18,0); glColor3f(1.0f,1.0f,1.0f); scaledglprintf(0.1f,0.1f,"%.3i%c",controlled->strength,'%'); } /* if */ } break; } /* switch */ glPopMatrix(); } /* NETHER::draw_status */