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