block_value.c 2.09 KB
Newer Older
Jeroen Vreeken's avatar
Jeroen Vreeken committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/*
	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>

Jeroen Vreeken's avatar
Jeroen Vreeken committed
24
#include <controller/controller_block.h>
Jeroen Vreeken's avatar
Jeroen Vreeken committed
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57

/*
  	 outputs
  	 nr name

  -----------------
  |		  |
  |	 0  value |----
  |		  |
  -----------------
 */

struct controller_block_private {
	float value;
};

static struct controller_block_param_list params[] = {
	{ "value", false },
	{ NULL },
};

static void param_get(struct controller_block *value, int param, void *val)
{
	/* We have only one parameter... */
	*(float*)val = value->private->value;
}

static void param_set(struct controller_block *value, int param, va_list val)
{
	/* we have only one parameter... */
	value->private->value = va_arg(val, double);
}

58
59
60
61
62
static struct controller_block_outterm_list outterms[] = {
	{ "value", CONTROLLER_BLOCK_TERM_FLOAT, offsetof(struct controller_block_private, value) },
	{ NULL }
};

Jeroen Vreeken's avatar
Jeroen Vreeken committed
63
64
65
66
struct controller_block * block_value_create(char *name)
{
	struct controller_block *value;
	
67
	if (!(value = controller_block_alloc("value", name, sizeof(struct controller_block_private))))
Jeroen Vreeken's avatar
Jeroen Vreeken committed
68
69
70
71
		return NULL;

	value->private->value = 0.0;
	
72
73
	if (controller_block_outterm_list_init(value, outterms))
		goto err_block;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
74
75

	if (controller_block_param_list_init(value, params))
76
		goto err_block;
Jeroen Vreeken's avatar
Jeroen Vreeken committed
77
78
79
80
81
82
83

	value->param_get = param_get;
	value->param_set = param_set;

	controller_block_add(value);
	return value;

84
85
err_block:
	controller_block_free(value);
Jeroen Vreeken's avatar
Jeroen Vreeken committed
86
87
	return NULL;
}