需要调用一个函数作为主代码的中断
我正在为我的班级创建一个状态机程序,其作用就像交通控制器。我有 9 个模拟交通灯情况的案例(即案例 1:NS 道路上的红灯和 EW 道路上的黄灯)。我在设置案例时没有任何问题,但我的问题是我需要创建一个空函数,该函数在每个案例中起作用并识别正在按下的按钮并激活“覆盖”状态。一旦激活此“覆盖”,视情况而定;代码将切换到另一种状态。下面是我应该复制的预期 void 函数
void clockwise(int gpio, int level, uint32_t tick)
{
if(level == 1) {cycle_direction = 1;}
}
这就是我所拥有的:
void emergency(int gpio, int level, uint32_t tick)
{
if(level == 1)
{
override = 1;
}
}
这就是我尝试将其应用到我的代码中的方式:
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;
}
}
长话短说,代码应该像这样工作:
if(override_function() = non-active state)
{
do some stuff
}
else if (override function() = active state)
{
switch to a different case
}
有谁知道我应该使用什么在主代码中调用我的函数的第三个参数?或者 if 语句是否需要以不同的方式设置?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论