void gpio_set_output( struct MENU_ENTRY *menu_entry ) { if( menu_entry->user_data < 10 ) gpio_digital_outputs[menu_entry->user_data].state = true; else gpio_digital_outputs[menu_entry->user_data - 10].state = false; // Display state of the output if( gpio_digital_outputs[(menu_entry->user_data < 10 ? menu_entry->user_data : menu_entry->user_data - 10)].state == true ) menu_edit_output[1].data = (void *) "ON"; else menu_edit_output[1].data = (void *) "OFF"; }
what a piece of code did i wrote now
i placed a ternary operator in array element number
also check this out:
case MENU_COMMAND: { // Some hard core C hacking here // // The code below takes address to a function and type casts it // from (void *) to a function which can be invoked void (*function_ptr)(struct MENU_ENTRY *) = (void (*)(struct MENU_ENTRY *)) menu_current[menu_cursor_position].data; (*function_ptr)( &menu_current[menu_cursor_position] ); break; }
Comments
test mathjax
test square root of x: \(\sqrt{x}\)