Steve Karg - 2017-01-26

Review the demo/piface/main.c to see one method (of many) for controlling and reading GPIO using the demo/object/ of your choice.

/**
 * Perform a periodic task for the PiFace card
 */
static void piface_task(void) 
{
    unsigned i = 0;
    BACNET_BINARY_PV present_value = BINARY_INACTIVE;
    bool pin_status = false;

    for (i = 0; i < MAX_BINARY_INPUTS; i++) {
        if (!Binary_Input_Out_Of_Service(i)) {
            present_value = Binary_Input_Present_Value(i);
            pin_status = false;
            if (pifacedigital_digital_read(i)) {
                pin_status = true;
            }
            if (pin_status != PiFace_Pin_Status[i]) {
                PiFace_Pin_Status[i] = pin_status;
                if (pin_status) {
                    /* toggle the input only when button is pressed */
                    if (present_value == BINARY_INACTIVE) {
                        present_value = BINARY_ACTIVE;
                    } else {
                        present_value = BINARY_INACTIVE;
                    }
                    Binary_Input_Present_Value_Set(i, present_value);
                }
            }
        }
    }
    for (i = 0; i < MAX_BINARY_OUTPUTS; i++) {
        if (!Binary_Output_Out_Of_Service(i)) {
            present_value = Binary_Output_Present_Value(i);
            if (present_value == BINARY_INACTIVE) {
                pifacedigital_digital_write(i, 0);
            } else {
                pifacedigital_digital_write(i, 1);
            }
        }
    }   
}