Revision 71
fixed packet parsing, remote fully operational
lab4/mouse.c | ||
---|---|---|
49 | 49 |
pp.rb = pp.bytes[0] & RIGHT_BUTTON; |
50 | 50 |
pp.mb = pp.bytes[0] & MIDDLE_BUTTON; |
51 | 51 |
pp.lb = pp.bytes[0] & LEFT_BUTTON; |
52 |
pp.delta_x = pp.bytes[1];
|
|
53 |
pp.delta_y = pp.bytes[2];
|
|
52 |
pp.delta_x = sign_extend_byte((packet_bytes[0] & MSB_X_DELTA) != 0, pp.bytes[1]);
|
|
53 |
pp.delta_y = sign_extend_byte((packet_bytes[0] & MSB_Y_DELTA) != 0, pp.bytes[2]);
|
|
54 | 54 |
pp.x_ov = pp.bytes[0] & X_OVERFLOW; |
55 | 55 |
pp.y_ov = pp.bytes[0] & Y_OVERFLOW; |
56 | 56 |
return pp; |
... | ... | |
101 | 101 |
} |
102 | 102 |
return TIMEOUT_ERROR; |
103 | 103 |
} |
104 |
|
|
105 |
int16_t (sign_extend_byte)(uint8_t sign_bit, uint8_t byte) { |
|
106 |
return (int16_t)(((0xFF * sign_bit)<<8) | byte); |
|
107 |
} |
lab4/mouse.h | ||
---|---|---|
42 | 42 |
* @brief Reads byte from mouse |
43 | 43 |
* <summary> |
44 | 44 |
* Reads byte from mouse, giving error if exceeds number of tries to read |
45 |
* </summary> |
|
45 | 46 |
* @param byte Pointer to variable where byte read from mouse will be stored |
46 | 47 |
* @return ERROR_CODE code representing the result of the operation, SUCCESS code is returned if everything is OK |
47 | 48 |
* @see {_ERRORS_H_::errors} |
48 | 49 |
*/ |
49 | 50 |
int (mouse_read_byte)(uint8_t *byte); |
50 | 51 |
|
52 |
/** |
|
53 |
* @brief Converts 9-bit number to 16-bit with sign extension |
|
54 |
* @param sign_bit Sign bit identifiying the signal of the number |
|
55 |
* @param byte Least significant byte that will be extended |
|
56 |
* @return Extended 9-bit number |
|
57 |
*/ |
|
58 |
int16_t (sign_extend_byte)(uint8_t sign_bit, uint8_t byte); |
|
59 |
|
|
51 | 60 |
#endif //MOUSE_H_INCLUDED |
Also available in: Unified diff