Announcement

Collapse
No announcement yet.

Is this a valid way to read a dipswitch?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • pkourany
    replied


    Baran,

    See my email in regards to this issue. Your code seems to compile fine for me!

    Paul

    Leave a comment:


  • CompuGrow
    replied


    Hi Again,

    Thank you so much for the clarification. I extracted the routines you inserted in the arduino sketch until I had just the dipswitch data and the switch was responsive, displaying 0, 1, or 2 depending on the position - perfect!

    I then took all the parts of this sketch and began moving them into my sketch, eliminating redundancy. I seem to be having a problem in my void handleGenieEvent (void) section. Will what I am doing work - mixing genieFrame Event; and genieFrame reply; ?

    What happens is that when I move the void dipSwitchEvent portion into my sketch [found at the end of my handleGenieEvent section below], I get an error compiling that says I have too few arguments to function. I wonder what arguments could have been dropped, as it works just fine in the stand alone demo when i am not packing lots of events into my event handler.

    Does anything come readily to mind?

    Thank you - Baran





    void handleGenieEvent (void){ int keyboardValue; genieFrame Event; genieDequeueEvent(&Event); int dipswitch_val; genieFrame reply; genieDequeueEvent(&reply); // Remove this event from the queue //If the cmd received is from a Reported Object, which occurs if a Read Object is requested in the main code, reply processed here. if(Event.reportObject.cmd == GENIE_REPORT_OBJ) { if (Event.reportObject.object == GENIE_OBJ_DIPSW) // If the Reported Message was from a DIP switch { dipswitch_val = genieGetEventData(&Event); // Dipswitch1 data into dipswitch_val dipSwitchEvent(Event.reportObject.index, dipswitch_val); // Call your function } } if (reply.reportObject.cmd != GENIE_REPORT_EVENT) // If this event is NOT a Reported Message {// We got here because we have a REPORT_OBJECT message in response to a genieReadObject() commanddigitalWrite (13, 1); // Set the LED to show a different message has been received (invalid to this demo)return ;} else if (reply.reportObject.object == GENIE_OBJ_KEYBOARD) // If this event is from a Keyboard{if (reply.reportObject.index == 0)// If from the pump timing Keyboard [Keyboard0]{ keyboardValue = genieGetEventData(&reply);// Get data from Keyboard0calculatorKey0 (keyboardValue);// pass data to the calculatorKey0 function for processing} if (reply.reportObject.index == 1) //If from the motion detection timing keyboard { keyboardValue = genieGetEventData(&reply); // Get data from Keyboard1 calculatorKey1 (keyboardValue); // pass data on to the calculatorKey1 function for processing } if (reply.reportObject.index == 2) //If from the LED timing keyboard { keyboardValue = genieGetEventData(&reply); // Get data from Keyboard2 calculatorKey2 (keyboardValue); // pass data on to the calculatorKey2 function for processing }elsedigitalWrite (13, 1) ;// If this event is from a different keyboard, set LED as its invalid for this demo}else if (reply.reportObject.object == GENIE_OBJ_WINBUTTON) // If this event is from a button{buttonEvent(reply.reportObject.index);}else if (reply.reportObject.object == GENIE_OBJ_DIPSW) // If this event is from a button{dipSwitchEvent(reply.reportObject.index);}elsedigitalWrite (13, 1); // If this event is from a different object, set LED as its invalid for this demo int r, g, b, w ; genieDequeueEvent(&reply); // Remove this event from the queue if (reply.reportObject.cmd != GENIE_REPORT_EVENT) // If this event is NOT a Reported Message { digitalWrite (13, 1) ; // Set the LED to show a different message has been received (invalid to this demo) return ; } if (reply.reportObject.object == GENIE_OBJ_WINBUTTON) // If this event is from a WinButton { if (reply.reportObject.index == 254) // Button 27 - all Max { setLEDs (255, 255, 255, 255) ; genieWriteObject (GENIE_OBJ_SLIDER, 0, 255) ; genieWriteObject (GENIE_OBJ_SLIDER, 1, 255) ; genieWriteObject (GENIE_OBJ_SLIDER, 2, 255) ; genieWriteObject (GENIE_OBJ_SLIDER, 3, 255) ; } else if (reply.reportObject.index == 80) // Button 28 is all off { resetDisplay () ; } else if (reply.reportObject.index == 255)// Button 80 is random { r = random () % 256 ; g = random () % 256 ; b = random () % 256 ; w = random () % 256 ; setLEDs (r, g, b, w) ; genieWriteObject (GENIE_OBJ_SLIDER, 0, r) ; genieWriteObject (GENIE_OBJ_SLIDER, 1, g) ; genieWriteObject (GENIE_OBJ_SLIDER, 2, b) ; genieWriteObject (GENIE_OBJ_SLIDER, 3, w) ; } else digitalWrite (13, 1) ; // If from another button, set the LED as its invalid for this demo } else if (reply.reportObject.object == GENIE_OBJ_SLIDER) // If this event is from a Slider { if (reply.reportObject.index == 0) // Slider 0 analogWrite (RED_LED, logLed (reply.reportObject.data_lsb)) ; else if (reply.reportObject.index == 1) // Slider 1 analogWrite (GREEN_LED, logLed (reply.reportObject.data_lsb)) ; else if (reply.reportObject.index == 2) // Slider 2 analogWrite (BLUE_LED, logLed (reply.reportObject.data_lsb)) ; else if (reply.reportObject.index == 3) // Slider 3 analogWrite (WHITE_LED, logLed (reply.reportObject.data_lsb)) ; else digitalWrite (13, 1) ; // If from another slider, set the LED as its invalid for this demo } } void dipSwitchEvent(int index, int value){ switch (index) { case 0x01: // If from dipswitch 1 if (value == 0x00) // If position 0 genieWriteObject(GENIE_OBJ_LED_DIGITS, 0x08, display); // redoneoff = display; else if (value == 0x01) // If position 1 genieWriteObject(GENIE_OBJ_LED_DIGITS, 0x03, display); else if (value == 0x02) // If position 2 genieWriteObject(GENIE_OBJ_LED_DIGITS, 0x07, display); // redoneon = display; div> break; }}

    Leave a comment:


  • Doff
    replied


    Hi,

    You cannot use the function

    if (genieReadObject(GENIE_OBJ_DIPSW, 0x00)

    this way (I presume that you are using the latest library?). If you have come across the genieArduino_Demo sketch, it shows how to properly use the genieReadObject function. A comment in the sketch says:

    // The results of this call will be available to myGenieEventHandler() after the display has responded // Do a manual read from the Slider0 object genieReadObject(GENIE_OBJ_SLIDER, 0x00);

    In your code I think you were evaluating if the object has the value specified. Or perhaps you were expecting the function to return the current value of Dipswitch0 (it will not). Again, the results will be available to the event handler. The genieArduino_Demo sketch illustrates this point. Also, the app note

    4D-AN-P4017_ViSi-Genie_Connecting_a_4D_Display_to_an_Arduino_Host

    offers additional explanations on how the sketch works.


    else if (genieReadObject(GENIE_OBJ_DIPSW, 0x02) // If position 2
    Also, please note that in

    genieReadObject(GENIE_OBJ_SLIDER, 0x00);

    GENIE_OBJ_SLIDER is the object, and 0x00 is the index. This is explained in the app note.

    Attached now is a sketch created for your application. This sketch is patterned on the genieArduino_Demo sketch. It is highly recommend that you do the same for your future applications.

    Hope this helps. Attached files dipswitch.zip (3.7 KB)

    Leave a comment:


  • CompuGrow
    started a topic Is this a valid way to read a dipswitch?

    Is this a valid way to read a dipswitch?

    Greetings,

    This code compiles but does not run. Am I on the right track for reading a dipswitch event? In this case (case 01), dipswitch 0 is being tested for positions 0 and 2, if I am doing things correctly. Then again, if I were doing things correctly, it would work.

    Thanks - Baran


    void dipSwitchEvent(int index){switch (index){ case 01:// If from dipswitch 1if (genieReadObject(GENIE_OBJ_DIPSW, 0x00) // If position 0 redoneoff = display; else if (genieReadObject(GENIE_OBJ_DIPSW, 0x02) // If position 2 redoneon = display;
    }
    }
Working...
X