Merge branch 'main' into display

This commit is contained in:
jonny_ji7 2022-08-21 20:48:35 +02:00
commit 6acf99d894
5 changed files with 32 additions and 18 deletions

View File

@ -34,12 +34,13 @@ buzzer_t::buzzer_t(gpio_num_t gpio_pin_f, uint16_t msGap_f){
//=========== beep ===========
//============================
//function to add a beep command to the queue
void buzzer_t::beep(uint8_t count, uint16_t msOn, uint16_t msOff){
void buzzer_t::beep(uint8_t count, uint16_t msOn, uint16_t msOff, bool noGap){
//create entry struct with provided data
struct beepEntry entryInsert = {
count = count,
msOn = msOn,
msOff = msOff
msOff = msOff,
noGap = noGap
};
// Send a pointer to a struct AMessage object. Don't block if the
@ -83,9 +84,11 @@ void buzzer_t::processQueue(){
gpio_set_level(gpio_pin, 0);
vTaskDelay(entryRead.msOff / portTICK_PERIOD_MS);
}
if( entryRead.noGap == false ){
//wait for minimum gap between beep events
vTaskDelay(msGap / portTICK_PERIOD_MS);
}
}
}else{ //wait for queue to become available
vTaskDelay(50 / portTICK_PERIOD_MS);
}

View File

@ -27,7 +27,7 @@ class buzzer_t {
//--- functions ---
void processQueue(); //has to be run once in a separate task, waits for and processes queued events
void beep(uint8_t count, uint16_t msOn, uint16_t msOff);
void beep(uint8_t count, uint16_t msOn, uint16_t msOff, bool noGap = false);
//void clear(); (TODO - not implemented yet)
//void createTask(); (TODO - not implemented yet)
@ -45,6 +45,7 @@ class buzzer_t {
uint8_t count;
uint16_t msOn;
uint16_t msOff;
bool noGap;
};
//queue for queueing up multiple events while one is still processing

View File

@ -11,5 +11,5 @@ gpio_evaluatedSwitch SW_PRESET2(GPIO_SW_PRESET2, false, true); //pullup false, I
gpio_evaluatedSwitch SW_PRESET3(GPIO_SW_PRESET3, false, true); //pullup false, INVERTED (switch to 3V3, pulldown on pcb soldered)
//create buzzer object with gap between queued events of 100ms
buzzer_t buzzer(GPIO_BUZZER, 100);
//create buzzer object with no gap between beep events
buzzer_t buzzer(GPIO_BUZZER, 0);

View File

@ -209,14 +209,24 @@ void task_control(void *pvParameter)
//read adc
potiRead = readAdc(ADC_CHANNEL_POTI); //0-4095
//scale to target length range
int lengthTargetNew = (float)potiRead / 4095 * 50000;
//round to whole meters
lengthTarget = round(lengthTarget / 1000) * 1000;
//update target length and beep if changed
int lengthTargetNew = (float)potiRead / 4095 * 30000;
//apply hysteresis and round to whole meters //TODO optimize this
if (lengthTargetNew % 1000 < 200) { //round down if less than .2 meter
ESP_LOGD(TAG, "Poti input = %d -> rounding down", lengthTargetNew);
lengthTargetNew = (lengthTargetNew/1000 ) * 1000; //round down
} else if (lengthTargetNew % 1000 > 800 ) { //round up if more than .8 meter
ESP_LOGD(TAG, "Poti input = %d -> rounding up", lengthTargetNew);
lengthTargetNew = (lengthTargetNew/1000 + 1) * 1000; //round up
} else {
ESP_LOGD(TAG, "Poti input = %d -> hysteresis", lengthTargetNew);
lengthTargetNew = lengthTarget;
}
//update target length and beep when effectively changed
if (lengthTargetNew != lengthTarget) {
//TODO update lengthTarget only at button release?
lengthTarget = lengthTargetNew;
buzzer.beep(1, 60, 0);
ESP_LOGI(TAG, "Changed target length to %d mm", lengthTarget);
buzzer.beep(1, 25, 10);
}
}
//beep start and end of editing
@ -232,15 +242,15 @@ void task_control(void *pvParameter)
if (controlState != MANUAL) { //dont apply preset length while controlling motor with preset buttons
if (SW_PRESET1.risingEdge){
lengthTarget = 1000;
buzzer.beep(lengthTarget/1000, 50, 30);
buzzer.beep(lengthTarget/1000, 25, 30);
}
else if (SW_PRESET2.risingEdge) {
lengthTarget = 5000;
buzzer.beep(lengthTarget/1000, 50, 30);
buzzer.beep(lengthTarget/1000, 25, 30);
}
else if (SW_PRESET3.risingEdge) {
lengthTarget = 10000;
buzzer.beep(lengthTarget/1000, 50, 30);
buzzer.beep(lengthTarget/1000, 25, 30);
}
}

View File

@ -721,10 +721,10 @@ CONFIG_LOG_DEFAULT_LEVEL_INFO=y
# CONFIG_LOG_DEFAULT_LEVEL_DEBUG is not set
# CONFIG_LOG_DEFAULT_LEVEL_VERBOSE is not set
CONFIG_LOG_DEFAULT_LEVEL=3
CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT=y
# CONFIG_LOG_MAXIMUM_EQUALS_DEFAULT is not set
# CONFIG_LOG_MAXIMUM_LEVEL_DEBUG is not set
# CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE is not set
CONFIG_LOG_MAXIMUM_LEVEL=3
CONFIG_LOG_MAXIMUM_LEVEL_VERBOSE=y
CONFIG_LOG_MAXIMUM_LEVEL=5
CONFIG_LOG_COLORS=y
CONFIG_LOG_TIMESTAMP_SOURCE_RTOS=y
# CONFIG_LOG_TIMESTAMP_SOURCE_SYSTEM is not set