summaryrefslogtreecommitdiffstats
path: root/app/code.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/code.c')
-rw-r--r--app/code.c98
1 files changed, 98 insertions, 0 deletions
diff --git a/app/code.c b/app/code.c
new file mode 100644
index 0000000..4d32f7b
--- /dev/null
+++ b/app/code.c
@@ -0,0 +1,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();
+
+
+}