mirror of
https://github.com/eddyem/stm32samples.git
synced 2025-12-06 10:45:11 +03:00
display modes: window and menu; check ADC - wery good
This commit is contained in:
parent
13cc2a7e70
commit
a67da85f55
34
F3:F303/NitrogenFlooding/ADUvsR
Normal file
34
F3:F303/NitrogenFlooding/ADUvsR
Normal file
@ -0,0 +1,34 @@
|
||||
1. interchannel difference (with ommeter influence)
|
||||
|
||||
Rx 0 1 2 3 4 5 6 7 8 9
|
||||
106 388 387 387 386 385 385 386 384 384 384
|
||||
425 1064 1063 1064 1064 1063 1064 1063 1063 1062 1062
|
||||
1001 1471 1470 1469 1471 1470 1469 1471 1470 1469 1469
|
||||
2500 1763 1765 1765 1763 1765 1763 1763 1762 1763 1763
|
||||
5020 1888 1888 1888 1888 1889 1888 1889 1888 1890 1889
|
||||
1007 1958 1956 1957 1958 1959 1956 1957 1956 1957 1956
|
||||
|
||||
2. ADU vs R (pure: without ommeter influence)
|
||||
Rx ADU
|
||||
44 173
|
||||
103 380
|
||||
143 507
|
||||
236 778
|
||||
356 1073
|
||||
481 1329
|
||||
723 1718
|
||||
814 1836
|
||||
913 1952
|
||||
1010 2056
|
||||
1145 2181
|
||||
1340 2341
|
||||
1519 2464
|
||||
1701 2574
|
||||
2040 2745
|
||||
2910 3046
|
||||
3760 3231
|
||||
4710 3373
|
||||
5960 3502
|
||||
7420 3603
|
||||
8600 3663
|
||||
10060 3720
|
||||
@ -61,7 +61,7 @@ void process_keys(){
|
||||
}
|
||||
}
|
||||
}
|
||||
if(e != k->event){
|
||||
if(e != k->event || e == EVT_HOLD){
|
||||
k->lastTms = Tms;
|
||||
lastUnsleep = Tms;
|
||||
}
|
||||
|
||||
@ -86,11 +86,15 @@
|
||||
// refresh interval for screen windows
|
||||
#define WINDOW_REFRESH_TIMEOUT (1000)
|
||||
|
||||
typedef uint16_t btnevtmask; // event mask: less 8 - press, high 8 - hold
|
||||
// buttons masks bit0 - button0 etc
|
||||
#define BTN_ESC_MASK (1<<0)
|
||||
#define BTN_LEFT_MASK (1<<1)
|
||||
#define BTN_RIGHT_MASK (1<<2)
|
||||
#define BTN_SEL_MASK (1<<3)
|
||||
#define BTN_PRESS(e, mask) ((e) & (mask))
|
||||
#define BTN_HOLD(e, mask) ((e) & ((mask) << 8))
|
||||
#define BTN_PRESSHOLD(e, mask) ((e) & ((mask) | ((mask)<<8)))
|
||||
|
||||
// global sensors' data
|
||||
extern float Temperature, Pressure, Humidity, Dewpoint;
|
||||
|
||||
@ -40,8 +40,8 @@ static uint32_t ledT[LEDS_AMOUNT] = {0};
|
||||
static uint32_t ledH[LEDS_AMOUNT] = {199, 0, 0, 0};
|
||||
static uint32_t ledL[LEDS_AMOUNT] = {799, 1, 1, 1};
|
||||
|
||||
static void refresh_mainwin(uint8_t evtmask);
|
||||
static void refresh_menu(uint8_t evtmask);
|
||||
static void refresh_mainwin(btnevtmask evtmask);
|
||||
static void refresh_menu(btnevtmask evtmask);
|
||||
|
||||
// current menu
|
||||
static menu *curmenu = &mainmenu;
|
||||
@ -81,17 +81,17 @@ TRUE_INLINE void leds_proc(){
|
||||
}
|
||||
}
|
||||
|
||||
static void refresh_mainwin(uint8_t evtmask){ // ask all parameters and refresh main window with new values
|
||||
if(evtmask & BTN_ESC_MASK){ // force refresh
|
||||
static void refresh_mainwin(btnevtmask evtmask){ // ask all parameters and refresh main window with new values
|
||||
if(BTN_PRESS(evtmask, BTN_ESC_MASK)){ // force refresh
|
||||
Sens_measured_time = Tms - SENSORS_DATA_TIMEOUT*2; // force refresh
|
||||
lastTupd = Tms;
|
||||
return; // just start measurements
|
||||
}
|
||||
if(evtmask & BTN_SEL_MASK){ // switch to menu
|
||||
if(BTN_PRESS(evtmask, BTN_SEL_MASK)){ // switch to menu
|
||||
init_menu(&mainmenu);
|
||||
return;
|
||||
}
|
||||
if(evtmask) return; // left/right buttons - do nothing
|
||||
if(evtmask) return; // left/right buttons press, any hold - do nothing
|
||||
cls();
|
||||
SetFontScale(1); // small menu items labels
|
||||
setBGcolor(COLOR_BLACK); setFGcolor(COLOR_LIGHTGREEN);
|
||||
@ -141,19 +141,19 @@ void init_menu(menu *m){
|
||||
refresh_menu(0);
|
||||
}
|
||||
|
||||
static void refresh_menu(uint8_t evtmask){ // refresh menu with changed selection
|
||||
static void refresh_menu(btnevtmask evtmask){ // refresh menu with changed selection
|
||||
DBG("REFRESH menu");
|
||||
if(!curmenu){
|
||||
init_window(refresh_mainwin);
|
||||
return;
|
||||
}
|
||||
if(evtmask & BTN_ESC_MASK){ // escape to level upper or to main window
|
||||
if(BTN_PRESS(evtmask, BTN_ESC_MASK)){ // escape to level upper or to main window
|
||||
if(curmenu) curmenu = curmenu->parent;
|
||||
if(!curmenu){
|
||||
init_window(refresh_mainwin);
|
||||
return;
|
||||
}
|
||||
} else if(evtmask & BTN_SEL_MASK){
|
||||
} else if(BTN_PRESS(evtmask, BTN_SEL_MASK)){
|
||||
menuitem *selitem = &curmenu->items[curmenu->selected];
|
||||
menu *sub = selitem->submenu;
|
||||
void (*action)() = selitem->action;
|
||||
@ -161,9 +161,9 @@ static void refresh_menu(uint8_t evtmask){ // refresh menu with changed selectio
|
||||
if(sub){ // change to submenu
|
||||
curmenu = sub;
|
||||
} else return;
|
||||
} else if(evtmask & BTN_LEFT_MASK){ // up
|
||||
} else if(BTN_PRESSHOLD(evtmask, BTN_LEFT_MASK)){ // up
|
||||
if(curmenu->selected) --curmenu->selected;
|
||||
} else if(evtmask & BTN_RIGHT_MASK){ // down
|
||||
} else if(BTN_PRESSHOLD(evtmask, BTN_RIGHT_MASK)){ // down
|
||||
if(curmenu->selected < curmenu->nitems - 1) ++curmenu->selected;
|
||||
}
|
||||
cls();
|
||||
@ -198,15 +198,21 @@ static void refresh_menu(uint8_t evtmask){ // refresh menu with changed selectio
|
||||
* 2 - down
|
||||
* 3 - select/menu
|
||||
*/
|
||||
TRUE_INLINE uint8_t btns_proc(){
|
||||
#if BTNSNO > 8
|
||||
#pragma error "Change this code!"
|
||||
#endif
|
||||
TRUE_INLINE btnevtmask btns_proc(){
|
||||
static uint32_t lastT = 0;
|
||||
uint8_t evtmask = 0; // bitmask for active buttons (==1)
|
||||
btnevtmask evtmask = 0; // bitmask for active buttons (==1)
|
||||
static keyevent lastevent[BTNSNO] = {0};
|
||||
if(lastUnsleep == lastT) return 0; // no buttons activity
|
||||
lastT = lastUnsleep;
|
||||
for(int i = 0; i < BTNSNO; ++i){
|
||||
keyevent evt = keystate(i, NULL); // T may be used for doubleclick detection
|
||||
if(evt == EVT_PRESS && lastevent[i] != EVT_PRESS) evtmask |= 1<<i;
|
||||
if(evt == EVT_HOLD){
|
||||
evtmask |= (0x100 << i);
|
||||
}
|
||||
lastevent[i] = evt;
|
||||
}
|
||||
if(!evtmask) return 0;
|
||||
@ -219,7 +225,7 @@ void indication_process(){
|
||||
if(!LEDsON) return;
|
||||
leds_proc();
|
||||
if(ScrnState != SCREEN_RELAX) return; // dont process buttons when screen in updating state
|
||||
uint8_t e = btns_proc();
|
||||
btnevtmask e = btns_proc();
|
||||
if(dispstate == DISP_WINDOW){ // send refresh by timeout event
|
||||
if(e) lastTupd = Tms;
|
||||
else if(Tms - lastTupd > WINDOW_REFRESH_TIMEOUT){
|
||||
|
||||
@ -24,17 +24,26 @@
|
||||
#include "strfunc.h"
|
||||
#include "usb.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
// integer parameter to change
|
||||
typedef struct{
|
||||
uint32_t min;
|
||||
uint32_t max;
|
||||
uint32_t cur;
|
||||
uint32_t *val;
|
||||
} u32par;
|
||||
int32_t min;
|
||||
int32_t max;
|
||||
int32_t cur;
|
||||
int32_t *val;
|
||||
} i32par_t;
|
||||
|
||||
// function to run after selecting "yes" in yesno window
|
||||
typedef void (*yesfun_t)();
|
||||
yesfun_t yesfunction = NULL;
|
||||
|
||||
// current parameter of uint32_t setter
|
||||
static u32par u32parameter = {0};
|
||||
static i32par_t i32parameter = {0};
|
||||
|
||||
// string buffer for non-constant parname
|
||||
#define PARNMBUFSZ (63)
|
||||
static char parnmbuff[PARNMBUFSZ+1];
|
||||
static const char *parname = NULL;
|
||||
|
||||
// upper level menu to return from subwindow functions
|
||||
@ -43,6 +52,7 @@ static menu *uplevel = NULL;
|
||||
static void showadc(menu *m);
|
||||
static void htr1(menu *m);
|
||||
static void htr2(menu *m);
|
||||
static void savesettings(menu *m);
|
||||
|
||||
static void testx(const char *text){
|
||||
USB_sendstr(text);
|
||||
@ -55,29 +65,28 @@ static void stest1(menu _U_ *m){testx("sub 1");}
|
||||
static void stest2(menu _U_ *m){testx("sub 2");}
|
||||
static void stest3(menu _U_ *m){testx("sub 3");}
|
||||
static void stest4(menu _U_ *m){testx("sub 4");}
|
||||
static void stest5(menu _U_ *m){testx("sub 5");}
|
||||
|
||||
|
||||
static menuitem submenu1items[] = {
|
||||
static menuitem settingsmenuitems[] = {
|
||||
{"test 1", NULL, stest1},
|
||||
{"test 2", NULL, stest2},
|
||||
{"test 3", NULL, stest3},
|
||||
{"test 4", NULL, stest4},
|
||||
{"test 5", NULL, stest5},
|
||||
{"Save", NULL, savesettings},
|
||||
};
|
||||
|
||||
static menu submenu1 = {
|
||||
static menu settingsmenu = {
|
||||
.parent = &mainmenu,
|
||||
.nitems = 5,
|
||||
.selected = 0,
|
||||
.items = submenu1items
|
||||
.items = settingsmenuitems
|
||||
};
|
||||
|
||||
static menuitem mainmenuitems[] = {
|
||||
{"ADC raw data", NULL, showadc},
|
||||
{"Heater1 power", NULL, htr1},
|
||||
{"Heater2 power", NULL, htr2},
|
||||
{"Submenu1", &submenu1, NULL},
|
||||
{"Settings", &settingsmenu, NULL},
|
||||
{"Test3", NULL, test3},
|
||||
{"Test4", NULL, test4},
|
||||
};
|
||||
@ -89,8 +98,8 @@ menu mainmenu = {
|
||||
.items = mainmenuitems
|
||||
};
|
||||
|
||||
static void refresh_adcwin(uint8_t evtmask){
|
||||
if(evtmask & BTN_ESC_MASK || evtmask & BTN_SEL_MASK){ // switch to menu
|
||||
static void refresh_adcwin(btnevtmask evtmask){
|
||||
if(BTN_PRESS(evtmask, BTN_ESC_MASK | BTN_SEL_MASK)){ // switch to menu
|
||||
init_menu(uplevel);
|
||||
return;
|
||||
}
|
||||
@ -127,20 +136,28 @@ static void showadc(menu *m){
|
||||
}
|
||||
|
||||
// window of uint32_t setter
|
||||
static void refresh_u32setter(uint8_t evtmask){
|
||||
static void refresh_i32setter(btnevtmask evtmask){
|
||||
int selected = 0;
|
||||
if(evtmask & BTN_ESC_MASK){ // return to main menu
|
||||
if(BTN_PRESS(evtmask, BTN_ESC_MASK)){ // return to main menu
|
||||
init_menu(uplevel);
|
||||
return;
|
||||
}
|
||||
cls();
|
||||
if(evtmask & BTN_SEL_MASK){ // change value
|
||||
*u32parameter.val = u32parameter.cur;
|
||||
int incrdecr = 0;
|
||||
if(BTN_PRESS(evtmask, BTN_SEL_MASK)){ // change value
|
||||
*i32parameter.val = i32parameter.cur;
|
||||
selected = 1;
|
||||
} else if(evtmask & BTN_LEFT_MASK){ // decrement
|
||||
if(u32parameter.cur > u32parameter.min) --u32parameter.cur;
|
||||
} else if(evtmask & BTN_RIGHT_MASK){ // increment
|
||||
if(u32parameter.cur < u32parameter.max) ++u32parameter.cur;
|
||||
} else if(BTN_PRESSHOLD(evtmask, BTN_LEFT_MASK)){ // decrement
|
||||
if(BTN_HOLD(evtmask, BTN_LEFT_MASK)) incrdecr = -3;
|
||||
else incrdecr = -1;
|
||||
} else if(BTN_PRESSHOLD(evtmask, BTN_RIGHT_MASK)){ // increment
|
||||
if(BTN_HOLD(evtmask, BTN_RIGHT_MASK)) incrdecr = 3;
|
||||
else incrdecr = 1;
|
||||
}
|
||||
if(incrdecr){
|
||||
i32parameter.cur += incrdecr;
|
||||
if(i32parameter.cur < i32parameter.min) i32parameter.cur = i32parameter.min;
|
||||
if(i32parameter.cur > i32parameter.max) i32parameter.cur = i32parameter.max;
|
||||
}
|
||||
setFGcolor(COLOR_CHOCOLATE);
|
||||
SetFontScale(2);
|
||||
@ -150,18 +167,62 @@ static void refresh_u32setter(uint8_t evtmask){
|
||||
Y += fontheight + fontheight/2;
|
||||
if(selected) setFGcolor(COLOR_GREEN);
|
||||
else setFGcolor(COLOR_BLUE);
|
||||
CenterStringAt(Y, u2str(u32parameter.cur));
|
||||
CenterStringAt(Y, u2str(i32parameter.cur));
|
||||
}
|
||||
|
||||
// init pwm setter
|
||||
static void showpwm(menu *m, int nccr){
|
||||
u32parameter.max = 100;
|
||||
u32parameter.min = 0;
|
||||
u32parameter.cur = (nccr == 3) ? TIM3->CCR3 : TIM3->CCR4;
|
||||
u32parameter.val = (nccr == 3) ? (uint32_t*) &TIM3->CCR3 : (uint32_t*) &TIM3->CCR4;
|
||||
i32parameter.max = PWM_CCR_MAX;
|
||||
i32parameter.min = 0;
|
||||
i32parameter.cur = (nccr == 3) ? TIM3->CCR3 : TIM3->CCR4;
|
||||
i32parameter.val = (nccr == 3) ? (int32_t*) &TIM3->CCR3 : (int32_t*) &TIM3->CCR4;
|
||||
parname = m->items[m->selected].text;
|
||||
uplevel = m;
|
||||
init_window(refresh_u32setter);
|
||||
init_window(refresh_i32setter);
|
||||
}
|
||||
static void htr1(menu *m){showpwm(m, 3);}
|
||||
static void htr2(menu *m){showpwm(m, 4);}
|
||||
|
||||
|
||||
static void refresh_yesno(btnevtmask evtmask){
|
||||
if(BTN_PRESS(evtmask, BTN_ESC_MASK)){ // return to main menu
|
||||
init_menu(uplevel);
|
||||
return;
|
||||
}
|
||||
cls();
|
||||
const char *msgs[] = {"No", "Yes"};
|
||||
static int current = 0; // current item: "NO"
|
||||
int selected = 0; // not selected
|
||||
if(BTN_PRESS(evtmask, BTN_SEL_MASK)){ // change value
|
||||
selected = 1;
|
||||
} else if(BTN_PRESS(evtmask, BTN_LEFT_MASK | BTN_RIGHT_MASK)){
|
||||
current = !current;
|
||||
}
|
||||
setFGcolor(COLOR_CHOCOLATE);
|
||||
SetFontScale(2);
|
||||
int Y = fontheight + fontheight/2;
|
||||
CenterStringAt(Y, parname);
|
||||
SetFontScale(3);
|
||||
Y += fontheight + fontheight/2;
|
||||
if(selected) setFGcolor(COLOR_GREEN);
|
||||
else setFGcolor(COLOR_BLUE);
|
||||
CenterStringAt(Y, msgs[current]);
|
||||
if(selected && current == 1) yesfunction();
|
||||
}
|
||||
|
||||
static void savesdummy(){
|
||||
USB_sendstr("Settings saved\n");
|
||||
}
|
||||
// save current settings
|
||||
static void savesettings(menu *m){
|
||||
yesfunction = savesdummy;
|
||||
uplevel = m;
|
||||
const char *p = m->items[m->selected].text;
|
||||
int l = strlen(p);
|
||||
if(l > PARNMBUFSZ-1) l = PARNMBUFSZ-1;
|
||||
strncpy(parnmbuff, p, l);
|
||||
parnmbuff[l] = '?';
|
||||
parnmbuff[l+1] = 0;
|
||||
parname = parnmbuff;
|
||||
init_window(refresh_yesno);
|
||||
}
|
||||
|
||||
@ -18,6 +18,8 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "hardware.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
struct _menu_;
|
||||
@ -37,4 +39,4 @@ typedef struct _menu_{
|
||||
extern menu mainmenu;
|
||||
|
||||
// subwindow handler
|
||||
typedef void (*window_handler)(uint8_t evtmask);
|
||||
typedef void (*window_handler)(btnevtmask evtmask);
|
||||
|
||||
Binary file not shown.
@ -161,9 +161,9 @@ static int adcon(const char *cmd, int _U_ parno, const char *c, int32_t i){
|
||||
static int adcval(const char *cmd, int parno, const char _U_ *c, int32_t i){
|
||||
if(parno >= NUMBER_OF_ADC_CHANNELS) return RET_WRONGPARNO;
|
||||
if(parno < 0){ // all channels
|
||||
for(i = 0; i < NUMBER_OF_ADC_CHANNELS; ++i) sendkey(cmd, i, getADCval(i));
|
||||
for(i = 0; i < NUMBER_OF_ADC_CHANNELS; ++i) sendkey(cmd, i, ADCvals[i]);
|
||||
}else
|
||||
sendkey(cmd, parno, getADCval(parno));
|
||||
sendkey(cmd, parno, ADCvals[i]);
|
||||
return RET_GOOD;
|
||||
}
|
||||
static int adcvoltage(const char *cmd, int parno, const char _U_ *c, int32_t i){
|
||||
|
||||
@ -133,7 +133,7 @@ int spi_read(uint8_t *data, uint32_t n){
|
||||
SPIDR = 0;
|
||||
WAITX(!(SPI2->SR & SPI_SR_RXNE));
|
||||
data[x] = SPIDR;
|
||||
USB_sendstr("rd got "); USB_sendstr(uhex2str(data[x]));
|
||||
//USB_sendstr("rd got "); USB_sendstr(uhex2str(data[x]));
|
||||
newline();
|
||||
}
|
||||
return 1;
|
||||
|
||||
@ -1,2 +1,2 @@
|
||||
#define BUILD_NUMBER "280"
|
||||
#define BUILD_NUMBER "294"
|
||||
#define BUILD_DATE "2023-05-14"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user