|
@@ -17,18 +17,54 @@
|
17
|
17
|
static char cnsl_line_buff[CNSL_BUFF_SIZE + 1];
|
18
|
18
|
static uint32_t cnsl_buff_pos = 0;
|
19
|
19
|
|
|
20
|
+static char cnsl_last_command[CNSL_BUFF_SIZE + 1];
|
|
21
|
+
|
|
22
|
+static char cnsl_repeated_command[CNSL_BUFF_SIZE + 1];
|
|
23
|
+static bool repeat_command = false;
|
|
24
|
+static uint32_t last_repeat_time = 0;
|
|
25
|
+
|
20
|
26
|
static void cnsl_interpret(const char *line) {
|
21
|
|
- if ((strcmp(line, "help") == 0)
|
|
27
|
+ if (strlen(line) == 0) {
|
|
28
|
+ // repeat last command once
|
|
29
|
+ print("repeating command \"%s\"", cnsl_last_command);
|
|
30
|
+ cnsl_interpret(cnsl_last_command);
|
|
31
|
+ print();
|
|
32
|
+ return;
|
|
33
|
+ } else if (strcmp(line, "repeat") == 0) {
|
|
34
|
+ if (!repeat_command) {
|
|
35
|
+ // mark last command to be repeated multiple times
|
|
36
|
+ strncpy(cnsl_repeated_command, cnsl_last_command, CNSL_BUFF_SIZE + 1);
|
|
37
|
+ last_repeat_time = to_ms_since_boot(get_absolute_time()) - 1001;
|
|
38
|
+ repeat_command = true;
|
|
39
|
+ } else {
|
|
40
|
+ // stop repeating
|
|
41
|
+ repeat_command = false;
|
|
42
|
+ }
|
|
43
|
+ } else if ((strcmp(line, "help") == 0)
|
22
|
44
|
|| (strcmp(line, "h") == 0)
|
23
|
45
|
|| (strcmp(line, "?") == 0)) {
|
24
|
46
|
print("Trackball Firmware Usage:");
|
25
|
47
|
print(" cpi - print current sensitivity");
|
26
|
48
|
print(" cpi N - set sensitivity");
|
27
|
|
- print(" pmw - print PMW3360 status");
|
28
|
|
- print(" help - print this message");
|
|
49
|
+ print(" pmws - print PMW3360 status");
|
|
50
|
+ print(" pmwr - reset PMW3360");
|
|
51
|
+ print(" reset - reset back into this firmware");
|
29
|
52
|
print(" \\x18 - reset to bootloader");
|
30
|
|
- } else if (strcmp(line, "pmw") == 0) {
|
|
53
|
+ print(" repeat - repeat last command once per second");
|
|
54
|
+ print(" help - print this message");
|
|
55
|
+ print("Press Enter with no input to repeat last command.");
|
|
56
|
+ print("Use repeat to continuously execute last command.");
|
|
57
|
+ print("Stop this by calling repeat again.");
|
|
58
|
+ } else if (strcmp(line, "pmws") == 0) {
|
31
|
59
|
pmw_print_status();
|
|
60
|
+ } else if (strcmp(line, "pmwr") == 0) {
|
|
61
|
+ print("user requests re-initializing of PMW3360");
|
|
62
|
+ int r = pmw_init();
|
|
63
|
+ if (r < 0) {
|
|
64
|
+ print("error initializing PMW3360");
|
|
65
|
+ } else {
|
|
66
|
+ print("PMW3360 re-initialized successfully");
|
|
67
|
+ }
|
32
|
68
|
} else if (strcmp(line, "cpi") == 0) {
|
33
|
69
|
uint8_t sense = pmw_get_sensitivity();
|
34
|
70
|
uint16_t cpi = PMW_SENSE_TO_CPI(sense);
|
|
@@ -44,9 +80,14 @@ static void cnsl_interpret(const char *line) {
|
44
|
80
|
print("setting cpi to 0x%02llX", num);
|
45
|
81
|
pmw_set_sensitivity(num);
|
46
|
82
|
}
|
|
83
|
+ } else if (strcmp(line, "reset") == 0) {
|
|
84
|
+ reset_to_main();
|
47
|
85
|
} else {
|
48
|
86
|
print("unknown command \"%s\"", line);
|
|
87
|
+ return;
|
49
|
88
|
}
|
|
89
|
+
|
|
90
|
+ print();
|
50
|
91
|
}
|
51
|
92
|
|
52
|
93
|
void cnsl_init(void) {
|
|
@@ -65,6 +106,19 @@ static int32_t cnsl_find_line_end(void) {
|
65
|
106
|
return -1;
|
66
|
107
|
}
|
67
|
108
|
|
|
109
|
+void cnsl_run(void) {
|
|
110
|
+ if (repeat_command) {
|
|
111
|
+ uint32_t now = to_ms_since_boot(get_absolute_time());
|
|
112
|
+ if (now >= (last_repeat_time + 1000)) {
|
|
113
|
+ print("repeating command \"%s\"", cnsl_repeated_command);
|
|
114
|
+ cnsl_interpret(cnsl_repeated_command);
|
|
115
|
+ print();
|
|
116
|
+
|
|
117
|
+ last_repeat_time = now;
|
|
118
|
+ }
|
|
119
|
+ }
|
|
120
|
+}
|
|
121
|
+
|
68
|
122
|
void cnsl_handle_input(const char *buf, uint32_t len) {
|
69
|
123
|
if ((cnsl_buff_pos + len) > CNSL_BUFF_SIZE) {
|
70
|
124
|
debug("error: console input buffer overflow! %lu > %u", cnsl_buff_pos + len, CNSL_BUFF_SIZE);
|
|
@@ -87,6 +141,9 @@ void cnsl_handle_input(const char *buf, uint32_t len) {
|
87
|
141
|
|
88
|
142
|
cnsl_interpret(cnsl_line_buff);
|
89
|
143
|
|
|
144
|
+ // store command for eventual repeats
|
|
145
|
+ strncpy(cnsl_last_command, cnsl_line_buff, CNSL_BUFF_SIZE + 1);
|
|
146
|
+
|
90
|
147
|
// clear string and move following data over
|
91
|
148
|
uint32_t cnt = line_len + 1;
|
92
|
149
|
if (cnsl_line_buff[line_len + 1] == '\n') {
|