-
Notifications
You must be signed in to change notification settings - Fork 23
/
zyncoder_test.c
105 lines (91 loc) · 2.78 KB
/
zyncoder_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/*
* ******************************************************************
* ZYNTHIAN PROJECT: Zyncoder Library Test
*
* Test switches & encoders for zynthian kit configurations
*
* Copyright (C) 2015-2021 Fernando Moyano <[email protected]>
*
* ******************************************************************
*
* 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 2 of
* the License, or 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.
*
* For a full copy of the GNU General Public License see the LICENSE.txt file.
*
* ******************************************************************
*/
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include <unistd.h>
#include "gpiod_callback.h"
#include "zynpot.h"
#include "zyncoder.h"
#include "zynaptik.h"
#include "zyncontrol.h"
//-----------------------------------------------------------------------------
// Callback function
//-----------------------------------------------------------------------------
void test_zynpot_cb(int8_t i, int32_t val) {
printf("PT-%d = %d\n", i, val);
}
//-----------------------------------------------------------------------------
// Main function
//-----------------------------------------------------------------------------
int main() {
int i;
printf("Starting ZynCore...\n");
init_zyncontrol();
init_zynmidirouter();
#ifdef DEBUG
if (zynpots[0].type==ZYNPOT_RV112) {
fprintf(stdout, "Range 25 = %d\n", RV112_ADS1115_RANGE_25);
fprintf(stdout, "Range 50 = %d\n", RV112_ADS1115_RANGE_50);
fprintf(stdout, "Range 75 = %d\n", RV112_ADS1115_RANGE_75);
fprintf(stdout, "Range 100 = %d\n", RV112_ADS1115_RANGE_100);
}
#endif
int last_zynswitch_index = get_last_zynswitch_index();
int num_zynswitches = get_num_zynswitches();
int num_zynpots = get_num_zynpots();
//Configure zynpots
setup_zynpot_cb(test_zynpot_cb);
for (i=0; i<num_zynpots; i++) {
setup_behaviour_zynpot(i, 0);
}
printf("Testing switches & rotaries...\n");
while(1) {
i=0;
while (i <= last_zynswitch_index) {
int dtus = get_zynswitch(i, 2000000);
if (dtus>0) fprintf(stdout, "SW-%d = %d\n", i, dtus);
i++;
}
/*
for (i=0;i<num_zynpots;i++) {
int32_t val = get_value_zynpot(i);
if (val!=0) {
printf("PT-%d = %d\n", i, val);
}
}
*/
/*
#ifdef ZYNAPTIK_CONFIG
for (i=0;i<4;i++) {
int val=zynaptik_get_cvin(i);
printf("AD-%d = %d\n", i, (int)(val*12*6.144/32767));
usleep(100000);
}
#endif
*/
}
return 0;
}