aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-ntrig.c
diff options
context:
space:
mode:
authorRafi Rubin <rafi@seas.upenn.edu>2011-03-07 21:13:28 -0500
committerJiri Kosina <jkosina@suse.cz>2011-03-14 07:58:15 -0400
commitff4046294ba215abeaf45c10ab6cbfae41978b14 (patch)
tree1929c8b3b78e923324176fc4097ffb0a25d7388a /drivers/hid/hid-ntrig.c
parent6638dedaec6e3d32654f0ac5786f5d32963e208b (diff)
HID: ntrig remove if and drop an indent
Signed-off-by: Rafi Rubin <rafi@seas.upenn.edu> Tested-by: Peter Hutterer <peter.hutterer@who-t.net> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-ntrig.c')
-rw-r--r--drivers/hid/hid-ntrig.c456
1 files changed, 227 insertions, 229 deletions
diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c
index f152b5114f05..dffffa763bd7 100644
--- a/drivers/hid/hid-ntrig.c
+++ b/drivers/hid/hid-ntrig.c
@@ -557,268 +557,266 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field,
557 if (field->application == HID_DG_PEN) 557 if (field->application == HID_DG_PEN)
558 return 0; 558 return 0;
559 559
560 if (hid->claimed & HID_CLAIMED_INPUT) { 560 switch (usage->hid) {
561 switch (usage->hid) { 561 case 0xff000001:
562 case 0xff000001: 562 /* Tag indicating the start of a multitouch group */
563 /* Tag indicating the start of a multitouch group */ 563 nd->reading_mt = 1;
564 nd->reading_mt = 1; 564 nd->first_contact_touch = 0;
565 nd->first_contact_touch = 0; 565 break;
566 break; 566 case HID_DG_TIPSWITCH:
567 case HID_DG_TIPSWITCH: 567 nd->tipswitch = value;
568 nd->tipswitch = value; 568 /* Prevent emission of touch until validated */
569 /* Prevent emission of touch until validated */ 569 return 1;
570 return 1; 570 case HID_DG_CONFIDENCE:
571 case HID_DG_CONFIDENCE: 571 nd->confidence = value;
572 nd->confidence = value; 572 break;
573 break; 573 case HID_GD_X:
574 case HID_GD_X: 574 nd->x = value;
575 nd->x = value; 575 /* Clear the contact footer */
576 /* Clear the contact footer */ 576 nd->mt_foot_count = 0;
577 nd->mt_foot_count = 0; 577 break;
578 break; 578 case HID_GD_Y:
579 case HID_GD_Y: 579 nd->y = value;
580 nd->y = value; 580 break;
581 break; 581 case HID_DG_CONTACTID:
582 case HID_DG_CONTACTID: 582 nd->id = value;
583 nd->id = value; 583 break;
584 break; 584 case HID_DG_WIDTH:
585 case HID_DG_WIDTH: 585 nd->w = value;
586 nd->w = value; 586 break;
587 break; 587 case HID_DG_HEIGHT:
588 case HID_DG_HEIGHT: 588 nd->h = value;
589 nd->h = value; 589 /*
590 * when in single touch mode, this is the last
591 * report received in a finger event. We want
592 * to emit a normal (X, Y) position
593 */
594 if (!nd->reading_mt) {
590 /* 595 /*
591 * when in single touch mode, this is the last 596 * TipSwitch indicates the presence of a
592 * report received in a finger event. We want 597 * finger in single touch mode.
593 * to emit a normal (X, Y) position
594 */ 598 */
595 if (!nd->reading_mt) { 599 input_report_key(input, BTN_TOUCH,
596 /* 600 nd->tipswitch);
597 * TipSwitch indicates the presence of a 601 input_report_key(input, BTN_TOOL_DOUBLETAP,
598 * finger in single touch mode. 602 nd->tipswitch);
599 */ 603 input_event(input, EV_ABS, ABS_X, nd->x);
600 input_report_key(input, BTN_TOUCH, 604 input_event(input, EV_ABS, ABS_Y, nd->y);
601 nd->tipswitch); 605 }
602 input_report_key(input, BTN_TOOL_DOUBLETAP, 606 break;
603 nd->tipswitch); 607 case 0xff000002:
604 input_event(input, EV_ABS, ABS_X, nd->x); 608 /*
605 input_event(input, EV_ABS, ABS_Y, nd->y); 609 * we receive this when the device is in multitouch
606 } 610 * mode. The first of the three values tagged with
611 * this usage tells if the contact point is real
612 * or a placeholder
613 */
614
615 /* Shouldn't get more than 4 footer packets, so skip */
616 if (nd->mt_foot_count >= 4)
607 break; 617 break;
608 case 0xff000002:
609 /*
610 * we receive this when the device is in multitouch
611 * mode. The first of the three values tagged with
612 * this usage tells if the contact point is real
613 * or a placeholder
614 */
615 618
616 /* Shouldn't get more than 4 footer packets, so skip */ 619 nd->mt_footer[nd->mt_foot_count++] = value;
617 if (nd->mt_foot_count >= 4)
618 break;
619 620
620 nd->mt_footer[nd->mt_foot_count++] = value; 621 /* if the footer isn't complete break */
622 if (nd->mt_foot_count != 4)
623 break;
621 624
622 /* if the footer isn't complete break */ 625 /* Pen activity signal. */
623 if (nd->mt_foot_count != 4) 626 if (nd->mt_footer[2]) {
624 break; 627 /*
628 * When the pen deactivates touch, we see a
629 * bogus frame with ContactCount > 0.
630 * We can
631 * save a bit of work by ensuring act_state < 0
632 * even if deactivation slack is turned off.
633 */
634 nd->act_state = deactivate_slack - 1;
635 nd->confidence = 0;
636 break;
637 }
625 638
626 /* Pen activity signal. */ 639 /*
627 if (nd->mt_footer[2]) { 640 * The first footer value indicates the presence of a
628 /* 641 * finger.
629 * When the pen deactivates touch, we see a 642 */
630 * bogus frame with ContactCount > 0. 643 if (nd->mt_footer[0]) {
631 * We can 644 /*
632 * save a bit of work by ensuring act_state < 0 645 * We do not want to process contacts under
633 * even if deactivation slack is turned off. 646 * the size threshold, but do not want to
634 */ 647 * ignore them for activation state
635 nd->act_state = deactivate_slack - 1; 648 */
649 if (nd->w < nd->min_width ||
650 nd->h < nd->min_height)
636 nd->confidence = 0; 651 nd->confidence = 0;
637 break; 652 } else
638 } 653 break;
639 654
655 if (nd->act_state > 0) {
640 /* 656 /*
641 * The first footer value indicates the presence of a 657 * Contact meets the activation size threshold
642 * finger.
643 */ 658 */
644 if (nd->mt_footer[0]) { 659 if (nd->w >= nd->activation_width &&
645 /* 660 nd->h >= nd->activation_height) {
646 * We do not want to process contacts under 661 if (nd->id)
647 * the size threshold, but do not want to
648 * ignore them for activation state
649 */
650 if (nd->w < nd->min_width ||
651 nd->h < nd->min_height)
652 nd->confidence = 0;
653 } else
654 break;
655
656 if (nd->act_state > 0) {
657 /*
658 * Contact meets the activation size threshold
659 */
660 if (nd->w >= nd->activation_width &&
661 nd->h >= nd->activation_height) {
662 if (nd->id)
663 /*
664 * first contact, activate now
665 */
666 nd->act_state = 0;
667 else {
668 /*
669 * avoid corrupting this frame
670 * but ensure next frame will
671 * be active
672 */
673 nd->act_state = 1;
674 break;
675 }
676 } else
677 /* 662 /*
678 * Defer adjusting the activation state 663 * first contact, activate now
679 * until the end of the frame.
680 */ 664 */
665 nd->act_state = 0;
666 else {
667 /*
668 * avoid corrupting this frame
669 * but ensure next frame will
670 * be active
671 */
672 nd->act_state = 1;
681 break; 673 break;
682 } 674 }
683 675 } else
684 /* Discarding this contact */
685 if (!nd->confidence)
686 break;
687
688 /* emit a normal (X, Y) for the first point only */
689 if (nd->id == 0) {
690 /* 676 /*
691 * TipSwitch is superfluous in multitouch 677 * Defer adjusting the activation state
692 * mode. The footer events tell us 678 * until the end of the frame.
693 * if there is a finger on the screen or
694 * not.
695 */ 679 */
696 nd->first_contact_touch = nd->confidence; 680 break;
697 input_event(input, EV_ABS, ABS_X, nd->x); 681 }
698 input_event(input, EV_ABS, ABS_Y, nd->y);
699 }
700 682
701 /* Emit MT events */ 683 /* Discarding this contact */
702 input_event(input, EV_ABS, ABS_MT_POSITION_X, nd->x); 684 if (!nd->confidence)
703 input_event(input, EV_ABS, ABS_MT_POSITION_Y, nd->y); 685 break;
704 686
687 /* emit a normal (X, Y) for the first point only */
688 if (nd->id == 0) {
705 /* 689 /*
706 * Translate from height and width to size 690 * TipSwitch is superfluous in multitouch
707 * and orientation. 691 * mode. The footer events tell us
692 * if there is a finger on the screen or
693 * not.
708 */ 694 */
709 if (nd->w > nd->h) { 695 nd->first_contact_touch = nd->confidence;
710 input_event(input, EV_ABS, 696 input_event(input, EV_ABS, ABS_X, nd->x);
711 ABS_MT_ORIENTATION, 1); 697 input_event(input, EV_ABS, ABS_Y, nd->y);
712 input_event(input, EV_ABS, 698 }
713 ABS_MT_TOUCH_MAJOR, nd->w);
714 input_event(input, EV_ABS,
715 ABS_MT_TOUCH_MINOR, nd->h);
716 } else {
717 input_event(input, EV_ABS,
718 ABS_MT_ORIENTATION, 0);
719 input_event(input, EV_ABS,
720 ABS_MT_TOUCH_MAJOR, nd->h);
721 input_event(input, EV_ABS,
722 ABS_MT_TOUCH_MINOR, nd->w);
723 }
724 input_mt_sync(field->hidinput->input);
725 break;
726 699
727 case HID_DG_CONTACTCOUNT: /* End of a multitouch group */ 700 /* Emit MT events */
728 if (!nd->reading_mt) /* Just to be sure */ 701 input_event(input, EV_ABS, ABS_MT_POSITION_X, nd->x);
729 break; 702 input_event(input, EV_ABS, ABS_MT_POSITION_Y, nd->y);
703
704 /*
705 * Translate from height and width to size
706 * and orientation.
707 */
708 if (nd->w > nd->h) {
709 input_event(input, EV_ABS,
710 ABS_MT_ORIENTATION, 1);
711 input_event(input, EV_ABS,
712 ABS_MT_TOUCH_MAJOR, nd->w);
713 input_event(input, EV_ABS,
714 ABS_MT_TOUCH_MINOR, nd->h);
715 } else {
716 input_event(input, EV_ABS,
717 ABS_MT_ORIENTATION, 0);
718 input_event(input, EV_ABS,
719 ABS_MT_TOUCH_MAJOR, nd->h);
720 input_event(input, EV_ABS,
721 ABS_MT_TOUCH_MINOR, nd->w);
722 }
723 input_mt_sync(field->hidinput->input);
724 break;
730 725
731 nd->reading_mt = 0; 726 case HID_DG_CONTACTCOUNT: /* End of a multitouch group */
727 if (!nd->reading_mt) /* Just to be sure */
728 break;
732 729
730 nd->reading_mt = 0;
731
732
733 /*
734 * Activation state machine logic:
735 *
736 * Fundamental states:
737 * state > 0: Inactive
738 * state <= 0: Active
739 * state < -deactivate_slack:
740 * Pen termination of touch
741 *
742 * Specific values of interest
743 * state == activate_slack
744 * no valid input since the last reset
745 *
746 * state == 0
747 * general operational state
748 *
749 * state == -deactivate_slack
750 * read sufficient empty frames to accept
751 * the end of input and reset
752 */
753
754 if (nd->act_state > 0) { /* Currently inactive */
755 if (value)
756 /*
757 * Consider each live contact as
758 * evidence of intentional activity.
759 */
760 nd->act_state = (nd->act_state > value)
761 ? nd->act_state - value
762 : 0;
763 else
764 /*
765 * Empty frame before we hit the
766 * activity threshold, reset.
767 */
768 nd->act_state = nd->activate_slack;
733 769
734 /* 770 /*
735 * Activation state machine logic: 771 * Entered this block inactive and no
736 * 772 * coordinates sent this frame, so hold off
737 * Fundamental states: 773 * on button state.
738 * state > 0: Inactive
739 * state <= 0: Active
740 * state < -deactivate_slack:
741 * Pen termination of touch
742 *
743 * Specific values of interest
744 * state == activate_slack
745 * no valid input since the last reset
746 *
747 * state == 0
748 * general operational state
749 *
750 * state == -deactivate_slack
751 * read sufficient empty frames to accept
752 * the end of input and reset
753 */ 774 */
754 775 break;
755 if (nd->act_state > 0) { /* Currently inactive */ 776 } else { /* Currently active */
756 if (value) 777 if (value && nd->act_state >=
757 /* 778 nd->deactivate_slack)
758 * Consider each live contact as
759 * evidence of intentional activity.
760 */
761 nd->act_state = (nd->act_state > value)
762 ? nd->act_state - value
763 : 0;
764 else
765 /*
766 * Empty frame before we hit the
767 * activity threshold, reset.
768 */
769 nd->act_state = nd->activate_slack;
770
771 /* 779 /*
772 * Entered this block inactive and no 780 * Live point: clear accumulated
773 * coordinates sent this frame, so hold off 781 * deactivation count.
774 * on button state.
775 */ 782 */
776 break; 783 nd->act_state = 0;
777 } else { /* Currently active */ 784 else if (nd->act_state <= nd->deactivate_slack)
778 if (value && nd->act_state >=
779 nd->deactivate_slack)
780 /*
781 * Live point: clear accumulated
782 * deactivation count.
783 */
784 nd->act_state = 0;
785 else if (nd->act_state <= nd->deactivate_slack)
786 /*
787 * We've consumed the deactivation
788 * slack, time to deactivate and reset.
789 */
790 nd->act_state =
791 nd->activate_slack;
792 else { /* Move towards deactivation */
793 nd->act_state--;
794 break;
795 }
796 }
797
798 if (nd->first_contact_touch && nd->act_state <= 0) {
799 /* 785 /*
800 * Check to see if we're ready to start 786 * We've consumed the deactivation
801 * emitting touch events. 787 * slack, time to deactivate and reset.
802 *
803 * Note: activation slack will decrease over
804 * the course of the frame, and it will be
805 * inconsistent from the start to the end of
806 * the frame. However if the frame starts
807 * with slack, first_contact_touch will still
808 * be 0 and we will not get to this point.
809 */ 788 */
810 input_report_key(input, BTN_TOOL_DOUBLETAP, 1); 789 nd->act_state =
811 input_report_key(input, BTN_TOUCH, 1); 790 nd->activate_slack;
812 } else { 791 else { /* Move towards deactivation */
813 input_report_key(input, BTN_TOOL_DOUBLETAP, 0); 792 nd->act_state--;
814 input_report_key(input, BTN_TOUCH, 0); 793 break;
815 } 794 }
816 break; 795 }
817 796
818 default: 797 if (nd->first_contact_touch && nd->act_state <= 0) {
819 /* fall-back to the generic hidinput handling */ 798 /*
820 return 0; 799 * Check to see if we're ready to start
800 * emitting touch events.
801 *
802 * Note: activation slack will decrease over
803 * the course of the frame, and it will be
804 * inconsistent from the start to the end of
805 * the frame. However if the frame starts
806 * with slack, first_contact_touch will still
807 * be 0 and we will not get to this point.
808 */
809 input_report_key(input, BTN_TOOL_DOUBLETAP, 1);
810 input_report_key(input, BTN_TOUCH, 1);
811 } else {
812 input_report_key(input, BTN_TOOL_DOUBLETAP, 0);
813 input_report_key(input, BTN_TOUCH, 0);
821 } 814 }
815 break;
816
817 default:
818 /* fall-back to the generic hidinput handling */
819 return 0;
822 } 820 }
823 821
824not_claimed_input: 822not_claimed_input: