mirror of
https://github.com/eddyem/stm32samples.git
synced 2025-12-06 18:55:13 +03:00
Add ADC trigger
This commit is contained in:
parent
1242b8f9ff
commit
926e8d2037
@ -16,4 +16,5 @@ Chronometer for downhill competitions
|
|||||||
- PA14 - TRIG1 - button1/laser/etc (EXTI)
|
- PA14 - TRIG1 - button1/laser/etc (EXTI)
|
||||||
- PA15 - USB pullup
|
- PA15 - USB pullup
|
||||||
|
|
||||||
- PB0,1,2 - free for other functions
|
- PB0 - ADC channel 8
|
||||||
|
- PB1,2 - free for other functions
|
||||||
|
|||||||
@ -17,6 +17,8 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "adc.h"
|
#include "adc.h"
|
||||||
|
#include "flash.h"
|
||||||
|
#include "hardware.h"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief ADC_array - array for ADC channels with median filtering:
|
* @brief ADC_array - array for ADC channels with median filtering:
|
||||||
@ -68,3 +70,19 @@ uint32_t getVdd(){
|
|||||||
vdd /= getADCval(2);
|
vdd /= getADCval(2);
|
||||||
return vdd;
|
return vdd;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void chkADCtrigger(){
|
||||||
|
static uint8_t triggered = 0;
|
||||||
|
savetrigtime();
|
||||||
|
uint16_t val = getADCval(0);
|
||||||
|
if(triggered){ // check untriggered action
|
||||||
|
if(val < the_conf.ADC_min || val > the_conf.ADC_max){
|
||||||
|
triggered = 0;
|
||||||
|
}
|
||||||
|
}else{ // check if thigger shot
|
||||||
|
if(val > the_conf.ADC_min && val < the_conf.ADC_max){
|
||||||
|
triggered = 1;
|
||||||
|
fillshotms(4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -25,5 +25,5 @@ extern uint16_t ADC_array[];
|
|||||||
int32_t getMCUtemp();
|
int32_t getMCUtemp();
|
||||||
uint32_t getVdd();
|
uint32_t getVdd();
|
||||||
uint16_t getADCval(int nch);
|
uint16_t getADCval(int nch);
|
||||||
|
void chkADCtrigger();
|
||||||
#endif // ADC_H
|
#endif // ADC_H
|
||||||
|
|||||||
Binary file not shown.
@ -58,6 +58,8 @@ typedef struct{
|
|||||||
,.trig_pullups = 0xff \
|
,.trig_pullups = 0xff \
|
||||||
,.trigstate = 0 \
|
,.trigstate = 0 \
|
||||||
,.trigpause = {400, 400, 400} \
|
,.trigpause = {400, 400, 400} \
|
||||||
|
,.ADC_min = 1024 \
|
||||||
|
,.ADC_max = 3072 \
|
||||||
}
|
}
|
||||||
|
|
||||||
__attribute__((section(".myvars"))) static const flash_storage Flash_Storage = {
|
__attribute__((section(".myvars"))) static const flash_storage Flash_Storage = {
|
||||||
|
|||||||
@ -38,6 +38,8 @@ typedef struct __attribute__((packed)){
|
|||||||
uint8_t trig_pullups; // trigger pullups: each bit ==0 to set OFF, ==1 to set ON pullup with given number
|
uint8_t trig_pullups; // trigger pullups: each bit ==0 to set OFF, ==1 to set ON pullup with given number
|
||||||
uint8_t trigstate; // level in `triggered` state
|
uint8_t trigstate; // level in `triggered` state
|
||||||
int32_t trigpause[TRIGGERS_AMOUNT]; // pause (ms) for false shots
|
int32_t trigpause[TRIGGERS_AMOUNT]; // pause (ms) for false shots
|
||||||
|
int16_t ADC_min; // min&max values of ADC (shot when ADval > ADC_min && < ADC_max)
|
||||||
|
int16_t ADC_max; // !!! BOTH ARE SIGNED! so you can include 0 & 4096
|
||||||
} user_conf;
|
} user_conf;
|
||||||
|
|
||||||
extern user_conf the_conf;
|
extern user_conf the_conf;
|
||||||
|
|||||||
@ -29,12 +29,13 @@
|
|||||||
|
|
||||||
#include <string.h> // memcpy
|
#include <string.h> // memcpy
|
||||||
|
|
||||||
|
uint8_t LEDSon = 1; // LEDS are working
|
||||||
// ports of triggers
|
// ports of triggers
|
||||||
GPIO_TypeDef *trigport[TRIGGERS_AMOUNT] = {GPIOA, GPIOA, GPIOA};
|
static GPIO_TypeDef *trigport[DIGTRIG_AMOUNT] = {GPIOA, GPIOA, GPIOA};
|
||||||
// pins of triggers: PA13, PA14, PA4
|
// pins of triggers: PA13, PA14, PA4
|
||||||
uint16_t trigpin[TRIGGERS_AMOUNT] = {1<<13, 1<<14, 1<<4};
|
static uint16_t trigpin[DIGTRIG_AMOUNT] = {1<<13, 1<<14, 1<<4};
|
||||||
// value of pin in `triggered` state
|
// value of pin in `triggered` state
|
||||||
uint8_t trigstate[TRIGGERS_AMOUNT];
|
static uint8_t trigstate[DIGTRIG_AMOUNT];
|
||||||
// time of triggers shot
|
// time of triggers shot
|
||||||
trigtime shottime[TRIGGERS_AMOUNT];
|
trigtime shottime[TRIGGERS_AMOUNT];
|
||||||
// Tms value when they shot
|
// Tms value when they shot
|
||||||
@ -64,7 +65,7 @@ static inline void gpio_setup(){
|
|||||||
EXTI->IMR = EXTI_IMR_MR1;
|
EXTI->IMR = EXTI_IMR_MR1;
|
||||||
EXTI->RTSR = EXTI_RTSR_TR1; // rising trigger
|
EXTI->RTSR = EXTI_RTSR_TR1; // rising trigger
|
||||||
// PA4/PA13/PA14 - buttons
|
// PA4/PA13/PA14 - buttons
|
||||||
for(int i = 0; i < TRIGGERS_AMOUNT; ++i){
|
for(int i = 0; i < DIGTRIG_AMOUNT; ++i){
|
||||||
uint16_t pin = trigpin[i];
|
uint16_t pin = trigpin[i];
|
||||||
// fill trigstate array
|
// fill trigstate array
|
||||||
uint8_t trgs = (the_conf.trigstate & (1<<i)) ? 1 : 0;
|
uint8_t trgs = (the_conf.trigstate & (1<<i)) ? 1 : 0;
|
||||||
@ -122,7 +123,7 @@ static inline void adc_setup(){
|
|||||||
|
|
||||||
void hw_setup(){
|
void hw_setup(){
|
||||||
gpio_setup();
|
gpio_setup();
|
||||||
//adc_setup();
|
adc_setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
void exti1_isr(){ // PPS - PA1
|
void exti1_isr(){ // PPS - PA1
|
||||||
@ -132,12 +133,12 @@ void exti1_isr(){ // PPS - PA1
|
|||||||
}
|
}
|
||||||
|
|
||||||
static trigtime trgtm;
|
static trigtime trgtm;
|
||||||
static void savetrigtime(){
|
void savetrigtime(){
|
||||||
trgtm.millis = Timer;
|
trgtm.millis = Timer;
|
||||||
memcpy(&trgtm.Time, ¤t_time, sizeof(curtime));
|
memcpy(&trgtm.Time, ¤t_time, sizeof(curtime));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void fillshotms(int i){
|
void fillshotms(int i){
|
||||||
if(i < 0 || i > TRIGGERS_AMOUNT) return;
|
if(i < 0 || i > TRIGGERS_AMOUNT) return;
|
||||||
if(shotms[i] - Tms > (uint32_t)the_conf.trigpause[i]){
|
if(shotms[i] - Tms > (uint32_t)the_conf.trigpause[i]){
|
||||||
shotms[i] = Tms;
|
shotms[i] = Tms;
|
||||||
@ -146,14 +147,14 @@ static void fillshotms(int i){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void exti4_isr(){ // PA4 - button2
|
void exti4_isr(){ // PA4 - trigger[2]
|
||||||
savetrigtime();
|
savetrigtime();
|
||||||
fillshotms(2);
|
fillshotms(2);
|
||||||
DBG("exti4");
|
DBG("exti4");
|
||||||
EXTI->PR = EXTI_PR_PR4;
|
EXTI->PR = EXTI_PR_PR4;
|
||||||
}
|
}
|
||||||
|
|
||||||
void exti15_10_isr(){ // PA13 - button0, PA14 - button1
|
void exti15_10_isr(){ // PA13 - trigger[0], PA14 - trigger[1]
|
||||||
savetrigtime();
|
savetrigtime();
|
||||||
if(EXTI->PR & EXTI_PR_PR13){
|
if(EXTI->PR & EXTI_PR_PR13){
|
||||||
fillshotms(0);
|
fillshotms(0);
|
||||||
|
|||||||
@ -38,12 +38,14 @@
|
|||||||
#define PPS_pin (1<<1)
|
#define PPS_pin (1<<1)
|
||||||
|
|
||||||
// PPS and triggers state
|
// PPS and triggers state
|
||||||
// amount of triggers, should be less than 9
|
// amount of triggers, should be less than 9; 5 - 0..2 - switches, 3 - LIDAR, 4 - ADC
|
||||||
#define TRIGGERS_AMOUNT (3)
|
#define TRIGGERS_AMOUNT (5)
|
||||||
extern GPIO_TypeDef *trigport[TRIGGERS_AMOUNT];
|
// amount of digital triggers (on interrupts)
|
||||||
extern uint16_t trigpin[TRIGGERS_AMOUNT];
|
#define DIGTRIG_AMOUNT (3)
|
||||||
extern uint8_t trigstate[TRIGGERS_AMOUNT];
|
|
||||||
uint8_t gettrig(uint8_t N);
|
uint8_t gettrig(uint8_t N);
|
||||||
|
void fillshotms(int i);
|
||||||
|
void savetrigtime();
|
||||||
#define GET_PPS() ((GPIOA->IDR & (1<<1)) ? 1 : 0)
|
#define GET_PPS() ((GPIOA->IDR & (1<<1)) ? 1 : 0)
|
||||||
|
|
||||||
// USB pullup - PA15
|
// USB pullup - PA15
|
||||||
@ -52,12 +54,12 @@ uint8_t gettrig(uint8_t N);
|
|||||||
#define USBPU_ON() pin_clear(USBPU_port, USBPU_pin)
|
#define USBPU_ON() pin_clear(USBPU_port, USBPU_pin)
|
||||||
#define USBPU_OFF() pin_set(USBPU_port, USBPU_pin)
|
#define USBPU_OFF() pin_set(USBPU_port, USBPU_pin)
|
||||||
|
|
||||||
#define LED_blink() pin_toggle(LED0_port, LED0_pin)
|
#define LED_blink() do{if(LEDSon)pin_toggle(LED0_port, LED0_pin);}while(0)
|
||||||
#define LED_on() pin_clear(LED0_port, LED0_pin)
|
#define LED_on() do{if(LEDSon)pin_clear(LED0_port, LED0_pin);}while(0)
|
||||||
#define LED_off() pin_set(LED0_port, LED0_pin)
|
#define LED_off() do{if(LEDSon)pin_set(LED0_port, LED0_pin);}while(0)
|
||||||
#define LED1_blink() pin_toggle(LED1_port, LED1_pin)
|
#define LED1_blink() do{if(LEDSon)pin_toggle(LED1_port, LED1_pin);}while(0)
|
||||||
#define LED1_on() pin_clear(LED1_port, LED1_pin)
|
#define LED1_on() do{if(LEDSon)pin_clear(LED1_port, LED1_pin);}while(0)
|
||||||
#define LED1_off() pin_set(LED1_port, LED1_pin)
|
#define LED1_off() do{if(LEDSon)pin_set(LED1_port, LED1_pin);}while(0)
|
||||||
|
|
||||||
// GPS USART == USART2, LIDAR USART == USART3
|
// GPS USART == USART2, LIDAR USART == USART3
|
||||||
#define GPS_USART (2)
|
#define GPS_USART (2)
|
||||||
@ -68,6 +70,8 @@ typedef struct{
|
|||||||
curtime Time;
|
curtime Time;
|
||||||
} trigtime;
|
} trigtime;
|
||||||
|
|
||||||
|
// turn on/off LEDs:
|
||||||
|
extern uint8_t LEDSon;
|
||||||
// time of triggers shot
|
// time of triggers shot
|
||||||
extern trigtime shottime[TRIGGERS_AMOUNT];
|
extern trigtime shottime[TRIGGERS_AMOUNT];
|
||||||
// if trigger[N] shots, the bit N will be 1
|
// if trigger[N] shots, the bit N will be 1
|
||||||
|
|||||||
@ -25,7 +25,7 @@ uint16_t last_lidar_stren = 0;
|
|||||||
uint16_t lidar_triggered_dist = 0;
|
uint16_t lidar_triggered_dist = 0;
|
||||||
|
|
||||||
void parse_lidar_data(char *txt){
|
void parse_lidar_data(char *txt){
|
||||||
static int triggered = 0;
|
static uint8_t triggered = 0;
|
||||||
last_lidar_dist = txt[2] | (txt[3] << 8);
|
last_lidar_dist = txt[2] | (txt[3] << 8);
|
||||||
last_lidar_stren = txt[4] | (txt[5] << 8);
|
last_lidar_stren = txt[4] | (txt[5] << 8);
|
||||||
if(last_lidar_stren < LIDAR_LOWER_STREN) return; // weak signal
|
if(last_lidar_stren < LIDAR_LOWER_STREN) return; // weak signal
|
||||||
@ -46,8 +46,10 @@ void parse_lidar_data(char *txt){
|
|||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if(last_lidar_dist > the_conf.dist_min && last_lidar_dist < the_conf.dist_max){
|
if(last_lidar_dist > the_conf.dist_min && last_lidar_dist < the_conf.dist_max){
|
||||||
|
savetrigtime();
|
||||||
triggered = 1;
|
triggered = 1;
|
||||||
lidar_triggered_dist = last_lidar_dist;
|
lidar_triggered_dist = last_lidar_dist;
|
||||||
|
fillshotms(3);
|
||||||
#ifdef EBUG
|
#ifdef EBUG
|
||||||
SEND("Triggered! distance=");
|
SEND("Triggered! distance=");
|
||||||
printu(1, last_lidar_dist);
|
printu(1, last_lidar_dist);
|
||||||
|
|||||||
@ -19,7 +19,7 @@
|
|||||||
* MA 02110-1301, USA.
|
* MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//#include "adc.h"
|
#include "adc.h"
|
||||||
#include "GPS.h"
|
#include "GPS.h"
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
#include "hardware.h"
|
#include "hardware.h"
|
||||||
@ -174,6 +174,24 @@ static char *get_USB(){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
void linecoding_handler(usb_LineCoding __attribute__((unused)) *lc){ // get/set line coding
|
||||||
|
DBG("linecoding_handler");
|
||||||
|
}*/
|
||||||
|
|
||||||
|
void clstate_handler(uint16_t __attribute__((unused)) val){ // lesser bits of val: DTR|RTS
|
||||||
|
USB_send("Chronometer version " VERSION ".\n");
|
||||||
|
#ifdef EBUG
|
||||||
|
if(val & 1) DBG("RTS set");
|
||||||
|
if(val & 2) DBG("DTR set");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
void break_handler(){ // client disconnected
|
||||||
|
DBG("break_handler");
|
||||||
|
}*/
|
||||||
|
|
||||||
int main(void){
|
int main(void){
|
||||||
uint32_t lastT = 0;
|
uint32_t lastT = 0;
|
||||||
sysreset();
|
sysreset();
|
||||||
@ -185,7 +203,10 @@ int main(void){
|
|||||||
get_userconf();
|
get_userconf();
|
||||||
// !!! hw_setup() should be the first in setup stage
|
// !!! hw_setup() should be the first in setup stage
|
||||||
hw_setup();
|
hw_setup();
|
||||||
|
USB_setup();
|
||||||
|
USBPU_ON();
|
||||||
usarts_setup();
|
usarts_setup();
|
||||||
|
#ifdef EBUG
|
||||||
SEND("Chronometer version " VERSION ".\n");
|
SEND("Chronometer version " VERSION ".\n");
|
||||||
if(RCC->CSR & RCC_CSR_IWDGRSTF){ // watchdog reset occured
|
if(RCC->CSR & RCC_CSR_IWDGRSTF){ // watchdog reset occured
|
||||||
SEND("WDGRESET=1\n");
|
SEND("WDGRESET=1\n");
|
||||||
@ -193,11 +214,10 @@ int main(void){
|
|||||||
if(RCC->CSR & RCC_CSR_SFTRSTF){ // software reset occured
|
if(RCC->CSR & RCC_CSR_SFTRSTF){ // software reset occured
|
||||||
SEND("SOFTRESET=1\n");
|
SEND("SOFTRESET=1\n");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
RCC->CSR |= RCC_CSR_RMVF; // remove reset flags
|
RCC->CSR |= RCC_CSR_RMVF; // remove reset flags
|
||||||
|
|
||||||
USB_setup();
|
|
||||||
iwdg_setup();
|
iwdg_setup();
|
||||||
USBPU_ON();
|
|
||||||
|
|
||||||
while (1){
|
while (1){
|
||||||
IWDG->KR = IWDG_REFRESH; // refresh watchdog
|
IWDG->KR = IWDG_REFRESH; // refresh watchdog
|
||||||
@ -265,6 +285,7 @@ int main(void){
|
|||||||
parse_lidar_data(txt);
|
parse_lidar_data(txt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
chkADCtrigger();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
#include "adc.h"
|
||||||
#include "flash.h"
|
#include "flash.h"
|
||||||
#include "str.h"
|
#include "str.h"
|
||||||
#include "time.h"
|
#include "time.h"
|
||||||
@ -57,18 +58,30 @@ char *getchr(const char *str, char symbol){
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define sendu(x) do{USB_send(u2str(x));}while(0)
|
||||||
|
|
||||||
|
static void sendi(int32_t I){
|
||||||
|
if(I < 0){
|
||||||
|
USB_send("-");
|
||||||
|
I = -I;
|
||||||
|
}
|
||||||
|
USB_send(u2str((uint32_t)I));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief showuserconf - show configuration over USB
|
* @brief showuserconf - show configuration over USB
|
||||||
*/
|
*/
|
||||||
static void showuserconf(){
|
static void showuserconf(){
|
||||||
USB_send("\nCONFIG:\nDISTMIN="); USB_send(u2str(the_conf.dist_min));
|
USB_send("\nCONFIG:\nDISTMIN="); sendu(the_conf.dist_min);
|
||||||
USB_send("\nDISTMAX="); USB_send(u2str(the_conf.dist_max));
|
USB_send("\nDISTMAX="); sendu(the_conf.dist_max);
|
||||||
USB_send("\nPULLUPS="); USB_send(u2str(the_conf.trig_pullups));
|
USB_send("\nADCMIN="); sendi(the_conf.ADC_min);
|
||||||
USB_send("\nTRIGLVL="); USB_send(u2str(the_conf.trigstate));
|
USB_send("\nADCMAX="); sendi(the_conf.ADC_max);
|
||||||
|
USB_send("\nPULLUPS="); sendu(the_conf.trig_pullups);
|
||||||
|
USB_send("\nTRIGLVL="); sendu(the_conf.trigstate);
|
||||||
USB_send("\nTRIGPAUSE={");
|
USB_send("\nTRIGPAUSE={");
|
||||||
for(int i = 0; i < TRIGGERS_AMOUNT; ++i){
|
for(int i = 0; i < TRIGGERS_AMOUNT; ++i){
|
||||||
if(i) USB_send(", ");
|
if(i) USB_send(", ");
|
||||||
USB_send(u2str(the_conf.trigpause[i]));
|
sendu(the_conf.trigpause[i]);
|
||||||
}
|
}
|
||||||
USB_send("}");
|
USB_send("}");
|
||||||
USB_send("\nENDCONFIG\n");
|
USB_send("\nENDCONFIG\n");
|
||||||
@ -89,9 +102,14 @@ int parse_USBCMD(char *cmd){
|
|||||||
IWDG->KR = IWDG_REFRESH;
|
IWDG->KR = IWDG_REFRESH;
|
||||||
if(*cmd == '?'){ // help
|
if(*cmd == '?'){ // help
|
||||||
USB_send("Commands:\n"
|
USB_send("Commands:\n"
|
||||||
|
CMD_ADCMAX " - max ADC value treshold for trigger\n"
|
||||||
|
CMD_ADCMIN " - min -//- (triggered when ADval>min & <max\n"
|
||||||
|
CMD_GETADCVAL " - get ADC value\n"
|
||||||
CMD_DISTMIN " - min distance threshold (cm)\n"
|
CMD_DISTMIN " - min distance threshold (cm)\n"
|
||||||
CMD_DISTMAX " - max distance threshold (cm)\n"
|
CMD_DISTMAX " - max distance threshold (cm)\n"
|
||||||
CMD_GPSSTR " - current GPS data string\n"
|
CMD_GPSSTR " - current GPS data string\n"
|
||||||
|
CMD_LEDS "S - turn leds on/off (1/0)\n"
|
||||||
|
CMD_GETMCUTEMP " - MCU temperature\n"
|
||||||
CMD_PULLUP "NS - triggers pullups state (N - trigger No, S - 0/1 for off/on)\n"
|
CMD_PULLUP "NS - triggers pullups state (N - trigger No, S - 0/1 for off/on)\n"
|
||||||
CMD_SHOWCONF " - show current configuration\n"
|
CMD_SHOWCONF " - show current configuration\n"
|
||||||
CMD_PRINTTIME " - print time\n"
|
CMD_PRINTTIME " - print time\n"
|
||||||
@ -99,6 +117,7 @@ int parse_USBCMD(char *cmd){
|
|||||||
CMD_TRIGLVL "NS - working trigger N level S\n"
|
CMD_TRIGLVL "NS - working trigger N level S\n"
|
||||||
CMD_TRGPAUSE "NP - pause (P, ms) after trigger N shots\n"
|
CMD_TRGPAUSE "NP - pause (P, ms) after trigger N shots\n"
|
||||||
CMD_TRGTIME "N - show last trigger N time\n"
|
CMD_TRGTIME "N - show last trigger N time\n"
|
||||||
|
CMD_GETVDD " - Vdd value\n"
|
||||||
);
|
);
|
||||||
}else if(CMP(cmd, CMD_PRINTTIME) == 0){
|
}else if(CMP(cmd, CMD_PRINTTIME) == 0){
|
||||||
USB_send(get_time(¤t_time, get_millis()));
|
USB_send(get_time(¤t_time, get_millis()));
|
||||||
@ -132,7 +151,6 @@ int parse_USBCMD(char *cmd){
|
|||||||
}
|
}
|
||||||
}else if(CMP(cmd, CMD_GPSSTR) == 0){ // show GPS status string
|
}else if(CMP(cmd, CMD_GPSSTR) == 0){ // show GPS status string
|
||||||
showGPSstr = 1;
|
showGPSstr = 1;
|
||||||
return 0;
|
|
||||||
}else if(CMP(cmd, CMD_PULLUP) == 0){
|
}else if(CMP(cmd, CMD_PULLUP) == 0){
|
||||||
DBG("Pullups");
|
DBG("Pullups");
|
||||||
cmd += sizeof(CMD_PULLUP) - 1;
|
cmd += sizeof(CMD_PULLUP) - 1;
|
||||||
@ -159,7 +177,6 @@ int parse_USBCMD(char *cmd){
|
|||||||
succeed = 1;
|
succeed = 1;
|
||||||
}else if(CMP(cmd, CMD_SHOWCONF) == 0){
|
}else if(CMP(cmd, CMD_SHOWCONF) == 0){
|
||||||
showuserconf();
|
showuserconf();
|
||||||
return 0;
|
|
||||||
}else if(CMP(cmd, CMD_TRGPAUSE) == 0){
|
}else if(CMP(cmd, CMD_TRGPAUSE) == 0){
|
||||||
DBG("Trigger pause");
|
DBG("Trigger pause");
|
||||||
cmd += sizeof(CMD_TRGPAUSE) - 1;
|
cmd += sizeof(CMD_TRGPAUSE) - 1;
|
||||||
@ -176,7 +193,59 @@ int parse_USBCMD(char *cmd){
|
|||||||
uint8_t Nt = *cmd++ - '0';
|
uint8_t Nt = *cmd++ - '0';
|
||||||
if(Nt > TRIGGERS_AMOUNT - 1) goto bad_number;
|
if(Nt > TRIGGERS_AMOUNT - 1) goto bad_number;
|
||||||
show_trigger_shot((uint8_t)1<<Nt);
|
show_trigger_shot((uint8_t)1<<Nt);
|
||||||
return 0;
|
}else if(CMP(cmd, CMD_GETVDD) == 0){
|
||||||
|
USB_send("VDD=");
|
||||||
|
uint32_t vdd = getVdd();
|
||||||
|
sendu(vdd/100);
|
||||||
|
vdd %= 100;
|
||||||
|
if(vdd < 10) USB_send(".0");
|
||||||
|
else USB_send(".");
|
||||||
|
sendu(vdd);
|
||||||
|
USB_send("\n");
|
||||||
|
}else if(CMP(cmd, CMD_GETMCUTEMP) == 0){
|
||||||
|
int32_t t = getMCUtemp();
|
||||||
|
USB_send("MCUTEMP=");
|
||||||
|
if(t < 0){
|
||||||
|
t = -t;
|
||||||
|
USB_send("-");
|
||||||
|
}
|
||||||
|
sendu(t/10);
|
||||||
|
USB_send(".");
|
||||||
|
sendu(t%10);
|
||||||
|
USB_send("\n");
|
||||||
|
}else if(CMP(cmd, CMD_GETADCVAL) == 0){
|
||||||
|
USB_send("ADCVAL=");
|
||||||
|
sendu(getADCval(0));
|
||||||
|
USB_send("\n");
|
||||||
|
}else if(CMP(cmd, CMD_LEDS) == 0){
|
||||||
|
uint8_t Nt = cmd[sizeof(CMD_LEDS) - 1] - '0';
|
||||||
|
if(Nt > 1) goto bad_number;
|
||||||
|
USB_send("LEDS=");
|
||||||
|
if(Nt){
|
||||||
|
LEDSon = 1;
|
||||||
|
USB_send("ON\n");
|
||||||
|
}else{
|
||||||
|
LED_off();
|
||||||
|
LED1_off();
|
||||||
|
LEDSon = 0;
|
||||||
|
USB_send("OFF\n");
|
||||||
|
}
|
||||||
|
}else if(CMP(cmd, CMD_ADCMAX) == 0){ // set low limit
|
||||||
|
GETNUM(CMD_ADCMAX);
|
||||||
|
if(N < -4096 || N > 4096) goto bad_number;
|
||||||
|
if(the_conf.ADC_max != (int16_t)N){
|
||||||
|
conf_modified = 1;
|
||||||
|
the_conf.ADC_max = (int16_t) N;
|
||||||
|
succeed = 1;
|
||||||
|
}
|
||||||
|
}else if(CMP(cmd, CMD_ADCMIN) == 0){ // set low limit
|
||||||
|
GETNUM(CMD_ADCMIN);
|
||||||
|
if(N < -4096 || N > 4096) goto bad_number;
|
||||||
|
if(the_conf.ADC_min != (int16_t)N){
|
||||||
|
conf_modified = 1;
|
||||||
|
the_conf.ADC_min = (int16_t) N;
|
||||||
|
succeed = 1;
|
||||||
|
}
|
||||||
}else return 1;
|
}else return 1;
|
||||||
IWDG->KR = IWDG_REFRESH;
|
IWDG->KR = IWDG_REFRESH;
|
||||||
if(succeed) USB_send("Success!\n");
|
if(succeed) USB_send("Success!\n");
|
||||||
@ -198,7 +267,7 @@ void show_trigger_shot(uint8_t tshot){
|
|||||||
else continue;
|
else continue;
|
||||||
if(trigger_shot & X) trigger_shot &= ~X;
|
if(trigger_shot & X) trigger_shot &= ~X;
|
||||||
USB_send("TRIG");
|
USB_send("TRIG");
|
||||||
USB_send(u2str(i));
|
sendu(i);
|
||||||
USB_send("=");
|
USB_send("=");
|
||||||
USB_send(get_time(&shottime[i].Time, shottime[i].millis));
|
USB_send(get_time(&shottime[i].Time, shottime[i].millis));
|
||||||
USB_send("\n");
|
USB_send("\n");
|
||||||
|
|||||||
@ -26,10 +26,8 @@
|
|||||||
// lower and upper limits to capture
|
// lower and upper limits to capture
|
||||||
#define CMD_DISTMIN "distmin"
|
#define CMD_DISTMIN "distmin"
|
||||||
#define CMD_DISTMAX "distmax"
|
#define CMD_DISTMAX "distmax"
|
||||||
#define CMD_ADC1MIN "adc1min"
|
#define CMD_ADCMIN "adcmin"
|
||||||
#define CMD_ADC2MIN "adc2min"
|
#define CMD_ADCMAX "adcmax"
|
||||||
#define CMD_ADC1MAX "adc1max"
|
|
||||||
#define CMD_ADC2MAX "adc2max"
|
|
||||||
#define CMD_PRINTTIME "time"
|
#define CMD_PRINTTIME "time"
|
||||||
#define CMD_STORECONF "store"
|
#define CMD_STORECONF "store"
|
||||||
#define CMD_GPSSTR "gpsstring"
|
#define CMD_GPSSTR "gpsstring"
|
||||||
@ -38,6 +36,10 @@
|
|||||||
#define CMD_TRIGLVL "triglevel"
|
#define CMD_TRIGLVL "triglevel"
|
||||||
#define CMD_TRGPAUSE "trigpause"
|
#define CMD_TRGPAUSE "trigpause"
|
||||||
#define CMD_TRGTIME "trigtime"
|
#define CMD_TRGTIME "trigtime"
|
||||||
|
#define CMD_GETVDD "vdd"
|
||||||
|
#define CMD_GETMCUTEMP "mcutemp"
|
||||||
|
#define CMD_GETADCVAL "adcval"
|
||||||
|
#define CMD_LEDS "leds"
|
||||||
|
|
||||||
extern uint8_t showGPSstr;
|
extern uint8_t showGPSstr;
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user