Skip to content

Commit

Permalink
Aux should point to a valid pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
knro committed Mar 27, 2017
1 parent 93b9557 commit 7de115b
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions 3rdparty/indi-mgen/mgenautoguider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ using namespace std;
std::unique_ptr<MGenAutoguider> mgenAutoguider(new MGenAutoguider());
MGenAutoguider & MGenAutoguider::instance() { return *mgenAutoguider; }

const MGIO_INSERT_BUTTON::Button MGIO_Buttons[] = { MGIO_INSERT_BUTTON::IOB_ESC, MGIO_INSERT_BUTTON::IOB_SET, MGIO_INSERT_BUTTON::IOB_UP, MGIO_INSERT_BUTTON::IOB_LEFT,
MGIO_INSERT_BUTTON::IOB_RIGHT, MGIO_INSERT_BUTTON::IOB_DOWN};


/**************************************************************************************
** Return properties of device->
Expand Down Expand Up @@ -92,7 +95,7 @@ bool MGenAutoguider::ISNewSwitch(const char *dev, const char *name, ISState *sta
{
IUUpdateSwitch(&ui.buttons.properties[0], states, names, n);
ISwitch * const key_switch = IUFindOnSwitch(&ui.buttons.properties[0]);
MGIO_INSERT_BUTTON::Button button = static_cast<MGIO_INSERT_BUTTON::Button>(*(reinterpret_cast<int*>(key_switch->aux)));
MGIO_INSERT_BUTTON::Button button = *(reinterpret_cast<MGIO_INSERT_BUTTON::Button*>(key_switch->aux));
MGIO_INSERT_BUTTON(button).ask(*device);
key_switch->s = ISS_OFF;
ui.buttons.properties[0].s = IPS_OK;
Expand All @@ -102,7 +105,7 @@ bool MGenAutoguider::ISNewSwitch(const char *dev, const char *name, ISState *sta
{
IUUpdateSwitch(&ui.buttons.properties[1], states, names, n);
ISwitch * const key_switch = IUFindOnSwitch(&ui.buttons.properties[1]);
MGIO_INSERT_BUTTON::Button button = static_cast<MGIO_INSERT_BUTTON::Button>(*(reinterpret_cast<int*>(key_switch->aux)));
MGIO_INSERT_BUTTON::Button button = *(reinterpret_cast<MGIO_INSERT_BUTTON::Button*>(key_switch->aux));
MGIO_INSERT_BUTTON(button).ask(*device);
key_switch->s = ISS_OFF;
ui.buttons.properties[1].s = IPS_OK;
Expand Down Expand Up @@ -220,17 +223,17 @@ bool MGenAutoguider::initProperties()
IUFillNumberVector(&ui.framerate.property, &ui.framerate.number, 1, getDeviceName(), "MGEN_UI_OPTIONS", "UI", TAB, IP_RW, 60, IPS_IDLE);

IUFillSwitch(&ui.buttons.switches[0], "MGEN_UI_BUTTON_ESC", "ESC", ISS_OFF);
ui.buttons.switches[0].aux = (void*) MGIO_INSERT_BUTTON::IOB_ESC;
ui.buttons.switches[0].aux = (void *)&MGIO_Buttons[0];
IUFillSwitch(&ui.buttons.switches[1], "MGEN_UI_BUTTON_SET", "SET", ISS_OFF);
ui.buttons.switches[1].aux = (void*) MGIO_INSERT_BUTTON::IOB_SET;
ui.buttons.switches[1].aux = (void *)&MGIO_Buttons[1];
IUFillSwitch(&ui.buttons.switches[2], "MGEN_UI_BUTTON_UP", "UP", ISS_OFF);
ui.buttons.switches[2].aux = (void*) MGIO_INSERT_BUTTON::IOB_UP;
ui.buttons.switches[2].aux = (void *)&MGIO_Buttons[2];
IUFillSwitch(&ui.buttons.switches[3], "MGEN_UI_BUTTON_LEFT", "LEFT", ISS_OFF);
ui.buttons.switches[3].aux = (void*) MGIO_INSERT_BUTTON::IOB_LEFT;
ui.buttons.switches[3].aux = (void *)&MGIO_Buttons[3];
IUFillSwitch(&ui.buttons.switches[4], "MGEN_UI_BUTTON_RIGHT", "RIGHT", ISS_OFF);
ui.buttons.switches[4].aux = (void*) MGIO_INSERT_BUTTON::IOB_RIGHT;
ui.buttons.switches[4].aux = (void *)&MGIO_Buttons[4];
IUFillSwitch(&ui.buttons.switches[5], "MGEN_UI_BUTTON_DOWN", "DOWN", ISS_OFF);
ui.buttons.switches[5].aux = (void*) MGIO_INSERT_BUTTON::IOB_DOWN;
ui.buttons.switches[5].aux = (void *)&MGIO_Buttons[5];
/* ESC SET
* UP LEFT RIGHT DOWN
*/
Expand Down

1 comment on commit 7de115b

@TallFurryMan
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaah I think I see where the confusion is: in my original code, the aux value IS the button value. Integer converted to void*, converted back to integer. Awfully unclear, perhaps.

Please sign in to comment.