Skip to content

Commit 324d615

Browse files
committed
Add IR sensor toggle (f key)
1 parent 6a70c5e commit 324d615

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

hw/arm/prusa/parts/irsensor.c

+21-2
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
#include "qemu/osdep.h"
2424
#include "../utility/p404scriptable.h"
25+
#include "../utility/p404_keyclient.h"
2526
#include "../utility/macros.h"
2627
#include "../utility/ScriptHost_C.h"
2728
#include "../utility/ArgHelper.h"
@@ -45,11 +46,11 @@ struct IRState {
4546
};
4647

4748
enum {
48-
ACT_SET,
49+
ACT_SET,
4950
ACT_TOGGLE,
5051
};
5152

52-
OBJECT_DEFINE_TYPE_SIMPLE_WITH_INTERFACES(IRState, irsensor, IRSENSOR, SYS_BUS_DEVICE, {TYPE_P404_SCRIPTABLE}, {NULL})
53+
OBJECT_DEFINE_TYPE_SIMPLE_WITH_INTERFACES(IRState, irsensor, IRSENSOR, SYS_BUS_DEVICE, {TYPE_P404_SCRIPTABLE}, {TYPE_P404_KEYCLIENT}, {NULL})
5354

5455

5556
static void irsensor_finalize(Object *obj)
@@ -86,6 +87,17 @@ static int irsensor_process_action(P404ScriptIF *obj, unsigned int action, scrip
8687
return ScriptLS_Finished;
8788
}
8889

90+
static void irsensor_input_handle_key(P404KeyIF *opaque, Key keycode)
91+
{
92+
IRState *s = IRSENSOR(opaque);
93+
if (keycode == 'f')
94+
{
95+
s->state ^=1;
96+
printf("IR sensor toggled - new level: %u\n",s->state);
97+
irsensor_update(s);
98+
}
99+
}
100+
89101
static void irsensor_init(Object *obj)
90102
{
91103
IRState *s = IRSENSOR(obj);
@@ -98,6 +110,10 @@ static void irsensor_init(Object *obj)
98110
script_register_action(s->handle, "Toggle", "Toggles IR sensor state", ACT_TOGGLE);
99111

100112
scripthost_register_scriptable(s->handle);
113+
114+
p404_key_handle pKey = p404_new_keyhandler(P404_KEYCLIENT(obj));
115+
p404_register_keyhandler(pKey, 'f',"Toggles IR sensor state");
116+
101117
}
102118

103119
static const VMStateDescription vmstate_irsensor = {
@@ -117,4 +133,7 @@ static void irsensor_class_init(ObjectClass *oc, void *data)
117133
dc->vmsd = &vmstate_irsensor;
118134
P404ScriptIFClass *sc = P404_SCRIPTABLE_CLASS(oc);
119135
sc->ScriptHandler = irsensor_process_action;
136+
137+
P404KeyIFClass *kc = P404_KEYCLIENT_CLASS(oc);
138+
kc->KeyHandler = irsensor_input_handle_key;
120139
}

hw/arm/prusa/utility/KeyController.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,14 @@ class KeyController: private Scriptable
6767
std::map<unsigned char, std::vector<IKeyClient*> > m_mClients {};
6868
std::map<unsigned char, std::string> m_mDescrs {};
6969
std::vector<IKeyClient*> m_vAllClients {};
70-
std::map<std::pair<int,bool>, unsigned char> m_qemu2char
71-
{
70+
std::map<std::pair<int,bool>, unsigned char> m_qemu2char
71+
{
7272
{ {0x009F ,true} , 'S'},
7373
{ {0x11 ,false} , 'w'}, // shared with arrow keys for up/down
7474
{ {0x48 ,false} , 'w'}, // shared with arrow keys for up/down
7575
{ {0x1F ,false} , 's'},
7676
{ {0x50 ,false} , 's'},
77+
{ {0x21, false}, 'f'},
7778
{ {0x1c ,false} , 0xd}
7879
};
7980
std::atomic_uchar m_key {0};

0 commit comments

Comments
 (0)