34 changed files with 761 additions and 1026 deletions
-
3.vscode/settings.json
-
17auto.py
-
2stm32basic
-
2stm32components
-
5uappbase/base.hpp
-
106ucomponents/preportional_valve/preportional_valve_ctrl.cpp
-
50ucomponents/preportional_valve/preportional_valve_ctrl.hpp
-
3ucomponents/ucomponents.hpp
-
0ui/README.md
-
0ui/hand_acid_mainboard_ui.HMI
-
0ui/ui.h
-
19usrc/app/apublicboard/public_board_initer.hpp
-
3usrc/app/main_controler/abasicboard/basicboard.cpp
-
19usrc/app/main_controler/abasicboard/basicboard.hpp
-
3usrc/app/main_controler/main_controler.cpp
-
14usrc/app/main_controler/main_controler.hpp
-
5usrc/app/valvecontroler/valvecontroler.cpp
-
13usrc/app/valvecontroler/valvecontroler.hpp
-
82usrc/app_main.cpp
-
2usrc/appcfg/appcfg.hpp
-
4usrc/appcfg/publicboard.hpp
-
46usrc/apphal/apphal.cpp
-
15usrc/apphal/apphal.hpp
-
14usrc/apppublic/boardid.cpp
-
14usrc/apppublic/boardid.hpp
-
3usrc/main.c
-
21usrc/project_configs.h
-
23usrc/service/app_core.cpp
-
21usrc/service/app_core.hpp
@ -0,0 +1,17 @@ |
|||
import time |
|||
import ctypes |
|||
from pynput.keyboard import Key |
|||
from pynput.keyboard import Controller |
|||
a=0 |
|||
while True: |
|||
if ctypes.windll.user32.GetForegroundWindow() == 0: |
|||
print('0') |
|||
time.sleep(2) |
|||
else: |
|||
a = a+1 |
|||
b = Controller() |
|||
b.press(Key.f20) |
|||
b.release(Key.f20) |
|||
time.sleep(30) |
|||
print('1') |
|||
print(a) |
@ -1 +1 @@ |
|||
Subproject commit 7628a01fff313fd263d7de7e93d7d652b4325e59 |
|||
Subproject commit 219877a3ae5cfabe04211a9121eac9519b6081cc |
@ -1 +1 @@ |
|||
Subproject commit 03d9638ccbc69971524957a68e51842da0960940 |
|||
Subproject commit a3069a8005dcb8277f95d0341551c145fac2a046 |
@ -1,4 +1,5 @@ |
|||
#pragma once
|
|||
#include "ucomponents/ucomponents.hpp"
|
|||
#include "stm32basic/stm32basic.hpp"
|
|||
#include "stm32halport/stm32halport.hpp"
|
|||
#include "stm32basic/stm32basic.hpp"
|
|||
#include "ucomponents/ucomponents.hpp"
|
|||
#include "main.h"
|
@ -1,106 +0,0 @@ |
|||
#include "preportional_valve_ctrl.hpp"
|
|||
|
|||
using namespace iflytop; |
|||
using namespace zscanprotocol; |
|||
|
|||
#define WORK_STATE_REG 0x0000
|
|||
#define CTRL_STATE_REG 0x0001
|
|||
#define POS_STATE_REG 0x0013
|
|||
#define OVERTIME 30
|
|||
#define TAG "PreportionalValveCtrl"
|
|||
|
|||
void PreportionalValveCtrl::initialize(UART_HandleTypeDef* huart) { m_modbusBlockHost.initialize(huart); } |
|||
|
|||
int32_t PreportionalValveCtrl::writeReg06(uint8_t slaveAddr, uint16_t regAddr, uint16_t regVal) { |
|||
// 重发三次
|
|||
for (size_t i = 0; i < 3; i++) { |
|||
int32_t err = m_modbusBlockHost.writeReg06(slaveAddr, regAddr, regVal, OVERTIME); |
|||
if (err == 0) return 0; |
|||
} |
|||
return err::kerr_subdevice_offline; |
|||
} |
|||
int32_t PreportionalValveCtrl::readReg03(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal) { |
|||
// 重发三次
|
|||
for (size_t i = 0; i < 3; i++) { |
|||
int32_t err = m_modbusBlockHost.readReg03(slaveAddr, regAddr, regVal, OVERTIME); |
|||
if (err == 0) return 0; |
|||
} |
|||
return err::kerr_subdevice_offline; |
|||
} |
|||
|
|||
int32_t PreportionalValveCtrl::setValvePos(int32_t valueid, int32_t pos) { //
|
|||
int32_t ret = 0; |
|||
if (valueid > 255 || valueid < 1) { |
|||
return err::kerr_invalid_param; |
|||
} |
|||
ret = writeReg06(valueid, CTRL_STATE_REG, pos); |
|||
if (!ret) return err::kerr_subdevice_offline; |
|||
|
|||
m_last_set_valve_ticket = HAL_GetTick(); |
|||
m_targetpos[valueid] = pos; |
|||
return 0; |
|||
} |
|||
|
|||
int32_t PreportionalValveCtrl::getValvePos(int32_t valueid, int32_t* pos) { |
|||
int32_t ret = 0; |
|||
if (valueid > 255 || valueid < 1) { |
|||
return err::kerr_invalid_param; |
|||
} |
|||
|
|||
uint16_t pos16 = 0; |
|||
ret = readReg03(valueid, POS_STATE_REG, &pos16); |
|||
if (!ret) return err::kerr_subdevice_offline; |
|||
|
|||
*pos = pos16; |
|||
return 0; |
|||
} |
|||
int32_t PreportionalValveCtrl::getValveOrderPos(int32_t valueid, int32_t* pos) { |
|||
int32_t ret = 0; |
|||
if (valueid > 255 || valueid < 1) { |
|||
return err::kerr_invalid_param; |
|||
} |
|||
|
|||
uint16_t pos16 = 0; |
|||
ret = readReg03(valueid, CTRL_STATE_REG, &pos16); |
|||
if (!ret) return err::kerr_subdevice_offline; |
|||
|
|||
*pos = pos16; |
|||
return 0; |
|||
} |
|||
|
|||
int32_t PreportionalValveCtrl::isBusy(int32_t valueid, int32_t* busy) { |
|||
#if 1
|
|||
int32_t orderpos = 0; |
|||
int32_t pos = 0; |
|||
int32_t err = 0; |
|||
|
|||
#if 0
|
|||
err = getValveOrderPos(valueid, &orderpos); |
|||
if (err != 0) return err; |
|||
#endif
|
|||
orderpos = m_targetpos[valueid]; |
|||
|
|||
err = getValvePos(valueid, &pos); |
|||
if (err != 0) return err; |
|||
|
|||
if (abs(m_targetpos[valueid] - pos) <= 11) { |
|||
*busy = 0; |
|||
} else { |
|||
*busy = 1; |
|||
} |
|||
return 0; |
|||
#endif
|
|||
} |
|||
|
|||
int32_t PreportionalValveCtrl::getValveWorkState(int32_t valueid, int32_t* state) { |
|||
int32_t ret = 0; |
|||
if (valueid > 255 || valueid < 1) { |
|||
return err::kerr_invalid_param; |
|||
} |
|||
|
|||
uint16_t state16 = 0; |
|||
ret = readReg03(valueid, WORK_STATE_REG, &state16); |
|||
if (!ret) return err::kerr_subdevice_offline; |
|||
*state = state16; |
|||
return 0; |
|||
} |
@ -1,50 +0,0 @@ |
|||
#pragma once
|
|||
#include <stddef.h>
|
|||
#include <stdio.h>
|
|||
|
|||
#include "stm32components/modbus/modbus_block_host.hpp"
|
|||
#include "stm32basic/stm32basic.hpp"
|
|||
#include "stm32components/stm32components.hpp"
|
|||
|
|||
/**
|
|||
* @brief |
|||
* |
|||
* https://iflytop1.feishu.cn/wiki/GQwCwHMqFiaJRwks80ncwaYKnSe
|
|||
*/ |
|||
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
class PreportionalValveCtrl { |
|||
public: |
|||
typedef enum { |
|||
kstate_stop = 0x0, |
|||
kstate_running_forward = 0xaa, |
|||
kstate_running_backward = 0xbb, |
|||
kstate_err_state = 0xea, |
|||
} work_state_t; |
|||
|
|||
private: |
|||
/* data */ |
|||
ModbusBlockHost m_modbusBlockHost; |
|||
int32_t val = 0; |
|||
uint32_t m_last_set_valve_ticket = 0; |
|||
uint16_t m_targetpos[255]; |
|||
|
|||
public: |
|||
PreportionalValveCtrl() {}; |
|||
~PreportionalValveCtrl() {}; |
|||
|
|||
void initialize(UART_HandleTypeDef* huart); |
|||
int32_t setValvePos(int32_t valueid, int32_t pos); |
|||
int32_t getValvePos(int32_t valueid, int32_t* pos); |
|||
int32_t getValveOrderPos(int32_t valueid, int32_t* pos); |
|||
int32_t isBusy(int32_t valueid, int32_t* busy); |
|||
int32_t getValveWorkState(int32_t valueid, int32_t* state); |
|||
|
|||
private: |
|||
|
|||
int32_t writeReg06(uint8_t slaveAddr, uint16_t regAddr, uint16_t regVal); |
|||
int32_t readReg03(uint8_t slaveAddr, uint16_t regAddr, uint16_t* regVal); |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -1,2 +1 @@ |
|||
#pragma once
|
|||
#include "preportional_valve/preportional_valve_ctrl.hpp"
|
|||
#pragma once
|
@ -1,19 +0,0 @@ |
|||
#pragma once
|
|||
#include "appdep.hpp"
|
|||
#include "project_configs.h"
|
|||
namespace iflytop { |
|||
#define PB PublicBoardIniter::ins()
|
|||
class PublicBoardIniter { |
|||
private: |
|||
/* data */ |
|||
public: |
|||
static PublicBoardIniter* ins() { |
|||
static PublicBoardIniter instance; |
|||
return &instance; |
|||
} |
|||
|
|||
void MX_TIM6_Init(); |
|||
void MX_TIM7_Init(); |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -1,3 +0,0 @@ |
|||
#include "basicboard.hpp"
|
|||
using namespace iflytop; |
|||
|
@ -1,19 +0,0 @@ |
|||
#pragma once
|
|||
#include "appdep.hpp"
|
|||
namespace iflytop { |
|||
using namespace std; |
|||
class BasicBoard { |
|||
private: |
|||
/* data */ |
|||
BasicBoard() {} |
|||
|
|||
public: |
|||
static BasicBoard* ins() { |
|||
static BasicBoard instance; |
|||
return &instance; |
|||
} |
|||
|
|||
|
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -1,3 +0,0 @@ |
|||
#include "main_controler.hpp"
|
|||
|
|||
using namespace iflytop; |
@ -1,14 +0,0 @@ |
|||
#pragma once
|
|||
#include "appdep.hpp"
|
|||
|
|||
namespace iflytop { |
|||
class MainControler { |
|||
|
|||
public: |
|||
static MainControler* ins() { |
|||
static MainControler instance; |
|||
return &instance; |
|||
} |
|||
void init(){} |
|||
}; |
|||
} // namespace iflytop
|
@ -1,5 +0,0 @@ |
|||
#include "valvecontroler.hpp"
|
|||
|
|||
using namespace iflytop; |
|||
|
|||
void ValvaControler::init() {} |
@ -1,13 +0,0 @@ |
|||
#pragma once
|
|||
#include "appdep.hpp"
|
|||
|
|||
namespace iflytop { |
|||
class ValvaControler { |
|||
public: |
|||
static ValvaControler* ins() { |
|||
static ValvaControler instance; |
|||
return &instance; |
|||
} |
|||
void init(); |
|||
}; |
|||
} // namespace iflytop
|
@ -1,82 +0,0 @@ |
|||
#include <stddef.h>
|
|||
#include <stdio.h>
|
|||
//
|
|||
#include "appdep.hpp"
|
|||
#include "apppublic/boardid.hpp"
|
|||
//
|
|||
#include "app/main_controler/main_controler.hpp"
|
|||
#include "app/valvecontroler/valvecontroler.hpp"
|
|||
|
|||
#define TAG "main"
|
|||
extern void umain(); |
|||
extern "C" { |
|||
void StartDefaultTask(void const *argument) { umain(); } |
|||
} |
|||
/*******************************************************************************
|
|||
* MAIN * |
|||
*******************************************************************************/ |
|||
|
|||
using namespace iflytop; |
|||
|
|||
/* IWDG init function */ |
|||
void MX_IWDG_Init(void) { |
|||
hiwdg.Instance = IWDG; |
|||
hiwdg.Init.Prescaler = IWDG_PRESCALER_256; |
|||
hiwdg.Init.Reload = 501; |
|||
if (HAL_IWDG_Init(&hiwdg) != HAL_OK) { |
|||
Error_Handler(); |
|||
} |
|||
} |
|||
|
|||
static ZGPIO debuglight0; |
|||
static ZGPIO debuglight1; |
|||
static bool errorFlag; |
|||
static inline void debugLightLoop() { |
|||
static bool light = false; |
|||
static uint32_t lastcall = 0; |
|||
|
|||
if (errorFlag) { |
|||
if (zos_haspassedms(lastcall) > 30) { |
|||
light = !light; |
|||
debuglight0.write(light); |
|||
debuglight1.write(light); |
|||
lastcall = zos_get_tick(); |
|||
} |
|||
} else { |
|||
if (zos_haspassedms(lastcall) > 300) { |
|||
light = !light; |
|||
debuglight0.write(light); |
|||
debuglight1.write(light); |
|||
lastcall = zos_get_tick(); |
|||
} |
|||
} |
|||
} |
|||
|
|||
int32_t getDeviceIdFromFlash() { |
|||
int32_t *deviceId = (int32_t *)BOARD_TYPE_ID_FLASH_ADD; |
|||
if (*deviceId <= 0) { |
|||
return 0; |
|||
} |
|||
return *deviceId; |
|||
} |
|||
|
|||
void umain() { |
|||
MX_IWDG_Init(); |
|||
|
|||
debuglight0.initAsOutput(DEBUG_LIGHT_IO0, kxs_gpio_nopull, false, false); |
|||
debuglight1.initAsOutput(DEBUG_LIGHT_IO1, kxs_gpio_nopull, false, false); |
|||
int32_t id = getDeviceIdFromFlash(); |
|||
if (id == boardid::kbmainboard) { |
|||
MainControler::ins()->init(); |
|||
} else if (id == boardid::kvalveboard) { |
|||
ValvaControler::ins()->init(); |
|||
} else { |
|||
errorFlag = true; |
|||
} |
|||
|
|||
while (true) { |
|||
osDelay(30); |
|||
debugLightLoop(); |
|||
HAL_IWDG_Refresh(&hiwdg); |
|||
} |
|||
} |
@ -0,0 +1,2 @@ |
|||
#pragma once
|
|||
#include "project_configs.h"
|
@ -1,4 +0,0 @@ |
|||
#pragma once
|
|||
|
|||
#define DEBUG_UART_TX PA9
|
|||
#define DEBUG_UART_RX PA10
|
@ -0,0 +1,15 @@ |
|||
#pragma once
|
|||
#include "appcfg/appcfg.hpp"
|
|||
#include "uappbase/base.hpp"
|
|||
namespace iflytop { |
|||
class AppHal { |
|||
private: |
|||
/* data */ |
|||
public: |
|||
static void MX_TIM6_Init(void); |
|||
static void MX_TIM7_Init(void); |
|||
static void DEBUG_UART_INIT(Pin_t tx, Pin_t rx, int32_t baudrate); |
|||
static void MX_IWDG_Init(void); |
|||
}; |
|||
|
|||
} // namespace iflytop
|
@ -1,14 +0,0 @@ |
|||
#pragma once
|
|||
#include "boardid.hpp"
|
|||
|
|||
#include "appdep.hpp"
|
|||
#include "project_configs.h"
|
|||
using namespace iflytop; |
|||
|
|||
boardid::id_t BoardId_get() { |
|||
int32_t *deviceId = (int32_t *)BOARD_TYPE_ID_FLASH_ADD; |
|||
if (*deviceId <= 0) { |
|||
return boardid::kunsupport; |
|||
} |
|||
return (boardid::id_t)*deviceId; |
|||
} |
@ -1,14 +0,0 @@ |
|||
#pragma once
|
|||
#include "appdep.hpp"
|
|||
namespace iflytop { |
|||
namespace boardid { |
|||
typedef enum { |
|||
kunsupport = 0, |
|||
kbmainboard = 1, |
|||
kvalveboard = 2, |
|||
} id_t; |
|||
} |
|||
|
|||
boardid::id_t BoardId_get(); |
|||
|
|||
} // namespace iflytop
|
@ -0,0 +1,23 @@ |
|||
#include "app_core.hpp"
|
|||
|
|||
#include <stddef.h>
|
|||
#include <stdio.h>
|
|||
|
|||
#define TAG "main"
|
|||
|
|||
extern "C" { |
|||
void umain() { AppCore::ins()->initialize(); } |
|||
} |
|||
using namespace iflytop; |
|||
void AppCore::initialize() { |
|||
AppHal::MX_TIM6_Init(); |
|||
AppHal::MX_TIM7_Init(); |
|||
AppHal::DEBUG_UART_INIT(PA9, PA10, 460800); |
|||
AppHal::MX_IWDG_Init(); |
|||
|
|||
ZLOGI(TAG, "======================= boardinfo ==================== "); |
|||
ZLOGI(TAG, "project : %s ", PROJECT); |
|||
ZLOGI(TAG, "version : %d ", SOFTWARE_VERSION); |
|||
ZLOGI(TAG, "sn : %s", sn_get_str()); |
|||
ZLOGI(TAG, "="); |
|||
} |
@ -0,0 +1,21 @@ |
|||
#pragma once
|
|||
|
|||
#include "appcfg/appcfg.hpp"
|
|||
#include "apphal/apphal.hpp"
|
|||
#include "uappbase/base.hpp"
|
|||
|
|||
namespace iflytop { |
|||
class AppCore { |
|||
private: |
|||
/* data */ |
|||
AppCore(/* args */) {} |
|||
|
|||
public: |
|||
static AppCore* ins() { |
|||
static AppCore ins; |
|||
return &ins; |
|||
} |
|||
void initialize(); |
|||
}; |
|||
|
|||
} // namespace iflytop
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue