-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathknob.cpp
42 lines (32 loc) · 967 Bytes
/
knob.cpp
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
#include <stdlib.h>
#include "hal.h"
#include <FreeRTOS.h>
#include <task.h>
#include <semphr.h>
#include <queue.h>
#include "knob.h"
#include "format.h"
#include "main.h"
volatile uint8_t KNOB_Tick=15;
#ifdef __cplusplus
extern "C"
#endif
void vTaskKNOB(void* pvParameters)
{ // ADC_Configuration();
uint8_t Tick=KNOB_Tick;
for( ; ; )
{ vTaskDelay(40);
xSemaphoreTake(ADC1_Mutex, portMAX_DELAY);
uint16_t Knob = ADC_Read_Knob();
xSemaphoreGive(ADC1_Mutex);
uint16_t PrevKnob = ((uint16_t)Tick<<8)+0x80;
int16_t Err = Knob-PrevKnob;
if(abs(Err)>=(0x80+0x20)) // 0x20 is the histeresis to avoid noisy input
{ KNOB_Tick = (Tick = (Knob>>8)); Play(Play_Oct_1 | Tick, 10);
// xSemaphoreTake(CONS_Mutex, portMAX_DELAY);
// Format_UnsDec(CONS_UART_Write, (uint16_t)Tick);
// CONS_UART_Write('\r'); CONS_UART_Write('\n');
// xSemaphoreGive(CONS_Mutex);
}
}
}