Sygaldry
Loading...
Searching...
No Matches
sygsa-trill_craft.hpp
1#pragma once
2/*
3Copyright 2021-2023 Edu Meneses https://www.edumeneses.com, Metalab - Société
4des Arts Technologiques (SAT), Input Devices and Music Interaction Laboratory
5(IDMIL), McGill University
6
7Copyright 2023 Travis J. West, https://traviswest.ca, Input Devices and Music
8Interaction Laboratory (IDMIL), Centre for Interdisciplinary Research in Music
9Media and Technology (CIRMMT), McGill University, Montréal, Canada, and Univ.
10Lille, Inria, CNRS, Centrale Lille, UMR 9189 CRIStAL, F-59000 Lille, France
11
12SPDX-License-Identifier: MIT
13*/
14
15#include <limits>
16#include <cstdint>
17#include "sygah-metadata.hpp"
18#include "sygah-endpoints.hpp"
19
20namespace sygaldry { namespace sygsa {
25
26struct TrillCraft
27: name_<"Trill Craft">
28, description_<"A capacitive touch sensor with 30 electrodes to be connected by "
29 "the user. Operates in DIFF mode only. See "
30 "https://learn.bela.io/using-trill/settings-and-sensitivity/ "
31 "for more information on configuration."
32 >
33, author_<"Edu Meneses, Travis J. West">
34, copyright_<"Copyright 2023 Sygaldry Contributors">
35, license_<"SPDX-License-Identifier: MIT">
36, version_<"0.0.0">
37{
38 static constexpr unsigned int channels = 30;
39 struct inputs_t {
40 // TODO: set baseline, speed and resolution, noise threshold, prescaler
41 slider_message<"prescaler", "measurement gain adjustment"
42 , uint8_t, 1, 8, 1
43 , tag_session_data
44 > prescaler;
45 slider_message<"noise threshold", "threshold for ignoring low-level noise"
46 , uint8_t, 0, 255, 0
47 , tag_session_data
48 > noise_threshold;
49 slider_message<"sampling speed"
50 , "0 - ultra fast (57 to 2800 us per sensor), "
51 "3 - slow (205 to 22000 us per sensor). "
52 "Broad sampling rate adjustment; see also resolution"
53 , uint8_t, 0, 3, 0
54 , tag_session_data
55 > speed;
56 slider_message<"resolution"
57 , "measurement resolution in bits; "
58 "higher resolutions reduce effective sampling rate"
59 , uint8_t, 9, 16, 9
60 , tag_session_data
61 > resolution;
62 bng<"update baseline"
63 , "reset the baseline capacitance based on the current sensor state."
64 "Avoid touching the sensor while updating the baseline reading."
65 > update_baseline;
66
67 /* NOTE: the IDAC value method provided by the Trill API seems not to be of
68 any use. According to the datasheet linked from the Bela API documentation
69
70 (https://www.infineon.com/dgdl/Infineon-CapSense_Sigma-Delta_Datasheet_CSD-Software+Module+Datasheets-v02_02-EN.pdf?fileId=8ac78c8c7d0d8da4017d0f9f5d9b0e82&redirId=File_1_2_579),
71
72 this value is overridden by the firmware by default. So don't worry about
73 adding an endpoint for setIDACValue()! */
74
75 // TODO: autoscan, event pin interrupt
76
77 array<"map", channels
78 , "mapping from raw channel to normalized channel, "
79 "e.g. if the 0th element in the map is 5, then the 0th raw"
80 "channel will be written to the normalized channel with index 5."
81 , int, 0, 29, 0
82 , tag_session_data
83 > map;
84 } inputs;
85
86 struct outputs_t {
87 toggle<"running", "indicates successful connection and polling status"> running;
88 text_message<"error status", "indicates error conditions"> error_status;
89
90 array<"raw", channels
91 , "unprocessed difference in capacitance with respect to baseline" // Technically not the actual raw measurement, but close enough?
92 , int, 0, std::numeric_limits<int>::max(), 0
93 // TOOD: what are the actual minimum and maximum values that can be found?
94 > raw;
95 toggle<"any", "indicates presence of any touch"> any;
96 array<"max seen", channels, "the maximum reading seen"
97 , int, 0, decltype(raw)::max(), 0
98 > max_seen;
99 array<"normalized", channels
100 , "normalized capacitance reading"
101 > normalized;
102 array<"mask", channels, "indicates which electrodes are touched"
103 , char, 0, 1, 0
104 > mask;
105 slider<"instant max", "the maximum normalized reading currently"
106 , float
107 > instant_max;
108 } outputs;
109
110 void * pimpl = nullptr;
111
123 void init();
124
126 void main();
127};
128
131} }