'Need to call a function that acts as an interrupt for main code
I am creating a state machine program for my class that acts like a traffic controller. I have 9 cases that simulate traffic light situation (i.e Case 1: Red Light on N-S roads and Yellow lights on E-W roads). I have no issues setting up the cases but my problem is that I need to create a void function that acts within each case and identifies that a button is being pressed and activates an "override" state. Once this "override" is activated, depending on the case; the code will switch to another state. Below is the expected void function I am supposed to replicate
void clockwise(int gpio, int level, uint32_t tick)
{
if(level == 1) {cycle_direction = 1;}
}
This is what I have:
void emergency(int gpio, int level, uint32_t tick)
{
if(level == 1)
{
override = 1;
}
}
This is how I am trying to apply it in my code:
case 0:
{
if(emergency(BUTTON_LEFT,1,???)) // <----
{
sprintf(command_string,"LCD:CLEAR\n");
serial_send_request(serial_handle, command_string, serial_receive_buffer);
process_serial_response(serial_receive_buffer);
if(serial_device.last_error_code < 0)
{
display_serial_device_error(serial_device.last_error_code);
}
printf("Red Light on N-S and E-W roads.\n");
sprintf(command_string,"LCD:TEXT:State 1\n");
serial_send_request(serial_handle, command_string, serial_receive_buffer);
process_serial_response(serial_receive_buffer);
if(serial_device.last_error_code < 0)
{
display_serial_device_error(serial_device.last_error_code);
}
gpioWrite(LED_RED,1);
sprintf(command_string, "LED:RED:1\n");
debug_message(DEBUG_INFO, temp_string);
serial_send_request(serial_handle, command_string, serial_receive_buffer);
process_serial_response(serial_receive_buffer);
if(serial_device.last_error_code < 0)
{
display_serial_device_error(serial_device.last_error_code);
}
gpioSleep(0,3,0);
break;
}
}
Long story short, the code should work like this:
if(override_function() = non-active state)
{
do some stuff
}
else if (override function() = active state)
{
switch to a different case
}
Does anybody know what I am supposed to use for the 3rd parameter of my function when calling it in the main code? Or does the if statement need to be set up differently?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
