Breadcrumbs

oh. deer. god.

By ValkaTR, 3 November, 2022

what a piece of code did i wrote now

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";
}

oh. deer. god.

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;
        }

Tags

Comments1

ValkaTR

1 year 5 months ago

test square root of x: \(\sqrt{x}\)