Show manual speed lvl; Change buf

- when in manual mode blink between 'manual' and motor 'lvl' on bottom
  display
- optimize buffer variables and sizes
This commit is contained in:
jonny_ji7 2022-08-22 18:27:28 +02:00
parent 586c335896
commit 4e2cc070d1

View File

@ -54,10 +54,8 @@ static const char *TAG = "control"; //tag for logging
const char* systemStateStr[5] = {"COUNTING", "WINDING_START", "WINDING", "TARGET_REACHED", "MANUAL"};
systemState_t controlState = COUNTING;
char buf_disp[20]; //both displays
char buf_disp1[10];// 8 digits + decimal point + \0
char buf_disp2[10];// 8 digits + decimal point + \0
char buf_tmp[15];
char buf10[10];// 8 digits + decimal point + \0
char buf20[20];
rotary_encoder_info_t encoder; //encoder device/info
QueueHandle_t encoder_queue = NULL; //encoder event queue
@ -71,7 +69,7 @@ int lengthTarget = 3000; //target length in mm
int lengthRemaining = 0; //(target - now) length needed for reaching the target
int potiRead = 0; //voltage read from adc
uint32_t timestamp_motorStarted = 0; //timestamp winding started
uint8_t manualSpeedLvl = 0; //current motor speed level in manual mode
//===== change State =====
//function for changing the controlState with log output
@ -309,7 +307,7 @@ void task_control(void *pvParameter)
//read poti value
potiRead = readAdc(ADC_CHANNEL_POTI); //0-4095
//scale poti to speed levels 0-3
uint8_t level = round( (float)potiRead / 4095 * 3 );
manualSpeedLvl = round( (float)potiRead / 4095 * 3 );
//exit manual mode if preset2 released
if ( SW_PRESET2.state == false ) {
changeState(COUNTING);
@ -317,12 +315,12 @@ void task_control(void *pvParameter)
}
//P2 + P1 -> turn left
else if ( SW_PRESET1.state && !SW_PRESET3.state ) {
vfd_setSpeedLevel(level); //TODO: use poti input for level
vfd_setSpeedLevel(manualSpeedLvl); //TODO: use poti input for level
vfd_setState(true, REV);
}
//P2 + P3 -> turn right
else if ( SW_PRESET3.state && !SW_PRESET1.state ) {
vfd_setSpeedLevel(level); //TODO: use poti input for level
vfd_setSpeedLevel(manualSpeedLvl); //TODO: use poti input for level
vfd_setState(true, FWD);
}
//no valid switch combination -> turn off motor
@ -337,11 +335,11 @@ void task_control(void *pvParameter)
//-------- display1 --------
//--------------------------
//show current position on display
sprintf(buf_tmp, "1ST %5.4f", (float)lengthNow/1000);
sprintf(buf20, "1ST %5.4f", (float)lengthNow/1000);
// 123456789
//limit length to 8 digits + decimal point (drop decimal places when it does not fit)
sprintf(buf_disp1, "%.9s", buf_tmp);
displayTop.showString(buf_disp1);
sprintf(buf10, "%.9s", buf20);
displayTop.showString(buf10);
//--------------------------
@ -349,19 +347,20 @@ void task_control(void *pvParameter)
//--------------------------
//setting target length: blink target length
if (SW_SET.state == true){
sprintf(buf_tmp, "S0LL%5.3f", (float)lengthTarget/1000);
displayBot.blinkStrings(buf_tmp, " ", 300, 100);
sprintf(buf10, "S0LL%5.3f", (float)lengthTarget/1000);
displayBot.blinkStrings(buf10, "S0LL ", 300, 100);
}
//manual state: blink "manual"
else if (controlState == MANUAL) {
displayBot.blinkStrings(" MANUAL ", " ", 1000, 800);
sprintf(buf10, " lvl %02i ", manualSpeedLvl);
displayBot.blinkStrings(" MANUAL ", buf10, 1000, 800);
}
//otherwise show target length
else {
//sprintf(buf_disp2, "%06.1f cm", (float)lengthTarget/10); //cm
sprintf(buf_tmp, "S0LL%5.3f", (float)lengthTarget/1000); //m
sprintf(buf10, "S0LL%5.3f", (float)lengthTarget/1000); //m
// 1234 5678
displayBot.showString(buf_tmp);
displayBot.showString(buf10);
}