Skip to content

Commit

Permalink
Add IR sensor toggle (f key)
Browse files Browse the repository at this point in the history
  • Loading branch information
vintagepc committed Aug 8, 2022
1 parent 6a70c5e commit 324d615
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
23 changes: 21 additions & 2 deletions hw/arm/prusa/parts/irsensor.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "qemu/osdep.h"
#include "../utility/p404scriptable.h"
#include "../utility/p404_keyclient.h"
#include "../utility/macros.h"
#include "../utility/ScriptHost_C.h"
#include "../utility/ArgHelper.h"
Expand All @@ -45,11 +46,11 @@ struct IRState {
};

enum {
ACT_SET,
ACT_SET,
ACT_TOGGLE,
};

OBJECT_DEFINE_TYPE_SIMPLE_WITH_INTERFACES(IRState, irsensor, IRSENSOR, SYS_BUS_DEVICE, {TYPE_P404_SCRIPTABLE}, {NULL})
OBJECT_DEFINE_TYPE_SIMPLE_WITH_INTERFACES(IRState, irsensor, IRSENSOR, SYS_BUS_DEVICE, {TYPE_P404_SCRIPTABLE}, {TYPE_P404_KEYCLIENT}, {NULL})


static void irsensor_finalize(Object *obj)
Expand Down Expand Up @@ -86,6 +87,17 @@ static int irsensor_process_action(P404ScriptIF *obj, unsigned int action, scrip
return ScriptLS_Finished;
}

static void irsensor_input_handle_key(P404KeyIF *opaque, Key keycode)
{
IRState *s = IRSENSOR(opaque);
if (keycode == 'f')
{
s->state ^=1;
printf("IR sensor toggled - new level: %u\n",s->state);
irsensor_update(s);
}
}

static void irsensor_init(Object *obj)
{
IRState *s = IRSENSOR(obj);
Expand All @@ -98,6 +110,10 @@ static void irsensor_init(Object *obj)
script_register_action(s->handle, "Toggle", "Toggles IR sensor state", ACT_TOGGLE);

scripthost_register_scriptable(s->handle);

p404_key_handle pKey = p404_new_keyhandler(P404_KEYCLIENT(obj));
p404_register_keyhandler(pKey, 'f',"Toggles IR sensor state");

}

static const VMStateDescription vmstate_irsensor = {
Expand All @@ -117,4 +133,7 @@ static void irsensor_class_init(ObjectClass *oc, void *data)
dc->vmsd = &vmstate_irsensor;
P404ScriptIFClass *sc = P404_SCRIPTABLE_CLASS(oc);
sc->ScriptHandler = irsensor_process_action;

P404KeyIFClass *kc = P404_KEYCLIENT_CLASS(oc);
kc->KeyHandler = irsensor_input_handle_key;
}
5 changes: 3 additions & 2 deletions hw/arm/prusa/utility/KeyController.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,14 @@ class KeyController: private Scriptable
std::map<unsigned char, std::vector<IKeyClient*> > m_mClients {};
std::map<unsigned char, std::string> m_mDescrs {};
std::vector<IKeyClient*> m_vAllClients {};
std::map<std::pair<int,bool>, unsigned char> m_qemu2char
{
std::map<std::pair<int,bool>, unsigned char> m_qemu2char
{
{ {0x009F ,true} , 'S'},
{ {0x11 ,false} , 'w'}, // shared with arrow keys for up/down
{ {0x48 ,false} , 'w'}, // shared with arrow keys for up/down
{ {0x1F ,false} , 's'},
{ {0x50 ,false} , 's'},
{ {0x21, false}, 'f'},
{ {0x1c ,false} , 0xd}
};
std::atomic_uchar m_key {0};
Expand Down

0 comments on commit 324d615

Please sign in to comment.