add enable/disable command

This commit is contained in:
2026-04-14 09:28:06 +03:00
parent 56701d6ef6
commit c93c2ac6ab
7 changed files with 41 additions and 3 deletions

View File

@@ -172,6 +172,7 @@ void canon_init(){
*/ */
void canon_proc(){ void canon_proc(){
static uint32_t Tconn = 0; static uint32_t Tconn = 0;
if(state == LENS_DISABLED) return;
if(state == LENS_DISCONNECTED){ if(state == LENS_DISCONNECTED){
if(!LENSCONNECTED()){ if(!LENSCONNECTED()){
Tconn = 0; Tconn = 0;
@@ -404,3 +405,25 @@ int canon_getinfo(){
uint16_t canon_getstate(){ uint16_t canon_getstate(){
return state | (inistate << 8); return state | (inistate << 8);
} }
void canon_disable(){
if(state == LENS_DISABLED) return;
state = LENS_DISABLED;
LENS_OFF();
ready = 0;
}
void canon_enable(){
if(state != LENS_DISABLED) return;
if(OVERCURRENT()){
state = LENS_OVERCURRENT;
return;
}
if(!LENSCONNECTED()){
state = LENS_DISCONNECTED;
return;
}
LENS_ON();
state = LENS_SLEEPING;
ready = 1;
}

View File

@@ -92,6 +92,7 @@ typedef enum{
LENS_INITIALIZED, // initializing process LENS_INITIALIZED, // initializing process
LENS_READY, // ready to operate LENS_READY, // ready to operate
LENS_ERR, // some error occured - reconnect after REINIT_PAUSE LENS_ERR, // some error occured - reconnect after REINIT_PAUSE
LENS_DISABLED, // powered off by command
LENS_S_AMOUNT LENS_S_AMOUNT
} lens_state; } lens_state;
@@ -109,6 +110,8 @@ typedef enum{
void canon_init(); void canon_init();
void canon_proc(); void canon_proc();
void canon_disable();
void canon_enable();
int canon_diaphragm(char command); int canon_diaphragm(char command);
int canon_focus(int16_t val); int canon_focus(int16_t val);
int canon_sendcmd(uint8_t cmd); int canon_sendcmd(uint8_t cmd);

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject> <!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 18.0.0, 2026-03-25T15:00:48. --> <!-- Written by QtCreator 18.0.0, 2026-04-14T09:27:26. -->
<qtcreator> <qtcreator>
<data> <data>
<variable>EnvironmentId</variable> <variable>EnvironmentId</variable>

View File

@@ -48,6 +48,7 @@ int main(void){
uint32_t SPIctr = Tms; uint32_t SPIctr = Tms;
while(1){ while(1){
// TODO: add CAN bus parsing
IWDG->KR = IWDG_REFRESH; IWDG->KR = IWDG_REFRESH;
if(Tms - SPIctr > CANONPROC_INTERVAL){ // not more than once per 10ms if(Tms - SPIctr > CANONPROC_INTERVAL){ // not more than once per 10ms
SPIctr = Tms; SPIctr = Tms;

View File

@@ -31,6 +31,8 @@ static const char *OK = "OK", *FAIL = "FAIL";
const char* helpmsg = const char* helpmsg =
"https://github.com/eddyem/stm32samples/tree/master/F1-nolib/Canon_managing_device build#" BUILD_NUMBER " @ " BUILD_DATE "\n" "https://github.com/eddyem/stm32samples/tree/master/F1-nolib/Canon_managing_device build#" BUILD_NUMBER " @ " BUILD_DATE "\n"
"# - turn off lens power\n"
"* - turn on lens power\n"
"0 - move to smallest foc value (e.g. 2.5m)\n" "0 - move to smallest foc value (e.g. 2.5m)\n"
"1 - move to largest foc value (e.g. infinity)\n" "1 - move to largest foc value (e.g. infinity)\n"
"a - move focus to given ABSOLUTE position or get current value (without number)\n" "a - move focus to given ABSOLUTE position or get current value (without number)\n"
@@ -105,6 +107,7 @@ const char *connmsgs[LENS_S_AMOUNT+1] = {
[LENS_INITIALIZED] = "initialized", [LENS_INITIALIZED] = "initialized",
[LENS_READY] = "ready", [LENS_READY] = "ready",
[LENS_ERR] = "error", [LENS_ERR] = "error",
[LENS_DISABLED] = "turned off",
[LENS_S_AMOUNT] = "wrong state" [LENS_S_AMOUNT] = "wrong state"
}; };
const char *inimsgs[INI_S_AMOUNT+1] = { const char *inimsgs[INI_S_AMOUNT+1] = {
@@ -128,6 +131,14 @@ void parse_cmd(const char *buf){
lastFloodTime= FALSE; lastFloodTime= FALSE;
if(buf[1] == '\n' || !buf[1]){ // one symbol commands if(buf[1] == '\n' || !buf[1]){ // one symbol commands
switch(*buf){ switch(*buf){
case '*':
canon_enable();
USB_sendstr(OK);
break;
case '#':
canon_disable();
USB_sendstr(OK);
break;
case 'a': case 'a':
case 'f': case 'f':
errw(canon_focus(-1)); errw(canon_focus(-1));

View File

@@ -1,2 +1,2 @@
#define BUILD_NUMBER "114" #define BUILD_NUMBER "133"
#define BUILD_DATE "2025-03-12" #define BUILD_DATE "2026-04-14"