2 * This file is part of the libsigrok project.
4 * Copyright (C) 2014 Bert Vermeulen <bert@biot.com>
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #include "libsigrok.h"
21 #include "libsigrok-internal.h"
24 #define LOG_PREFIX "trigger"
27 SR_API struct sr_trigger *sr_trigger_new(char *name)
29 struct sr_trigger *trig;
31 trig = g_malloc0(sizeof(struct sr_trigger));
33 trig->name = g_strdup(name);
38 SR_API void sr_trigger_free(struct sr_trigger *trig)
40 struct sr_trigger_stage *stage;
43 for (l = trig->stages; l; l = l->next) {
45 g_slist_free_full(stage->matches, g_free);
47 g_slist_free_full(trig->stages, g_free);
53 SR_API struct sr_trigger_stage *sr_trigger_stage_new(struct sr_trigger *trig)
55 struct sr_trigger_stage *stage;
57 stage = g_malloc0(sizeof(struct sr_trigger_stage));
58 stage->stage = g_slist_length(trig->stages);
59 trig->stages = g_slist_append(trig->stages, stage);
64 SR_API int sr_trigger_match_add(struct sr_trigger_stage *stage,
65 struct sr_channel *ch, int trigger_match, float value)
67 struct sr_trigger_match *match;
69 if (ch->type == SR_CHANNEL_LOGIC) {
70 if (trigger_match != SR_TRIGGER_ZERO &&
71 trigger_match != SR_TRIGGER_ONE &&
72 trigger_match != SR_TRIGGER_RISING &&
73 trigger_match != SR_TRIGGER_FALLING &&
74 trigger_match != SR_TRIGGER_EDGE) {
75 sr_err("Invalid trigger match for a logic channel.");
80 } else if (ch->type == SR_CHANNEL_ANALOG) {
81 if (trigger_match != SR_TRIGGER_FALLING &&
82 trigger_match != SR_TRIGGER_OVER &&
83 trigger_match != SR_TRIGGER_UNDER) {
84 sr_err("Invalid trigger match for an analog channel.");
89 match = g_malloc0(sizeof(struct sr_trigger_match));
91 match->match = trigger_match;
93 stage->matches = g_slist_append(stage->matches, match);