| 139 | } |
| 140 | |
| 141 | static void _look_up_motion_range(int deviceId, int source, float* outMinX, |
| 142 | float* outMaxX, float* outMinY, |
| 143 | float* outMaxY) { |
| 144 | int i; |
| 145 | for (i = 0; i < _motion_range_cache_items; i++) { |
| 146 | DeviceMotionRange* item = &_motion_range_cache[i]; |
| 147 | if (item->deviceId == deviceId && item->source == source) { |
| 148 | *outMinX = item->minX; |
| 149 | *outMaxX = item->maxX; |
| 150 | *outMinY = item->minY; |
| 151 | *outMaxY = item->maxY; |
| 152 | return; |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | DeviceMotionRange* newItem; |
| 157 | if (_motion_range_cache_items >= MOTION_RANGE_CACHE_MAX) { |
| 158 | static bool warned = false; |
| 159 | if (!warned) { |
| 160 | LOGW( |
| 161 | "**** Warning: Motion range cache exceeded. This shouldn't normally " |
| 162 | "happen."); |
| 163 | warned = true; |
| 164 | } |
| 165 | // as an emergency measure, overwrite (arbitrarily) the 1st entry: |
| 166 | newItem = &_motion_range_cache[i]; |
| 167 | } else { |
| 168 | // create a new entry |
| 169 | newItem = &_motion_range_cache[_motion_range_cache_items++]; |
| 170 | } |
| 171 | |
| 172 | LOGD("New device/source pair %d,%d. Querying motion range via JNI.", deviceId, |
| 173 | source); |
| 174 | |
| 175 | newItem->deviceId = deviceId; |
| 176 | newItem->source = source; |
| 177 | |
| 178 | LOGD("====Calling _look_up_motion_range() for device %d", deviceId); |
| 179 | #if 0 |
| 180 | /* |
| 181 | * What this is ? |
| 182 | */ |
| 183 | BGNActivity_GetDeviceMotionRange(deviceId, source, &(newItem->minX), &(newItem->maxX), |
| 184 | &(newItem->minY), &(newItem->maxY)); |
| 185 | #endif |
| 186 | LOGD("Motion range for (device %d, source %d) is X:%f-%f, Y:%f-%f", deviceId, |
| 187 | source, newItem->minX, newItem->maxX, newItem->minY, newItem->maxY); |
| 188 | *outMinX = newItem->minX; |
| 189 | *outMaxX = newItem->maxX; |
| 190 | *outMinY = newItem->minY; |
| 191 | *outMaxY = newItem->maxY; |
| 192 | } |
| 193 | |
| 194 | static bool CookEvent_Joy(AInputEvent* event, CookedEventCallback callback) { |
| 195 | struct CookedEvent ev; |