| 1 | use strict; | ||
| 2 | package Device::Ericsson::AccessoryMenu::Mouse; | ||
| 3 | use base 'Device::Ericsson::AccessoryMenu::State'; | ||
| 4 | __PACKAGE__->mk_accessors( qw( callback title upup ) ); | ||
| 5 | |||
| 6 | sub on_enter { | ||
| 7 | my $self = shift; | ||
| 8 | |||
| 9 | my $title = $self->title; | ||
| 10 | |||
| 11 | # show the user a dialog they can quit from | ||
| 12 | $self->send( qq{AT*EAID=13,2,"$title"} ); | ||
| 13 | $self->expect( 'OK' ); | ||
| 14 | # and put them into Event Reporting mode. | ||
| 15 | $self->send( qq{AT+CMER=3,2,0,0,0} ); | ||
| 16 | $self->expect( 'OK' ); | ||
| 17 | } | ||
| 18 | |||
| 19 | sub on_exit { | ||
| 20 | my $self = shift; | ||
| 21 | |||
| 22 | # reset spy mode | ||
| 23 | $self->send( qq{AT+CMER=0,0,0,0,0} ); | ||
| 24 | $self->expect( 'OK' ); | ||
| 25 | } | ||
| 26 | |||
| 27 | sub handle { | ||
| 28 | my $self = shift; | ||
| 29 | my $got = shift; | ||
| 30 | |||
| 31 | if ($got =~ /\+CKEV: (?:(.),(.))?/) { | ||
| 32 | my ($key, $updown) = ($1, $2); | ||
| 33 | unless (defined $key) { | ||
| 34 | # this seems glitchy on my phone. oh well - hack it | ||
| 35 | $key = "^"; | ||
| 36 | $updown = $self->upup; | ||
| 37 | $updown ^= 1; | ||
| 38 | $self->upup( $updown ); | ||
| 39 | } | ||
| 40 | $self->callback->($key, $updown) if $self->callback; | ||
| 41 | } | ||
| 42 | if ($got =~ /\*EAII/) { # backup | ||
| 43 | $self->exit_state; | ||
| 44 | return; | ||
| 45 | } | ||
| 46 | |||
| 47 | warn "Mouse got unexpected 'line'\n" if $self->debug; | ||
| 48 | } | ||
| 49 | |||
| 50 | 1; |