Fork of PS/2 Keyboard lib.
Fork of PS2 by
PS2Mouse.cpp@0:62b62530a82f, 2012-10-11 (annotated)
- Committer:
- pprasad7
- Date:
- Thu Oct 11 20:15:09 2012 +0000
- Revision:
- 0:62b62530a82f
PS/2 Input;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pprasad7 | 0:62b62530a82f | 1 | /** |
pprasad7 | 0:62b62530a82f | 2 | * PS/2 mouse interface control class (Version 0.0.1) |
pprasad7 | 0:62b62530a82f | 3 | * |
pprasad7 | 0:62b62530a82f | 4 | * Copyright (C) 2010 Shinichiro Nakamura (CuBeatSystems) |
pprasad7 | 0:62b62530a82f | 5 | * http://shinta.main.jp/ |
pprasad7 | 0:62b62530a82f | 6 | */ |
pprasad7 | 0:62b62530a82f | 7 | #include "PS2Mouse.h" |
pprasad7 | 0:62b62530a82f | 8 | |
pprasad7 | 0:62b62530a82f | 9 | PS2Mouse::PS2Mouse(PinName clk_pin, PinName dat_pin) |
pprasad7 | 0:62b62530a82f | 10 | : ps2ms_init(clk_pin, dat_pin), ps2ms(clk_pin, dat_pin) { |
pprasad7 | 0:62b62530a82f | 11 | cnt = 0; |
pprasad7 | 0:62b62530a82f | 12 | } |
pprasad7 | 0:62b62530a82f | 13 | |
pprasad7 | 0:62b62530a82f | 14 | PS2Mouse::~PS2Mouse() { |
pprasad7 | 0:62b62530a82f | 15 | } |
pprasad7 | 0:62b62530a82f | 16 | |
pprasad7 | 0:62b62530a82f | 17 | bool PS2Mouse::processing(mouse_event_t *p) { |
pprasad7 | 0:62b62530a82f | 18 | bool emit = false; |
pprasad7 | 0:62b62530a82f | 19 | for (int i = 0; i < 4; i++) { |
pprasad7 | 0:62b62530a82f | 20 | const int c = ps2ms.getc(); |
pprasad7 | 0:62b62530a82f | 21 | if (0 <= c) { |
pprasad7 | 0:62b62530a82f | 22 | switch (cnt % 4) { |
pprasad7 | 0:62b62530a82f | 23 | case 0: |
pprasad7 | 0:62b62530a82f | 24 | mi.byte1.byte = c; |
pprasad7 | 0:62b62530a82f | 25 | /* |
pprasad7 | 0:62b62530a82f | 26 | * Check and reset a buffer if state is wrong. |
pprasad7 | 0:62b62530a82f | 27 | */ |
pprasad7 | 0:62b62530a82f | 28 | if (mi.byte1.bit.always1 == 0) { |
pprasad7 | 0:62b62530a82f | 29 | cnt = 0; |
pprasad7 | 0:62b62530a82f | 30 | while (0 <= ps2ms.getc()) { |
pprasad7 | 0:62b62530a82f | 31 | } |
pprasad7 | 0:62b62530a82f | 32 | } |
pprasad7 | 0:62b62530a82f | 33 | break; |
pprasad7 | 0:62b62530a82f | 34 | case 1: |
pprasad7 | 0:62b62530a82f | 35 | mi.byte2.byte = c; |
pprasad7 | 0:62b62530a82f | 36 | break; |
pprasad7 | 0:62b62530a82f | 37 | case 2: |
pprasad7 | 0:62b62530a82f | 38 | mi.byte3.byte = c; |
pprasad7 | 0:62b62530a82f | 39 | break; |
pprasad7 | 0:62b62530a82f | 40 | case 3: |
pprasad7 | 0:62b62530a82f | 41 | mi.byte4.byte = c; |
pprasad7 | 0:62b62530a82f | 42 | /* |
pprasad7 | 0:62b62530a82f | 43 | * Store a event data. |
pprasad7 | 0:62b62530a82f | 44 | */ |
pprasad7 | 0:62b62530a82f | 45 | p->left = mi.byte1.bit.btnLeft ? true : false; |
pprasad7 | 0:62b62530a82f | 46 | p->center = mi.byte1.bit.btnCenter ? true : false; |
pprasad7 | 0:62b62530a82f | 47 | p->right = mi.byte1.bit.btnRight ? true : false; |
pprasad7 | 0:62b62530a82f | 48 | p->x = mi.byte1.bit.signX ? (-256 + mi.byte2.byte) : mi.byte2.byte; |
pprasad7 | 0:62b62530a82f | 49 | p->y = mi.byte1.bit.signY ? (-256 + mi.byte3.byte) : mi.byte3.byte; |
pprasad7 | 0:62b62530a82f | 50 | p->z = mi.byte4.bit.signZ ? (-128 + mi.byte4.bit.value) : mi.byte4.bit.value; |
pprasad7 | 0:62b62530a82f | 51 | emit = true; |
pprasad7 | 0:62b62530a82f | 52 | break; |
pprasad7 | 0:62b62530a82f | 53 | } |
pprasad7 | 0:62b62530a82f | 54 | cnt++; |
pprasad7 | 0:62b62530a82f | 55 | } |
pprasad7 | 0:62b62530a82f | 56 | } |
pprasad7 | 0:62b62530a82f | 57 | return emit; |
pprasad7 | 0:62b62530a82f | 58 | } |