Description
What MCU/Processor/Board and compiler are you using?
stm32f103rgt6
What LVGL version are you using?
v7.11
What do you want to achieve?
What I want to implement:
On one screen, when ‘the start button’ is pressed on the screen, the signal is on from the mcu output terminal.
While the signal is outputting, pressing ‘the up button’ increases the signal strength(amplitude), and pressing ‘the down button’ decreases the signal strength.
When any button except the stop button is pressed, the signal should be on.
When the button to reduce the signal strength is pressed, the signal should be reduced in real-time while the signal is output.
When the start button is pressed, the label changes to ‘stop’, and when the button’s label changed to stop is pressed again, the signal stops.
Each button (start/stop button, up button, down button) controls one signal function, but each function should perform the role of start/stop, signal increase, and decrease signal.
I don’t know how to interrupt the button callback while the signal function is on at all.
What have you tried so far?
Code to reproduce
// start button event callback func, matched "start_btn"
void start_event_cb(lv_obj_t * obj, lv_event_t event)
{
//get current touched position
indev1 = lv_indev_get_act();
lv_indev_get_point(indev1, &touched_point);
printf("touched_point->x: %d, touched_point->y: %d\r\n", touched_point.x, touched_point.y);
signal_volt = lv_spinbox_get_value(voltage_spinbox);
if(event == LV_EVENT_VALUE_CHANGED && obj == start_btn)
{
gui_DAC_Start(signal_volt , MODE_STI50Hz, obj, event);
}
}
// signal strength up/down event callback, matched btn_up, btn_down
static void voltage_spinbox_up_event_cb(lv_obj_t * btn, lv_event_t e)
{
if(e == LV_EVENT_PRESSED|| e == LV_EVENT_LONG_PRESSED|| e == LV_EVENT_LONG_PRESSED_REPEAT || e == LV_EVENT_VALUE_CHANGED) {
lv_spinbox_increment(voltage_spinbox);
signal_volt = lv_spinbox_get_value(voltage_spinbox);
gui_DAC_Start(signal_volt, MODE_STI50Hz, btn, e);
}
}
static void voltage_spinbox_down_event_cb(lv_obj_t * btn, lv_event_t e)
{
if(e == LV_EVENT_PRESSED|| e == LV_EVENT_LONG_PRESSED|| e == LV_EVENT_LONG_PRESSED_REPEAT || e == LV_EVENT_VALUE_CHANGED) {
lv_spinbox_decrement(voltage_spinbox);
signal_volt = lv_spinbox_get_value(voltage_spinbox);
gui_DAC_Start(signal_volt, MODE_STI50Hz, btn, e);
}
}
// signal function
void gui_DAC_Start(uint16_t dac_voltage, uint8_t mode, lv_obj_t * obj, lv_event_t event)
{
lv_obj_get_screen(obj);
HAL_DAC_Start(&hdac, DAC_CHANNEL_2);
HAL_DAC_Start(&hdac, DAC_CHANNEL_1);
lv_indev_get_point(indev1, &touched_point);
if(event == LV_EVENT_VALUE_CHANGED)
{
print("CHECKED\r\n");
if (mode == MODE_STI50Hz)
{
while(1)
{
lv_indev_get_point(indev1, &touched_point);
lv_indev_get_act();
lv_event_get_data();
lv_btn_set_state(start_btn, LV_BTN_STATE_RELEASED);
lv_obj_get_child(lv_scr_act(), btn_up);
lv_obj_get_child(lv_scr_act(), btn_down);
signal_volt = lv_spinbox_get_value(voltage_spinbox);
dac_vlt_H_temp = 5000-(3300-(signal_volt *100/2));
dac_vlt_L_temp = 5000-(3300+(signal_volt *100/2));
dac_vlt_H = (dac_vlt_H_temp/10)*62/5;
dac_vlt_L = (dac_vlt_L_temp/10)*62/5;
printf("signal_volt : %d\r\n", signal_volt);
for(on_count = 0; on_count <= 200; on_count++)
{
Signal_Pulse(dac_vlt_H, dac_vlt_L, S_PL_ON);
}
for(on_count = 201; on_count <= 400; on_count++)
{
Signal_Pulse(dac_vlt_L, dac_vlt_L, S_PL_OFF);
}
if ( on_count > 400 ) on_count = 0;
// touched coordinates are on Start button and touched irq is on, goto EXIT03, the signal stops.
if(touched_point.x >= 5 && touched_point.y >= 3 && touched_point.x <=63 && touched_point.y <= 31 && HAL_GPIO_ReadPin(XPT2046_IRQ_GPIO_Port, XPT2046_IRQ_Pin) == GPIO_PIN_RESET)
{
goto EXIT03;
}
// up or down button is clicked, goto EXIT02, the signal strength is changed.
else if(HAL_GPIO_ReadPin(XPT2046_IRQ_GPIO_Port, XPT2046_IRQ_Pin) == GPIO_PIN_RESET)
{
if(obj == btn_up)
{
obj = btn_up;
lv_spinbox_increment(voltage_spinbox);
lv_indev_get_point(indev1, &touched_point);
lv_event_send_refresh(btn_up);
goto EXIT02;
}
if(obj == btn_down)
{
lv_spinbox_decrement(voltage_spinbox);
lv_indev_get_point(indev1, &touched_point);
goto EXIT02;
}
}
EXIT02:
start_stim_signal_btn_event_cb(obj, event);
continue;
}
EXIT03:
// relay_off: the word that the signal is off.
RELAY_OFF;
lv_label_set_text(lv_label_start_stim, "Start");
HAL_DAC_Stop(&hdac, DAC_CHANNEL_1);
HAL_Delay(100);
}
}