Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 277 → Rev 278

/PIC Stuff/Cerebot_32MX7_LED_Cube/CONTROLLERS.c
24,6 → 24,7
}
 
ctrl_data_p->connected_count = 0x0;
ctrl_data_p->next_poll = 0x0;
 
// Poll to see which controllers are connected
Controller_Poll_Connected();
48,7 → 49,7
}
 
// A small delay is needed between polls
Delay_MS(1);
Delay_US(500);
}
 
// Show the number of controllers connected
64,36 → 65,38
 
void Controller_Update(void) {
uint8_t buffer[2];
uint8_t result, length, i, j;
uint8_t result, length;
CTRL_BTN_STATUS btn_change;
for (i = 0; i < ctrl_data_p->connected_count; i++) {
// Store the last read values
ctrl_data_p->btn_prev[i] = ctrl_data_p->btn_curr[i];
 
// Read in the button values for each controller
I2C1_Master_Restart(ctrl_data_p->connected_controllers[i], CONTROLLER_CMD_READ, 1);
do {
result = I2C1_Get_Status();
} while (!result);
// Save the read values
length = I2C1_Read_Buffer(buffer);
ctrl_data_p->btn_curr[i].w = buffer[0];
uint8_t controller = ctrl_data_p->next_poll;
 
// Determine if a change was made between the current and previous values
if (ctrl_data_p->btn_curr[i].w != ctrl_data_p->btn_prev[i].w) {
// Determine if a button was pressed (unpressed->pressed)
btn_change.w = ctrl_data_p->btn_prev[i].w ^ ctrl_data_p->btn_curr[i].w;
btn_change.w &= ctrl_data_p->btn_curr[i].w;
// Store the last read values
ctrl_data_p->btn_prev[controller] = ctrl_data_p->btn_curr[controller];
 
// If a button was pressed, call the saved callback
if (btn_change.w) {
if (ctrl_data_p->change_callback != NULL) {
ctrl_data_p->change_callback(i, btn_change);
}
// Read in the button values for each controller
I2C1_Master_Restart(ctrl_data_p->connected_controllers[controller], CONTROLLER_CMD_READ, 1);
do {
result = I2C1_Get_Status();
} while (!result);
// Save the read values
length = I2C1_Read_Buffer(buffer);
ctrl_data_p->btn_curr[controller].w = buffer[0];
 
// Determine if a change was made between the current and previous values
if (ctrl_data_p->btn_curr[controller].w != ctrl_data_p->btn_prev[controller].w) {
// Determine if a button was pressed (unpressed->pressed)
btn_change.w = ctrl_data_p->btn_prev[controller].w ^ ctrl_data_p->btn_curr[controller].w;
btn_change.w &= ctrl_data_p->btn_curr[controller].w;
 
// If a button was pressed, call the saved callback
if (btn_change.w) {
if (ctrl_data_p->change_callback != NULL) {
ctrl_data_p->change_callback(controller, btn_change);
}
}
}
 
ctrl_data_p->next_poll = (controller == ctrl_data_p->connected_count - 1) ? 0x0 : controller+1;
}
 
void Controller_Set_Left_Leds(uint8_t controller, uint8_t value) {