summaryrefslogtreecommitdiffstats
path: root/app/code.c
blob: 4d32f7badefe70bd0b2c9fec9a7c8d3715bb4a74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "project.h"


static uint8_t code[16];
static int code_len;
static int hide;
static int show;


void code_display(void)
{
size_t i;

#if 0
lcd_erase_line(0,16);

if (code_len!=16) 
	lcd_write("Enter code:",0,0);
else
	lcd_write("Code entered:",0,0);
#endif

  for (i=0;i<sizeof(code);++i) 
	lcd_write_char(hide ? '*': (code[i] ? code[i]:' '),i,1);


  lcd_backlight (!hide);
}


int
vendor_control_request (usbd_device * usbd_dev, struct usb_setup_data *req,
                     uint8_t ** buf, uint16_t * len,
                     int (**complete) (usbd_device * usbd_dev,
                                       struct usb_setup_data * req))
{
  (void) buf;
  (void) len;
  (void) usbd_dev;

  (void) complete;

  if ((req->bmRequestType & 0x7F) != 0x41)
    return 0;                   /* Only accept vendor request. */

  switch (req->bRequest)
    {

    case 0x34:
        (*buf)[0] = 0x1;
        (*buf)[1] = 0;
        (*buf)[2] = 0;
        (*buf)[3] = 0;
        (*buf)[4] = 0x2;
        (*buf)[5] = 0;          /* iString not used here */
        *len = 6;
        return 1;
      }

  return 0;

}


void code_tick(void)
{
if (!show) return;
show--;
	if (!show) {
		hide++;
		code_display();
	}

}




void key_event (uint8_t v, int ud)
{
  if (!ud) return;

  if (code_len==sizeof(code))  {
	code_len=0;
	memset(code,' ',sizeof(code));
  }


  show=5000;
  hide=0;

  code[code_len++]=v;


  code_display();
  

}