Add blink strings functionality

add functions to display.cpp
  - void display2_handle();
  - void display2_blinkStrings(const char * strOn, const char * strOff, uint32_t msOn, uint32_t msOff);

control.cpp:
  - blink target length when set button is pressed
  - blink MANUAL when in manual mode
This commit is contained in:
jonny_ji7 2022-08-21 17:30:00 +02:00
parent c8ffd94fe9
commit 9665560bbb
4 changed files with 102 additions and 38 deletions

View File

@ -1,5 +1,7 @@
#pragma once
extern "C" {
#include "driver/adc.h"
}
#include "gpio_evaluateSwitch.hpp"
#include "buzzer.hpp"

View File

@ -320,51 +320,43 @@ void task_control(void *pvParameter)
//---------------------------
//--------- display ---------
//---------------------------
//-- show current position on display1 ---
sprintf(buf_tmp, "1ST %5.4f", (float)lengthNow/1000); //m
//--------------------------
//-------- display1 --------
//--------------------------
//show current position on display
sprintf(buf_tmp, "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);
display1_showString(buf_disp1);
//--- show target length on display2 ---
//sprintf(buf_disp2, "%06.1f cm", (float)lengthTarget/10); //cm
sprintf(buf_tmp, "S0LL%5.3f", (float)lengthTarget/1000); //m
// 1234 5678
display2_showString(buf_tmp);
//--------------------------
//-------- display2 --------
//--------------------------
//setting target length: blink target length
if (SW_SET.state == true){
sprintf(buf_tmp, "S0LL%5.3f", (float)lengthTarget/1000);
display2_blinkStrings(buf_tmp, " ", 400, 100);
}
//manual state: blink "manual"
else if (controlState == MANUAL) {
display2_blinkStrings(" MANUAL ", " ", 1000, 500);
}
//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
// 1234 5678
display2_showString(buf_tmp);
}
//TODO: blink disp2 when set button pressed
//TODO: blink disp2 when preset button pressed (exept manual mode)
//TODO: write "MAN CTL" to disp2 when in manual mode
//TODO: display or blink "REACHED" when reached state and start pressed
//--- write to display ---
//max7219_clear(&display); //results in flickering display if same value anyways
//max7219_draw_text_7seg(&display, 0, buf_disp1);
//max7219_draw_text_7seg(&display, 8, buf_disp2);
// //switch between two display pages
// if (esp_log_timestamp() - timestamp_pageSwitched > 1000){
// timestamp_pageSwitched = esp_log_timestamp();
// page = !page;
// }
// max7219_clear(&display);
// if (page){
// //display current position
// display_current_distance(&display, &encoder);
// } else {
// //display counter
// sprintf(display_buf, "lvl: %02d", count);
// max7219_draw_text_7seg(&display, 0, display_buf);
// //count++;
// }
//sprintf(display_buf, "S0LL 12.3");
//max7219_draw_text_7seg(&display, 8, display_buf);
}
}

View File

@ -5,6 +5,17 @@
static const char *TAG = "display"; //tag for logging
max7219_t display;
bool disp1_blinkMode = false;
char disp2_strOn[20];
char disp2_strOff[20];
bool disp2_state = false;
bool disp2_blinkMode = false;
uint32_t disp2_timestampOn;
uint32_t disp2_timestampOff;
uint32_t disp2_msOn;
uint32_t disp2_msOff;
//========================
//===== init display =====
//========================
@ -62,16 +73,70 @@ void display_ShowWelcomeMsg(){
void display1_showString(const char * buf){
max7219_draw_text_7seg(&display, 0, buf);
max7219_draw_text_7seg(&display, 0, buf);
disp1_blinkMode = false;
}
void display2_showString(const char * buf){
max7219_draw_text_7seg(&display, 8, buf);
max7219_draw_text_7seg(&display, 8, buf);
disp2_blinkMode = false;
}
void display_showString(uint8_t pos, const char * buf){
max7219_draw_text_7seg(&display, pos, buf);
max7219_draw_text_7seg(&display, pos, buf);
}
//function that handles blinking of display2
void display2_handle(){
if (disp2_blinkMode == false){
return;
}
//--- define state on/off ---
if (disp2_state == true){ //display in ON state
if (esp_log_timestamp() - disp2_timestampOn > disp2_msOn){
disp2_state = false;
disp2_timestampOff = esp_log_timestamp();
}
} else { //display in OFF state
if (esp_log_timestamp() - disp2_timestampOff > disp2_msOff) {
disp2_state = true;
disp2_timestampOn = esp_log_timestamp();
}
}
//--- draw text of current state ---
if (disp2_state) {
max7219_draw_text_7seg(&display, 8, disp2_strOn);
} else {
max7219_draw_text_7seg(&display, 8, disp2_strOff);
}
}
//function switches between two strings in a given interval
void display2_blinkStrings(const char * strOn, const char * strOff, uint32_t msOn, uint32_t msOff){
//copy variables
strcpy(disp2_strOn, strOn);
strcpy(disp2_strOff, strOff);
disp2_msOn = msOn;
disp2_msOff = msOff;
//set to blink mode
disp2_blinkMode = true;
//run handle function for display update
display2_handle();
}
// //---------------------------
// //--------- display ---------
// //---------------------------

View File

@ -23,3 +23,8 @@ void display_ShowWelcomeMsg();
void display1_showString(const char * buf);
void display2_showString(const char * buf);
void display_showString(uint8_t pos, const char * buf);
//function that handles blinking of display2
void display2_handle();
//function switches between two strings in a given interval
void display2_blinkStrings(const char * strOn, const char * strOff, uint32_t msOn, uint32_t msOff);