-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlooper_effects.c
97 lines (65 loc) · 2.17 KB
/
looper_effects.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
/*
* looper_effects.c
*
* Created on: Apr 20, 2021
* Author: steph
*/
#include <assert.h>
#include "looper_effects.h"
#include "host_uart_task.h"
#include <stdlib.h>
#include <assert.h>
#include <stdbool.h>
static const uint32_t EFFECT_INCREMENT = 100;
static const uint32_t EFFECT_OFFSET = 102;
static const uint32_t MASTER_OFFSET = 110;
static bool send_all_effects = false;
typedef struct {
uint32_t last_value;
} effect_state_t;
static effect_state_t effects[12];
void init_looper_effects(void) {
uint32_t index;
for(index=0; index<12; index++) {
effects[index].last_value = 0;
}
} // ENd init_effects
void process_effects(uint32_t* adc00values,
uint32_t* adc11values) {
assert(adc00values);
assert(adc11values);
uint32_t index;
uart_msg_u uart_msg;
if(send_all_effects) {
for (index=0; index<12; index++) {
uart_msg.bitfield.message_type = EFFECT;
uart_msg.bitfield.pad_num = EFFECT_OFFSET + index;
uart_msg.bitfield.value = (effects[index].last_value/4096.0)*127;
send_to_host(uart_msg);
}
send_all_effects = false;
return;
}
for (index=0; index<12; index++) {
if (index < 8) {
if(abs(adc00values[index] - effects[index].last_value) > EFFECT_INCREMENT) {
uart_msg.bitfield.message_type = EFFECT;
uart_msg.bitfield.pad_num = EFFECT_OFFSET + index;
uart_msg.bitfield.value = (adc00values[index]/4096.0)*127;
send_to_host(uart_msg);
}
effects[index].last_value = adc00values[index];
} else {
if(abs(adc11values[index] - effects[index].last_value) > EFFECT_INCREMENT) {
uart_msg.bitfield.message_type = EFFECT;
uart_msg.bitfield.pad_num = MASTER_OFFSET + index;
uart_msg.bitfield.value = (adc11values[index]/4096.0)*127;
send_to_host(uart_msg);
}
effects[index].last_value = adc11values[index];
}
}
} // End process_effects
void send_effects(void) {
send_all_effects = true;
} // End send_effects