Commit bd366c55 authored by Jeroen Vreeken's avatar Jeroen Vreeken
Browse files

Add new bool command block

parent 1da12a12
/*
Copyright Jeroen Vreeken (jeroen@vreken.net), 2014
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <log/log.h>
#include <controller/controller_block.h>
//#include <controller/controller_sample.h>
#include <controller/controller_command.h>
struct controller_block_private {
bool value;
struct controller_command *command;
};
static void command_calculate(struct controller_block *cmd)
{
struct controller_block_private *priv = cmd->private;
struct command_entry c_entry;
if (!controller_command_queue_read(priv->command, &c_entry)) {
priv->value = c_entry.value.b;
}
}
static struct controller_block_outterm_list outterms[] = {
{ "value", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, value) },
{ NULL },
};
struct controller_block * block_command_bool_create(char *name)
{
struct controller_block *cmd;
if (!(cmd = controller_block_alloc("command_bool", name, sizeof(struct controller_block_private))))
return NULL;
cmd->private->value = false;
if (controller_block_outterm_list_init(cmd, outterms))
goto err_block;
cmd->calculate = command_calculate;
controller_block_add(cmd);
cmd->private->command = controller_command_create(
cmd, name, "Boolean");
cmd->private->command->value_type = COMMAND_VALUE_TYPE_BOOL;
cmd->private->command->command_types[0] = COMMAND_PTYPE_SETPOINT;
return cmd;
err_block:
controller_block_free(cmd);
return NULL;
}
......@@ -6,6 +6,7 @@ $(eval $(call SUBDIR,il2c))
BLOCKS := \
add \
bridge_pwm \
command_bool \
counter \
debug \
decoder_uint32_bool \
......
......@@ -77,6 +77,9 @@ blocks {
{ "add", "elevation_position_offset_r_sum" }
{ "add", "elevation_position_offset_l_sum" }
{ "command_bool", "focusbox_plus" }
{ "command_bool", "focusbox_min" }
{ "value_bool", "false" }
}
......@@ -168,8 +171,8 @@ links {
{ "elevation_safety", "torque_out_l","dt_el_l", "torque" , true }
{ "elevation_servo_state", "enable", "dt_el_r", "enable" , true }
{ "elevation_servo_state", "enable", "dt_el_l", "enable" , true }
{ "false", "value", "dt_el_r", "ba1" , true }
{ "false", "value", "dt_el_r", "ba2" , true }
{ "focusbox_plus", "value", "dt_el_r", "ba1" , true }
{ "focusbox_min", "value", "dt_el_r", "ba2" , true }
{ "false", "value", "dt_el_l", "ba1" , true }
{ "false", "value", "dt_el_l", "ba2" , true }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment