/* !!!! This function is designed for the controller !!!!! Purpose: Send out instructions from the elevator car node Input: Requests from the car node */ void Car(unsigned char sub_comp, unsigned char instruction) { static unsigned char data[DATA_LENGTH]; switch(sub_comp) { // Floor button case FLOOR_BUTTON: // From the elevator car node to the disance sensor /*data[0] = PID; data[1] = SET_POINT; data[2] = instruction; SCIprintf("%d%d%d", data[0], data[1], data[2]); (void)CANSend(PID, 0x00, 0x00, DATA_LENGTH, data);*/ // From the car back to the car data[0] = CAR; data[1] = BUTTON_INDICATOR_ON; data[2] = instruction; SCIprintf("%d%d%d", data[0], data[1], data[2]); (void)CANSend(CAR, 0x00, 0x00, DATA_LENGTH, data); switch(instruction) { case 3: LCDprintf("\nGo To: 1 \r",0); break; case 4: LCDprintf("\nGo To: 2 \r",0); break; case 5: LCDprintf("\nGo To: 3 \r",0); break; } break; case 1: data[0] = CAR; data[1] = 1; data[2] = instruction; SCIprintf("%d%d%d", data[0], data[1], data[2]); (void)CANSend(CAR, 0x00, 0x00, DATA_LENGTH, data); break; // E-Stop case E_STOP: break; } }
/* !!!! This function is designed for the controller !!!!! Purpose: To send the commands to each floor node as needed */ void Floor(unsigned char floor, unsigned char sub_comp, unsigned char instruction) { unsigned char data[DATA_LENGTH]; if(sub_comp == CALL_SWITCH1) { // Send led light so the user knows the car is coming data[0] = floor; data[1] = CALL_LED1; data[2] = ON; SCIprintf("%d%d%d", data[0], data[1], data[2]); (void)CANSend(floor, 0x00, 0x00, DATA_LENGTH, data); switch(floor) { case F1: LCDprintf("\nGo To: 1 \r",0); break; case F2: LCDprintf("\nGo To: 2 \r",0); break; case F3: LCDprintf("\nGo To: 3 \r",0); break; } data[0] = PID; data[1] = SET_POINT; data[2] = floor; SCIprintf("%d%d%d", data[0], data[1], data[2]); (void)CANSend(PID, 0x00, 0x00, DATA_LENGTH, data); } else if(sub_comp == CALL_SWITCH2) { data[0] = floor; data[1] = CALL_LED2; data[2] = ON; SCIprintf("%d%d%d", data[0], data[1], data[2]); (void)CANSend(floor, 0x00, 0x00, DATA_LENGTH, data); switch(floor) { case F1: LCDprintf("\nGo To: 1 \r",0); //dest_floor = F1; break; case F2: LCDprintf("\nGo To: 2 \r",0); break; case F3: LCDprintf("\nGo To: 3 \r",0); break; } data[0] = PID; data[1] = SET_POINT; data[2] = floor; SCIprintf("%d%d%d", data[0], data[1], data[2]); (void)CANSend(PID, 0x00, 0x00, DATA_LENGTH, data); } }
void button_down(byte my_floor) { CANframe txframe; LED2 = 1; #ifdef USE_LCD LCDclear(); LCDprintf("Floor: %d\nDir: %s", my_floor, "down"); #endif // Message to controller; down button pressed txframe.id = MSCAN_CTL_ID; txframe.priority = 0x01; txframe.length = 3; txframe.payload[0] = CMD_BUTTON_CALL; txframe.payload[1] = my_floor; txframe.payload[2] = BUTTON_DOWN; CANsend(&txframe); }
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); }
/* * Elevator car functionality * - */ void car(void) { byte ret; byte sw1_pressed = 0, sw2_pressed = 0; char *command, *floor, *direction; byte cur_floor; byte elevatorDirection = 0xFF; CANframe txframe; // Transmitted CAN frames byte rxmessage[PAYLOAD_SIZE]; // Received data payload cur_floor = 0; // Message to controller; floor 1 txframe.id = MSCAN_CTL_ID; txframe.priority = 0x01; txframe.length = 2; txframe.payload[0] = CMD_BUTTON_CAR; txframe.payload[2] = DIRECTION_STATIONARY; if(BTN_FLOOR1) { if (BUTTON_FL1 > cur_floor) { elevatorDirection = DIRECTION_DOWN; } else if (BUTTON_FL1 < cur_floor) { elevatorDirection = DIRECTION_UP; } else { elevatorDirection = DIRECTION_STATIONARY; } txframe.payload[1] = BUTTON_FL1; txframe.payload[2] = elevatorDirection; ret = CANsend(&txframe); if(ret) { // Message could not be sent! } } if(BTN_FLOOR2) { if (BUTTON_FL2 > cur_floor) { elevatorDirection = DIRECTION_DOWN; } else if (BUTTON_FL2 < cur_floor) { elevatorDirection = DIRECTION_UP; } else { elevatorDirection = DIRECTION_STATIONARY; } txframe.payload[1] = BUTTON_FL2; txframe.payload[2] = elevatorDirection; ret = CANsend(&txframe); if(ret) { // Message could not be sent! } } if(BTN_FLOOR3) { if (BUTTON_FL3 > cur_floor) { elevatorDirection = DIRECTION_DOWN; } else if (BUTTON_FL3 < cur_floor) { elevatorDirection = DIRECTION_UP; } else { elevatorDirection = DIRECTION_STATIONARY; } txframe.payload[1] = BUTTON_FL3; txframe.payload[2] = elevatorDirection; ret = CANsend(&txframe); if(ret) { // Message could not be sent! } } if(BTN_DROPEN) { txframe.payload[1] = BUTTON_DOOR_OPEN; txframe.payload[2] = elevatorDirection; ret = CANsend(&txframe); if(ret) { // Message could not be sent! } } if(BTN_DRCLOSE) { txframe.payload[1] = BUTTON_DOOR_CLOSE; txframe.payload[2] = elevatorDirection; ret = CANsend(&txframe); if(ret) { // Message could not be sent! } } if(BTN_ESTOP) { txframe.payload[1] = BUTTON_STOP; txframe.payload[2] = elevatorDirection; ret = CANsend(&txframe); if(ret) { // Message could not be sent! } } // CAN bus <-> serial link // Check for new incoming messages and send out received messages via serial runSerialCAN(MSCAN_NODE_ID); if(data_available()) { CANget(rxmessage); switch(rxmessage[0]) { case CMD_LOCATION: command = "Loc"; break; case CMD_BUTTON_CALL: command = "Call"; break; case CMD_BUTTON_CAR: command = "Car"; break; case CMD_DISP_APPEND: command = "Disp"; break; case CMD_ERROR: command = "Err"; break; default: // Command didn't match known commands! goto car_cmd_error; } switch(rxmessage[1]) { case FLOOR1: floor = "1"; cur_floor = 1; break; case FLOOR2: floor = "2"; cur_floor = 2; break; case FLOOR3: floor = "3"; cur_floor = 3; break; default: // Command didn't match known commands! goto car_cmd_error; } // Turn off LED when car arrives at requested floor if ( rxmessage[0] == CMD_LOCATION ) { if( rxmessage[1] == FLOOR1 ) { LED1 = 0; } if( rxmessage[1] == FLOOR2 ) { LED2 = 0; } /*if( rxmessage[1] == FLOOR3 ) { LED3 = 0; }*/ } #ifdef USE_LED7 led7_write(led7_table[cur_floor]); #endif #ifdef USE_LCD LCDhome(); LCDclear(); LCDprintf("Command: %s\nFloor%s", command, floor); #endif return; car_cmd_error: //LCDhome(); //LCDclear(); //LCDprintf("Error in\ncommand"); return; } }
/* * Controller functionality * - Send elevator location messages to callboxes * - Listen for button press messages */ void controller() { byte sw1_pressed = 0, sw2_pressed = 0; byte rxmessage[PAYLOAD_SIZE]; // Received data payload byte button_pressed; byte next_floor; char *button_floor_str, *button_direction_str; byte update_lcd = 1; byte cycle_count = 0; word distance; // car height in cm, distance measurement in mm byte cur_floor; byte last_floor = 0; //byte b; // used for debug manual frame sending testing dist_init(); mctrl_init(); // Initialize servo motor controller for(;;) { mctrl_update(); cycle_count++; if ( cycle_count == 10 ) { update_lcd = 1; cycle_count = 0; } if ( update_lcd ) { update_lcd = 0; /* #ifdef USE_LCD if ( cur_floor == 0 ) { LCDclear(); LCDputs("No car"); } else { LCDclear(); LCDprintf("%dmm/F%d", car_height, cur_floor); } #endif */ } // CAN bus <-> serial link // Check for new incoming messages and send out received messages via serial runSerialCAN(MSCAN_NODE_ID); /* while ( sci_bytesAvailable() ) { sci_readByte(&b); lcd_putc(b); } */ if(data_available()) { CANget(rxmessage); switch(rxmessage[0]) { case CMD_BUTTON_CALL: button_pressed = rxmessage[1]; addToQueue(button_pressed); next_floor = peekNextFloor(); pid_setpoint(FLOOR2SETPOINT(next_floor)); switch(cur_floor) { case FLOOR1: button_floor_str = "1"; break; case FLOOR2: button_floor_str = "2"; break; case FLOOR3: button_floor_str = "3"; break; default: break; } if(next_floor == cur_floor) { button_direction_str = "stat"; } else if(next_floor > cur_floor) { button_direction_str = "up "; } else { button_direction_str = "down"; } #ifdef USE_LCD LCDhome(); LCDprintf("\nFloor%s Dir %s", button_floor_str, button_direction_str); #else #ifdef USE_LCD2 lcd_goto(0x10); // Start at second line lcd_puts("Floor"); lcd_puts(button_floor_str); lcd_puts(" Dir "); lcd_puts(button_direction_str); #endif #endif break; case CMD_BUTTON_CAR: button_pressed = rxmessage[1]; if(button_pressed == BUTTON_STOP) { // call emergency stop function } else if(button_pressed < BUTTON_DOOR_CLOSE) { addToQueue(button_pressed); } next_floor = peekNextFloor(); pid_setpoint(FLOOR2SETPOINT(next_floor)); switch(cur_floor) { case FLOOR1: button_floor_str = "1"; break; case FLOOR2: button_floor_str = "2"; break; case FLOOR3: button_floor_str = "3"; break; default: break; } if(next_floor == cur_floor){ button_direction_str = "stat"; }else if(next_floor > cur_floor){ button_direction_str = "up "; }else { button_direction_str = "down"; } #ifdef USE_LCD LCDhome(); LCDprintf("\nFloor%s Dir %s", button_floor_str, button_direction_str); #endif #ifdef USE_LCD2 lcd_goto(0x10); // Start at second line lcd_puts("Floor"); lcd_puts(button_floor_str); lcd_puts(" Dir "); lcd_puts(button_direction_str); #endif break; case CMD_DISTANCE: distance = (rxmessage[1] << 8) | rxmessage[2]; pid_feedback(distance); if (distance < SETPOINT_F1 + FLOOR_MARGIN) cur_floor = FLOOR1; if (distance > SETPOINT_F2 - FLOOR_MARGIN && distance < SETPOINT_F2 + FLOOR_MARGIN) cur_floor = FLOOR2; if (distance > SETPOINT_F3 - FLOOR_MARGIN && distance < SETPOINT_F3 + FLOOR_MARGIN) cur_floor = FLOOR3; if ( distance > 1500 ) { cur_floor = 0; #ifdef USE_LED7 led7_write(led7_bars[1]); #endif } else { #ifdef USE_LED7 led7_write(led7_table[cur_floor]); #endif if ( cur_floor != last_floor ) { update_floor(cur_floor); last_floor = cur_floor; // if we have reached the target floor, pop off the top of the queue // TODO: change name of getNextFloor() to be more descriptive if(cur_floor == next_floor){ getNextFloor(); next_floor = peekNextFloor(); pid_setpoint(FLOOR2SETPOINT(next_floor)); } } } #ifdef USE_LCD LCDhome(); LCDprintf("Dist: %4d", distance); #endif break; case CMD_ERROR: break; default: #ifdef USE_LCD LCDclear(); LCDputs("\nUnknown command"); #endif #ifdef USE_LCD2 lcd_goto(0x10); // Start at second line lcd_puts("Unknown command"); #endif break; } } delay_ms(100); } }
void main(void) { char i, j; unsigned char txbuff[8] = ""; word distance = 0; CANMessage message = { 0x00, 0x00, 0x00, {0}}; unsigned char curFloor = 0; unsigned char elevatorDirection = 0; unsigned char callButtonsPressed[2][NUM_FLOORS] = { 0 }; unsigned char panelButtonsPressed[NUM_FLOORS] = { 0 }; unsigned char panicButton = 0; unsigned char elevatorTarget = 0; unsigned char targetFound = 0; timer_init(); LCDinit(); initCan(); j=0; while (!(CANCTL0 & 0x10)); CANRFLG = 0xC3; CANRIER = 0x01; //LCDprintf("Hello World"); usonic_init(); EnableInterrupts; for(;;) { LCDclear(); //get elevator distance distance = usonic_getDistance(); //generalized for NUM_FLOORS, for a given floor offset to the ground floor, and distance between floors (left in big if statement in case //distance between floors is non-constant for(i=0; i< NUM_FLOORS; i++){ if (distance < (FLOOR_OFFSET + (FLOOR_DISTANCE*i) + ELEV_THRESHOLD) && distance > (FLOOR_OFFSET + (FLOOR_DISTANCE*i) - ELEV_THRESHOLD)) { //LCDprintf("1st Floor!\n %d mm", distance); curFloor = i+1; } } /*if (distance < (ELEV_1ST + ELEV_THRESHOLD) && distance > (ELEV_1ST - ELEV_THRESHOLD)) { //LCDprintf("1st Floor!\n %d mm", distance); curFloor = 1; } else if (distance < (ELEV_2ND + ELEV_THRESHOLD) && distance > (ELEV_2ND - ELEV_THRESHOLD)) { //LCDprintf("2nd Floor!\n %d mm", distance); curFloor = 2; } else if (distance < (ELEV_3RD + ELEV_THRESHOLD) && distance > (ELEV_3RD - ELEV_THRESHOLD)) { //LCDprintf("3rd Floor!\n %d mm", distance); curFloor = 3; } else if (distance < (ELEV_4TH + ELEV_THRESHOLD) && distance > (ELEV_4TH - ELEV_THRESHOLD)) { //LCDprintf("4th Floor!\n %d mm", distance); curFloor = 4; } else { //LCDprintf("Distance %d mm", distance); } */ if (elevatorTarget != curFloor) { if ((elevatorTarget - curFloor) > 0 ) { elevatorDirection = DIR_UP; } else { elevatorDirection = DIR_DOWN; } txbuff[0] = ELEV_LOCATION; txbuff[1] = curFloor; txbuff[2] = elevatorDirection; message.id = ELEVATOR_CAR_ID | FLOOR_1_ID | FLOOR_2_ID | FLOOR_3_ID; message.priority = 0x00; message.length = 8; message.payload = txbuff; } else { //elevatorTarget = curFloor, which means elevator is stationary //elevatorDirection = DIR_STOPPED; //set direction to stationary txbuff[0] = ELEV_LOCATION; txbuff[1] = curFloor; txbuff[2] = elevatorDirection; message.id = ELEVATOR_CAR_ID | FLOOR_1_ID | FLOOR_2_ID | FLOOR_3_ID; message.priority = 0x00; message.length = 8; message.payload = txbuff; panelButtonsPressed[curFloor-1] = 0; //clear the panel floor button as we have reached the destination floor targetFound = 0; //clear the target found flag to find a new target } /* j = (j+1) %3; txbuff[0] = ELEV_LOCATION; txbuff[1] = j+1; txbuff[2] = DIR_UP; message.id = BROADCAST_ID; //Broadcast message.priority = 0; message.length = 8; message.payload = txbuff;*/ sendCanFrame(message); if ( canRXFlag ) //have received a message from one of the various floor buttons, receive message and enter it into the required motor output. { if (canRXData[0] == CALL_BTN_PRESS){ if(canRXData[2] == UP_CALL_BTN){ callButtonsPressed[UP_CALL_ROW][canRXData[1]-1] = 1; LCDprintf("Call FLOOR %d Up", canRXData[1]); }else { callButtonsPressed[DOWN_CALL_ROW][canRXData[1]-1] = 1; LCDprintf("Call FLOOR %d Down", canRXData[1]); } } else if (canRXData[0] == PANEL_BTN_PRESS){ switch (canRXData[1]){ case PANEL_FLOOR_1:{ panelButtonsPressed[0] = 1; LCDprintf("Car FLOOR %d", canRXData[1]); break; } case PANEL_FLOOR_2:{ panelButtonsPressed[1] = 1; LCDprintf("Car FLOOR %d", canRXData[1]); break; } case PANEL_FLOOR_3:{ panelButtonsPressed[2] = 1; LCDprintf("Car FLOOR %d", canRXData[1]); break; } case PANEL_FLOOR_4:{ panelButtonsPressed[3] = 1; break; } case DOOR_CLOSE:{ LCDprintf("Door Close"); break; } case DOOR_OPEN:{ LCDprintf("Door Open"); break; } case EMERG_STOP:{ panicButton = 1; break; } default: break; } } else if (canRXData[0] == ELEV_LOCATION){ LCDprintf("floor %d dir %d", canRXData[1], canRXData[2]); } else if (canRXData[0] == ERROR_MSG){ } //else ignore message //LCDprintf("Floor %d!\n %d mm", canRXData[0], distance); canRXFlag = 0; } /* //Logic to determine the current elevator target if (targetFound == 0) { elevatorTarget = curFloor; //set a back up target in case the target finding algorithm doesn't find any other targets if (elevatorDirection == DIR_UP){ //Elevator is currently moving up, handle any up requests above elevator before moving down for(i=curFloor-1; i< NUM_FLOORS; i++){ if(callButtonsPressed[UP_CALL_ROW][i] || panelButtonsPressed[i]){ callButtonsPressed[UP_CALL_ROW][i] = 0; panelButtonsPressed[i] = 0; elevatorTarget = i+1; targetFound = 1; break; } } if (targetFound == 0) { //No up requests above elevator current position, service any down requests, from the top floor first for(i = NUM_FLOORS; i >= 0; i--){ if(callButtonsPressed[DOWN_CALL_ROW][i] || panelButtonsPressed[i]){ callButtonsPressed[DOWN_CALL_ROW][i] = 0; panelButtonsPressed[i] = 0; elevatorTarget = i+1; targetFound = 1; break; } } if(targetFound == 0){ //no down requests found, service any up requests below the elevator's current floor for(i=0; i< curFloor-1; i++){ if(callButtonsPressed[UP_CALL_ROW][i]){ callButtonsPressed[UP_CALL_ROW][i] = 0; elevatorTarget = i+1; targetFound = 1; break; } } } } } else if (elevatorDirection == DIR_DOWN){ //Elevator currently moving down, handle any down requests below the elevator before moving back up for (i=curFloor-1; i >= 0; i--){ if(callButtonsPressed[DOWN_CALL_ROW][i] || panelButtonsPressed[i]){ callButtonsPressed[DOWN_CALL_ROW][i] = 0; panelButtonsPressed[i] = 0; elevatorTarget = i + 1; targetFound = 1; break; } } if (targetFound == 0) { //No down requests below elevator current position, service any up requests, from the bottom floor first for(i = 0; i < NUM_FLOORS; i++){ if(callButtonsPressed[UP_CALL_ROW][i] || panelButtonsPressed[i]){ callButtonsPressed[UP_CALL_ROW][i] = 0; panelButtonsPressed[i] = 0; elevatorTarget = i+1; targetFound = 1; break; } } if(targetFound == 0){ //no up requests found, service any down requests above the elevator's current floor for(i=NUM_FLOORS; i >= curFloor-1; i--){ if(callButtonsPressed[DOWN_CALL_ROW][i]){ callButtonsPressed[DOWN_CALL_ROW][i] = 0; elevatorTarget = i+1; targetFound = 1; break; } } } } } }*/ if(panicButton){ LCDprintf("EMERGENCY!"); }/* else if(targetFound){ LCDprintf("target floor: %d!", elevatorTarget); } else { LCDprintf("No target"); } */ msleep(100); } }
/* * Controller functionality * - Send elevator location messages to callboxes * - Listen for button press messages */ void controller(void) { byte ret; byte sw1_pressed = 0, sw2_pressed = 0; char *command, *floor, *direction; CANframe txframe; // Transmitted CAN frame byte rxmessage[PAYLOAD_SIZE]; // Received data payload if(SW1 && !sw1_pressed) { sw1_pressed = 1; LED1 = 1; // Message to floor 1 callbox; direction up txframe.id = MSCAN_FL1_ID; txframe.priority = 0x01; txframe.length = 3; txframe.payload[0] = CMD_LOCATION; txframe.payload[1] = FLOOR1; txframe.payload[2] = DIRECTION_UP; ret = CANsend(&txframe); if(ret) { // Message could not be sent! } } if(SW2 && !sw2_pressed) { sw2_pressed = 1; LED2 = 1; // Message to floor 1 callbox; direction down txframe.id = MSCAN_FL1_ID; txframe.priority = 0x01; txframe.length = 3; txframe.payload[0] = CMD_LOCATION; txframe.payload[1] = FLOOR1; txframe.payload[2] = DIRECTION_DOWN; ret = CANsend(&txframe); if(ret) { // Message could not be sent! } } if(!SW1) { sw1_pressed = 0; LED1 = 0; } if(!SW2) { sw2_pressed = 0; LED2 = 0; } if(data_available()) { CANget(rxmessage); switch(rxmessage[0]) { case CMD_BUTTON_CALL: command = "Call"; break; case CMD_BUTTON_CAR: command = "Car"; break; case CMD_DISP_APPEND: command = "Disp"; break; case CMD_ERROR: command = "Err"; break; default: // Command didn't match known commands! goto cmd_error; } switch(rxmessage[1]) { case FLOOR1: floor = "1"; break; case FLOOR2: floor = "2"; break; case FLOOR3: floor = "3"; break; default: // Command didn't match known commands! goto cmd_error; } switch(rxmessage[2]) { case BUTTON_UP: direction = "Up"; break; case BUTTON_DOWN: direction = "Down"; break; default: // Command didn't match known commands! goto cmd_error; } LCDclear(); LCDprintf("Command: %s\nFloor%s Dir: %s", command, floor, direction); return; cmd_error: LCDclear(); LCDprintf("Error in\ncommand"); } }
/* * Callbox functionality * - Listen for button presses, and accept elevator location messages */ void callbox(byte my_floor) { byte ret; byte sw1_pressed = 0, sw2_pressed = 0; CANframe txframe; // Transmitted CAN frame byte rxmessage[PAYLOAD_SIZE]; // Received data payload static byte floor, direction; floor = my_floor; // Assume starting floor is at this callbox floor direction = DIRECTION_STATIONARY; // Assume starting car direction is stationary if(SW1 && !sw1_pressed) { sw1_pressed = 1; LED1 = 1; // Message to controller; up button pressed txframe.id = MSCAN_CTL_ID; txframe.priority = 0x01; txframe.length = 3; txframe.payload[0] = CMD_BUTTON_CALL; txframe.payload[1] = my_floor; txframe.payload[2] = BUTTON_UP; ret = CANsend(&txframe); if(ret) { // Message could not be sent! } } if(SW2 && !sw2_pressed) { sw2_pressed = 1; LED2 = 1; // Message to controller; down button pressed txframe.id = MSCAN_CTL_ID; txframe.priority = 0x01; txframe.length = 3; txframe.payload[0] = CMD_BUTTON_CALL; txframe.payload[1] = my_floor; txframe.payload[2] = BUTTON_DOWN; ret = CANsend(&txframe); if(ret) { // Message could not be sent! } } if(!SW1 && (floor == my_floor)) sw1_pressed = 0; if(!SW2 && (floor == my_floor)) sw2_pressed = 0; if(data_available()) { CANget(rxmessage); switch(rxmessage[0]) { case CMD_LOCATION: floor = rxmessage[1]; direction = rxmessage[2]; break; case CMD_ERROR: // Error condition received! break; default: // Command didn't match known commands! break; } LCDclear(); LCDprintf("Floor: %s\nDir: %s", floor, direction); } }