oh. deer. god.

Submitted by ValkaTR on Thu, 11/03/2022 - 22:37

 

  1. void gpio_set_output( struct MENU_ENTRY *menu_entry )
  2. {
  3. if( menu_entry->user_data < 10 )
  4. gpio_digital_outputs[menu_entry->user_data].state = true;
  5. else
  6. gpio_digital_outputs[menu_entry->user_data - 10].state = false;
  7.  
  8. // Display state of the output
  9. if( gpio_digital_outputs[(menu_entry->user_data < 10 ? menu_entry->user_data : menu_entry->user_data - 10)].state == true )
  10. menu_edit_output[1].data = (void *) "ON";
  11. else
  12. menu_edit_output[1].data = (void *) "OFF";
  13. }

what a piece of code did i wrote now

oh. deer. god.

i placed a ternary operator in array element number

also check this out:

  1. case MENU_COMMAND:
  2. {
  3. // Some hard core C hacking here
  4. //
  5. // The code below takes address to a function and type casts it
  6. // from (void *) to a function which can be invoked
  7.  
  8. void (*function_ptr)(struct MENU_ENTRY *) = (void (*)(struct MENU_ENTRY *)) menu_current[menu_cursor_position].data;
  9. (*function_ptr)( &menu_current[menu_cursor_position] );
  10. break;
  11. }

Comments