void callbox(byte my_floor) { byte rxmessage[PAYLOAD_SIZE]; // Received data payload static byte floor, direction; word distance; static byte flag_dist_init = 0; CANframe txframe; // Transmitted CAN frame floor = 0xFF; // Start at false floor direction = DIRECTION_STATIONARY; // Assume starting car direction is stationary if (!flag_dist_init){ dist_init(); flag_dist_init = 1; } if(SW1 && !sw1_pressed) { sw1_pressed = 1; button_up(my_floor); } if(SW2 && !sw2_pressed) { sw2_pressed = 1; button_down(my_floor); } if(!SW1) sw1_pressed = 0; if(!SW2) sw2_pressed = 0; runSerialCAN(MSCAN_NODE_ID); if(data_available()) { CANget(rxmessage); switch(rxmessage[0]) { case CMD_LOCATION: floor = rxmessage[1]; direction = rxmessage[2]; #ifdef USE_LCD LCDclear(); LCDprintf("Floor: %d\nDir: %d", floor, direction); #endif #ifdef USE_LED7 led7_write(led7_table[floor]); #endif break; case CMD_BUTTON_CALL: rxmessage[1] == DIRECTION_UP ? button_up(my_floor) : button_down(my_floor); break; case CMD_ERROR: #ifdef USE_LCD LCDclear(); LCDprintf("Error condition\nreceived!"); #endif break; default: #ifdef USE_LCD LCDclear(); LCDputs("Unknown command"); #endif break; } // Turn off indicator LED once car has reached local floor if(floor == my_floor) { LED1 = 0; LED2 = 0; } } // Sonar sensor currently attached to callbox 1 // Send off distance message to controller node if (my_floor == FLOOR1) { distance = dist_read(); txframe.id = MSCAN_CTL_ID; txframe.priority = 0x01; txframe.length = 3; txframe.payload[0] = CMD_DISTANCE; txframe.payload[1] = (distance & 0xFF00) >> 8; txframe.payload[2] = (distance & 0x00FF); CANsend(&txframe); }
/* ** Animates a game until it is finished, and then cleans up allocated stuff. ** Returns final status of the game. */ int play_game() { unsigned int status; int i; Boolean newgame; if (num_combatants == 0) return GAME_FAILED; /* In an ultimate game, only reset at the beginning, since we want don't want scores to reset after every goal. */ if (settings.si.game == ULTIMATE_GAME) { init_combatants(); newgame = TRUE; } do { #ifdef X11 button_up(ANIM_WIN, FALSE); follow_mouse(ANIM_WIN, FALSE); #endif if (settings.si.game != ULTIMATE_GAME) { init_combatants(); newgame = TRUE; } if (setup_game(newgame) == GAME_FAILED) return GAME_FAILED; newgame = FALSE; game_running = True; #ifdef SOUND play_all(START_SOUND); #endif /*SOUND*/ do { status = animate(); } while (status == GAME_RUNNING); #ifdef SOUND play_all(END_SOUND); #endif /*SOUND*/ game_running = False; status = display_game_stats(status); game_cleanup(); /* nuking all the vehicles here is overkill */ } while (status == GAME_RESET); /* Unmap battle windows and clear all other windows on all the terminals */ for (i = 0; i < num_terminals; i++) { set_terminal(i); unmap_battle_windows(); clear_windows(); } /* Return to terminal 0 for the user interface */ set_terminal(0); #ifdef X11 button_up(ANIM_WIN, TRUE); follow_mouse(ANIM_WIN, TRUE); #endif return status; }