You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

108 lines
2.7 KiB

/*
Copyright Jeroen Vreeken (pe1rxq@amsat.org), 2007
Copyright Stichting C.A. Muller Radioastronomiestation, 2007
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 <controller/controller_block.h>
#include <log/log.h>
/*
inputs outputs
nr name nr name
----------------------
| |
---| 0 in 0 out |----
| |
----------------------
*/
struct controller_block_private {
bool *in;
float out;
float gain;
};
static void bool2float_calculate(struct controller_block *bool2float)
{
struct controller_block_private *priv = bool2float->private;
priv->out = *priv->in * priv->gain;
}
static int param_set(struct controller_block *bool2float, char *param, int argc,
va_list val)
{
bool2float->private->gain = va_arg(val, double);
return 0;
}
static struct controller_block_param_list params[] = {
{ "gain", false, param_set, .args = { "double", NULL } },
{ NULL },
};
static struct controller_block_interm_list interms[] = {
{ "in", CONTROLLER_BLOCK_TERM_BOOL, offsetof(struct controller_block_private, in) },
{ NULL }
};
static struct controller_block_outterm_list outterms[] = {
{ "out", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, out) },
{ NULL }
};
static struct controller_block * block_bool2float_create(char *name, int argc, va_list val)
{
struct controller_block *bool2float;
if (!(bool2float = controller_block_alloc("bool2float", name, sizeof(struct controller_block_private))))
return NULL;
bool2float->private->out = 0.0;
bool2float->private->gain = 1.0;
if (controller_block_interm_list_init(bool2float, interms))
goto err_block;
if (controller_block_outterm_list_init(bool2float, outterms))
goto err_block;
bool2float->calculate = bool2float_calculate;
if (controller_block_param_list_add(bool2float, params))
goto err_block;
if (controller_block_add(bool2float))
goto err_block;
return bool2float;
err_block:
controller_block_free(bool2float);
return NULL;
}
BLOCK_CREATE(bool2float) = {
.create = block_bool2float_create,
.args = { NULL },
};