forked from nanovna-v2/NanoVNA2-firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uihw.hpp
85 lines (76 loc) · 2.51 KB
/
uihw.hpp
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
#pragma once
#include <mculib/small_function.hpp>
#include <stdint.h>
// hardware interfacing for the UI
namespace UIHW {
enum class UIEventButtons: uint8_t {
None = 0,
Touch,
LeverLeft, LeverRight, LeverCenter
};
enum class UIEventTypes: uint8_t {
None = 0,
Down, // button down
Up, // button up
Click, // button down then up, with no ticks in between (if tick enabled for this button)
// button down (if tick disabled for this button)
DoubleClick, // two clicks separated by a short interval; the Click event is suppressed in both cases
LongPress, // fires some time after button is held down
Tick // regular timed event when button is held down
};
struct UIEvent {
UIEventButtons button;
UIEventTypes type;
// touchscreen was pressed
bool isTouchPress() {
return (button == UIEventButtons::Touch)
&& (type == UIEventTypes::Down);
}
bool isTouchRelease() {
return (button == UIEventButtons::Touch)
&& (type == UIEventTypes::Up);
}
// lever was clicked
bool isLeverClick() {
return (button == UIEventButtons::LeverCenter)
&& (type == UIEventTypes::Click);
}
bool isLeverLongPress() {
return (button == UIEventButtons::LeverCenter)
&& (type == UIEventTypes::LongPress);
}
// jog left or jog right
bool isJog() {
return (button == UIEventButtons::LeverLeft || button == UIEventButtons::LeverRight)
&& (type == UIEventTypes::Down || type == UIEventTypes::Tick);
}
// jog return to center
bool isJogEnd() {
return (button == UIEventButtons::LeverLeft || button == UIEventButtons::LeverRight)
&& (type == UIEventTypes::Up);
}
bool isJogLeft() {
return button == UIEventButtons::LeverLeft &&
(type == UIEventTypes::Down || type == UIEventTypes::Tick);
}
bool isJogRight() {
return button == UIEventButtons::LeverRight &&
(type == UIEventTypes::Down || type == UIEventTypes::Tick);
}
bool isTick() {
return type == UIEventTypes::Tick;
}
};
// hooks
// called directly from interrupt context. When this is called, the
// UI code should usually tell the application to call its
// event handler from the main thread.
extern small_function<void(UIEvent evt)> emitEvent;
// buttonCheckIntervalMicros is how often (in microseconds)
// the application will call checkButtons().
void init(uint32_t buttonCheckIntervalMicros);
// application should call this from a timer interrupt.
void checkButtons();
// get current touch position; returns false if there is no touch
bool touchPosition(uint16_t& x, uint16_t& y);
}