Skip to content

Commit 02b6713

Browse files
phoddiemkellner
authored andcommitted
add filter property to pulsecount constructor dictionary
1 parent c8bcf51 commit 02b6713

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

modules/pins/pulsecount/esp32/pulsecount.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void xs_pulsecount_destructor(void *data)
3535
void xs_pulsecount(xsMachine *the)
3636
{
3737
PulseCountRecord pc;
38-
int signal, control;
38+
int signal, control, filter = 100;
3939

4040
xsmcVars(1);
4141

@@ -53,6 +53,11 @@ void xs_pulsecount(xsMachine *the)
5353
xsUnknownError("invalid unit");
5454
}
5555

56+
if (xsmcHas(xsArg(0), xsID_filter)) {
57+
xsmcGet(xsVar(0), xsArg(0), xsID_filter);
58+
filter = xsmcToInteger(xsVar(0));
59+
}
60+
5661
pc.base = 0;
5762
xsmcSetHostChunk(xsThis, &pc, sizeof(PulseCountRecord));
5863

@@ -80,13 +85,12 @@ void xs_pulsecount(xsMachine *the)
8085

8186
pcnt_unit_config(&pcnt_config);
8287

83-
pcnt_set_filter_value(pc.unit, 100);
88+
pcnt_set_filter_value(pc.unit, filter);
8489
pcnt_filter_enable(pc.unit);
8590

8691
pcnt_counter_pause(pc.unit);
8792
pcnt_counter_clear(pc.unit);
8893
pcnt_counter_resume(pc.unit);
89-
9094
}
9195

9296
void xs_pulsecount_get(xsMachine *the)

0 commit comments

Comments
 (0)