Subversion Repositories Code-Repo

Rev

Rev 276 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 276 Rev 278
Line 22... Line 22...
22
            ctrl_data_p->led_status[i].w[j] = 0x0;
22
            ctrl_data_p->led_status[i].w[j] = 0x0;
23
        }
23
        }
24
    }
24
    }
25
 
25
 
26
    ctrl_data_p->connected_count = 0x0;
26
    ctrl_data_p->connected_count = 0x0;
-
 
27
    ctrl_data_p->next_poll = 0x0;
27
 
28
 
28
    // Poll to see which controllers are connected
29
    // Poll to see which controllers are connected
29
    Controller_Poll_Connected();
30
    Controller_Poll_Connected();
30
}
31
}
31
 
32
 
Line 46... Line 47...
46
            ctrl_data_p->connected_controllers[ctrl_data_p->connected_count] = address + i;
47
            ctrl_data_p->connected_controllers[ctrl_data_p->connected_count] = address + i;
47
            ctrl_data_p->connected_count++;
48
            ctrl_data_p->connected_count++;
48
        }
49
        }
49
 
50
 
50
        // A small delay is needed between polls
51
        // A small delay is needed between polls
51
        Delay_MS(1);
52
        Delay_US(500);
52
    }
53
    }
53
 
54
 
54
    // Show the number of controllers connected
55
    // Show the number of controllers connected
55
    if (ctrl_data_p->connected_count & 0x1)
56
    if (ctrl_data_p->connected_count & 0x1)
56
        LED1_LAT = 1;
57
        LED1_LAT = 1;
Line 62... Line 63...
62
        LED4_LAT = 1;
63
        LED4_LAT = 1;
63
}
64
}
64
 
65
 
65
void Controller_Update(void) {
66
void Controller_Update(void) {
66
    uint8_t buffer[2];
67
    uint8_t buffer[2];
67
    uint8_t result, length, i, j;
68
    uint8_t result, length;
68
    CTRL_BTN_STATUS btn_change;
69
    CTRL_BTN_STATUS btn_change;
69
    
-
 
70
    for (i = 0; i < ctrl_data_p->connected_count; i++) {
-
 
71
        // Store the last read values
-
 
72
        ctrl_data_p->btn_prev[i] = ctrl_data_p->btn_curr[i];
-
 
73
 
70
 
-
 
71
    uint8_t controller = ctrl_data_p->next_poll;
-
 
72
 
-
 
73
    // Store the last read values
-
 
74
    ctrl_data_p->btn_prev[controller] = ctrl_data_p->btn_curr[controller];
-
 
75
 
74
        // Read in the button values for each controller
76
    // Read in the button values for each controller
75
        I2C1_Master_Restart(ctrl_data_p->connected_controllers[i], CONTROLLER_CMD_READ, 1);
77
    I2C1_Master_Restart(ctrl_data_p->connected_controllers[controller], CONTROLLER_CMD_READ, 1);
76
        do {
78
    do {
77
            result = I2C1_Get_Status();
79
        result = I2C1_Get_Status();
78
        } while (!result);
80
    } while (!result);
79
        // Save the read values
81
    // Save the read values
80
        length = I2C1_Read_Buffer(buffer);
82
    length = I2C1_Read_Buffer(buffer);
81
        ctrl_data_p->btn_curr[i].w = buffer[0];
83
    ctrl_data_p->btn_curr[controller].w = buffer[0];
82
 
84
 
83
        // Determine if a change was made between the current and previous values
85
    // Determine if a change was made between the current and previous values
84
        if (ctrl_data_p->btn_curr[i].w != ctrl_data_p->btn_prev[i].w) {
86
    if (ctrl_data_p->btn_curr[controller].w != ctrl_data_p->btn_prev[controller].w) {
85
            // Determine if a button was pressed (unpressed->pressed)
87
        // Determine if a button was pressed (unpressed->pressed)
86
            btn_change.w = ctrl_data_p->btn_prev[i].w ^ ctrl_data_p->btn_curr[i].w;
88
        btn_change.w = ctrl_data_p->btn_prev[controller].w ^ ctrl_data_p->btn_curr[controller].w;
87
            btn_change.w &= ctrl_data_p->btn_curr[i].w;
89
        btn_change.w &= ctrl_data_p->btn_curr[controller].w;
88
 
90
 
89
            // If a button was pressed, call the saved callback
91
        // If a button was pressed, call the saved callback
90
            if (btn_change.w) {
92
        if (btn_change.w) {
91
                if (ctrl_data_p->change_callback != NULL) {
93
            if (ctrl_data_p->change_callback != NULL) {
92
                    ctrl_data_p->change_callback(i, btn_change);
94
                ctrl_data_p->change_callback(controller, btn_change);
93
                }
-
 
94
            }
95
            }
95
        }
96
        }
96
    }
97
    }
-
 
98
 
-
 
99
    ctrl_data_p->next_poll = (controller == ctrl_data_p->connected_count - 1) ? 0x0 : controller+1;
97
}
100
}
98
 
101
 
99
void Controller_Set_Left_Leds(uint8_t controller, uint8_t value) {
102
void Controller_Set_Left_Leds(uint8_t controller, uint8_t value) {
100
    uint8_t result, i;
103
    uint8_t result, i;
101
    uint8_t buffer[18];
104
    uint8_t buffer[18];