Browse Source

更改了RGB灯光的控制方式,删除了一些不需要的代码

new_pcb
tianjialong 2 years ago
parent
commit
ab8b17b662
  1. 12
      MDK-ARM/LWIP.uvguix.29643
  2. 50
      MDK-ARM/LWIP.uvoptx
  3. 1088
      MDK-ARM/LWIP.uvprojx
  4. 111
      usersrc/encoder.c
  5. 13
      usersrc/encoder.h
  6. 14
      usersrc/usermain.c

12
MDK-ARM/LWIP.uvguix.29643
File diff suppressed because it is too large
View File

50
MDK-ARM/LWIP.uvoptx

@ -1,4 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<ProjectOpt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_optx.xsd"> <ProjectOpt xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="project_optx.xsd">
<SchemaVersion>1.0</SchemaVersion> <SchemaVersion>1.0</SchemaVersion>
@ -45,7 +45,7 @@
<PageWidth>79</PageWidth> <PageWidth>79</PageWidth>
<PageLength>66</PageLength> <PageLength>66</PageLength>
<TabStop>8</TabStop> <TabStop>8</TabStop>
<ListingPath />
<ListingPath></ListingPath>
</OPTLEX> </OPTLEX>
<ListingPage> <ListingPage>
<CreateCListing>1</CreateCListing> <CreateCListing>1</CreateCListing>
@ -104,16 +104,16 @@
<bSchkAxf>0</bSchkAxf> <bSchkAxf>0</bSchkAxf>
<bTchkAxf>0</bTchkAxf> <bTchkAxf>0</bTchkAxf>
<nTsel>3</nTsel> <nTsel>3</nTsel>
<sDll />
<sDllPa />
<sDlgDll />
<sDlgPa />
<sIfile />
<tDll />
<tDllPa />
<tDlgDll />
<tDlgPa />
<tIfile />
<sDll></sDll>
<sDllPa></sDllPa>
<sDlgDll></sDlgDll>
<sDlgPa></sDlgPa>
<sIfile></sIfile>
<tDll></tDll>
<tDllPa></tDllPa>
<tDlgDll></tDlgDll>
<tDlgPa></tDlgPa>
<tIfile></tIfile>
<pMon>BIN\CMSIS_AGDI.dll</pMon> <pMon>BIN\CMSIS_AGDI.dll</pMon>
</DebugOpt> </DebugOpt>
<TargetDriverDllRegistry> <TargetDriverDllRegistry>
@ -130,12 +130,12 @@
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>ARMDBGFLAGS</Key> <Key>ARMDBGFLAGS</Key>
<Name />
<Name></Name>
</SetRegEntry> </SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
<Key>DLGUARM</Key> <Key>DLGUARM</Key>
<Name />
<Name></Name>
</SetRegEntry> </SetRegEntry>
<SetRegEntry> <SetRegEntry>
<Number>0</Number> <Number>0</Number>
@ -153,7 +153,7 @@
<Name>-U-O142 -O2254 -S0 -C0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F4xx_512.FLM -FS08000000 -FL080000 -FP0($$Device:STM32F407ZETx$CMSIS\Flash\STM32F4xx_512.FLM)</Name> <Name>-U-O142 -O2254 -S0 -C0 -N00("ARM CoreSight SW-DP") -D00(2BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC800 -FN1 -FF0STM32F4xx_512.FLM -FS08000000 -FL080000 -FP0($$Device:STM32F407ZETx$CMSIS\Flash\STM32F4xx_512.FLM)</Name>
</SetRegEntry> </SetRegEntry>
</TargetDriverDllRegistry> </TargetDriverDllRegistry>
<Breakpoint />
<Breakpoint/>
<WatchWindow1> <WatchWindow1>
<Ww> <Ww>
<count>0</count> <count>0</count>
@ -195,19 +195,19 @@
<newCpu>0</newCpu> <newCpu>0</newCpu>
<uProt>0</uProt> <uProt>0</uProt>
</DebugFlag> </DebugFlag>
<LintExecutable />
<LintConfigFile />
<LintExecutable></LintExecutable>
<LintConfigFile></LintConfigFile>
<bLintAuto>0</bLintAuto> <bLintAuto>0</bLintAuto>
<bAutoGenD>0</bAutoGenD> <bAutoGenD>0</bAutoGenD>
<LntExFlags>0</LntExFlags> <LntExFlags>0</LntExFlags>
<pMisraName />
<pszMrule />
<pSingCmds />
<pMultCmds />
<pMisraNamep />
<pszMrulep />
<pSingCmdsp />
<pMultCmdsp />
<pMisraName></pMisraName>
<pszMrule></pszMrule>
<pSingCmds></pSingCmds>
<pMultCmds></pMultCmds>
<pMisraNamep></pMisraNamep>
<pszMrulep></pszMrulep>
<pSingCmdsp></pSingCmdsp>
<pMultCmdsp></pMultCmdsp>
<DebugDescription> <DebugDescription>
<Enable>1</Enable> <Enable>1</Enable>
<EnableFlashSeq>0</EnableFlashSeq> <EnableFlashSeq>0</EnableFlashSeq>

1088
MDK-ARM/LWIP.uvprojx
File diff suppressed because it is too large
View File

111
usersrc/encoder.c

@ -4,12 +4,8 @@
#include "zport.h" #include "zport.h"
#include "udpclient.h" #include "udpclient.h"
static encoder_light_state_t camera_encoder_state = STANDBY;
static encoder_light_state_t driven_encoder_gear_state = STANDBY;
static uint32_t camera_encoder_lastprocess = 0; static uint32_t camera_encoder_lastprocess = 0;
static uint32_t driven_encoder_gear_lastprocess = 0; static uint32_t driven_encoder_gear_lastprocess = 0;
static bool camera_encoder_light_state;
static bool driven_encoder_light_state;
static encoder_t m_encoders[] = { static encoder_t m_encoders[] = {
{&camera_encoder, TIM_CHANNEL_1 | TIM_CHANNEL_2, 0, 0}, // {&camera_encoder, TIM_CHANNEL_1 | TIM_CHANNEL_2, 0, 0}, //
@ -40,9 +36,13 @@ void encoder_all_clear_counter(void)
} }
} }
void encoder_switch_clear_counter(encoder_usage_t encoder)
{
m_encoders[encoder].count = 0;
}
void encoder_read_with_encoder(encoder_usage_t encoder, uint32_t *encoder_value) void encoder_read_with_encoder(encoder_usage_t encoder, uint32_t *encoder_value)
{ {
bool get_encoder_value_flag = false;
switch (encoder) switch (encoder)
{ {
case CAMERA_ENCODER: case CAMERA_ENCODER:
@ -70,33 +70,29 @@ void encoder_light_schedule(void)
G2:tim4-->TIM_CHANNEL_3 G2:tim4-->TIM_CHANNEL_3
B2:tim4-->TIM_CHANNEL_4 B2:tim4-->TIM_CHANNEL_4
*/ */
void encoder_light_switch_set_color_and_brightness(encoder_usage_t encoder, encoder_light_color_table_t color, uint16_t brightness)
void encoder_light_switch_set_color(encoder_usage_t encoder, encoder_light_color_table_t color)
{ {
uint16_t count;
if (encoder == CAMERA_ENCODER) if (encoder == CAMERA_ENCODER)
{ {
switch (color) switch (color)
{ {
case ENCODER_LIGHT_COLOR_RED: case ENCODER_LIGHT_COLOR_RED:
count = (1 - brightness / 65535.0) * __HAL_TIM_GET_AUTORELOAD(&htim2);
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_4, count);
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_4);
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_1);
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
/* 红色 */
HAL_GPIO_WritePin(DIS_R1_GPIO_Port, DIS_R1_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(DIS_G1_GPIO_Port, DIS_G1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(DIS_B1_GPIO_Port, DIS_B1_Pin, GPIO_PIN_SET);
break; break;
case ENCODER_LIGHT_COLOR_GREEN: case ENCODER_LIGHT_COLOR_GREEN:
count = (1 - brightness / 65535.0) * __HAL_TIM_GET_AUTORELOAD(&htim2);
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_1, count);
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_4);
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_1);
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
/* 绿色 */
HAL_GPIO_WritePin(DIS_R1_GPIO_Port, DIS_R1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(DIS_G1_GPIO_Port, DIS_G1_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(DIS_B1_GPIO_Port, DIS_B1_Pin, GPIO_PIN_SET);
break; break;
case ENCODER_LIGHT_COLOR_BLUE: case ENCODER_LIGHT_COLOR_BLUE:
count = (1 - brightness / 65535.0) * __HAL_TIM_GET_AUTORELOAD(&htim3);
__HAL_TIM_SET_COMPARE(&htim3, TIM_CHANNEL_1, count);
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_4);
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_1);
HAL_TIM_PWM_Start(&htim3, TIM_CHANNEL_1);
/* 蓝色 */
HAL_GPIO_WritePin(DIS_R1_GPIO_Port, DIS_R1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(DIS_G1_GPIO_Port, DIS_G1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(DIS_B1_GPIO_Port, DIS_B1_Pin, GPIO_PIN_RESET);
break; break;
default: default:
@ -109,25 +105,22 @@ void encoder_light_switch_set_color_and_brightness(encoder_usage_t encoder, enco
switch (color) switch (color)
{ {
case ENCODER_LIGHT_COLOR_RED: case ENCODER_LIGHT_COLOR_RED:
count = (1 - brightness / 65535.0) * __HAL_TIM_GET_AUTORELOAD(&htim2);
__HAL_TIM_SET_COMPARE(&htim2, TIM_CHANNEL_3, count);
HAL_TIM_PWM_Start(&htim2, TIM_CHANNEL_3);
HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_3);
HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_4);
/* 红色 */
HAL_GPIO_WritePin(DIS_R2_GPIO_Port, DIS_R2_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(DIS_G2_GPIO_Port, DIS_G2_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(DIS_B2_GPIO_Port, DIS_B2_Pin, GPIO_PIN_SET);
break; break;
case ENCODER_LIGHT_COLOR_GREEN: case ENCODER_LIGHT_COLOR_GREEN:
count = (1 - brightness / 65535.0) * __HAL_TIM_GET_AUTORELOAD(&htim4);
__HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_3, count);
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3);
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3);
HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_4);
/* 绿色 */
HAL_GPIO_WritePin(DIS_R2_GPIO_Port, DIS_R2_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(DIS_G2_GPIO_Port, DIS_G2_Pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(DIS_B2_GPIO_Port, DIS_B2_Pin, GPIO_PIN_SET);
break; break;
case ENCODER_LIGHT_COLOR_BLUE: case ENCODER_LIGHT_COLOR_BLUE:
count = (1 - brightness / 65535.0) * __HAL_TIM_GET_AUTORELOAD(&htim4);
__HAL_TIM_SET_COMPARE(&htim4, TIM_CHANNEL_4, count);
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3);
HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_3);
HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_4);
/* 蓝色 */
HAL_GPIO_WritePin(DIS_R2_GPIO_Port, DIS_R2_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(DIS_G2_GPIO_Port, DIS_G2_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(DIS_B2_GPIO_Port, DIS_B2_Pin, GPIO_PIN_RESET);
break; break;
default: default:
@ -145,47 +138,15 @@ void encoder_switch_close_light(encoder_usage_t encoder)
{ {
if (encoder == CAMERA_ENCODER) if (encoder == CAMERA_ENCODER)
{ {
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_4);
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_1);
HAL_TIM_PWM_Stop(&htim3, TIM_CHANNEL_1);
}
else if (encoder == DRIVEN_ENCODER_GEAR)
{
HAL_TIM_PWM_Stop(&htim2, TIM_CHANNEL_3);
HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_3);
HAL_TIM_PWM_Stop(&htim4, TIM_CHANNEL_4);
}
else
{
// error
}
}
void encoder_switch_toggle_on_off_state(encoder_usage_t encoder)
{
if (encoder == CAMERA_ENCODER)
{
if (camera_encoder_light_state)
{
encoder_switch_close_light(CAMERA_ENCODER);
}
else
{
encoder_light_switch_set_color_and_brightness(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_BLUE, encoder_light_max_brightness);
}
camera_encoder_light_state = !camera_encoder_light_state;
HAL_GPIO_WritePin(DIS_R1_GPIO_Port, DIS_R1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(DIS_G1_GPIO_Port, DIS_G1_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(DIS_B1_GPIO_Port, DIS_B1_Pin, GPIO_PIN_SET);
} }
else if (encoder == DRIVEN_ENCODER_GEAR) else if (encoder == DRIVEN_ENCODER_GEAR)
{ {
if (driven_encoder_light_state)
{
encoder_switch_close_light(DRIVEN_ENCODER_GEAR);
}
else
{
encoder_light_switch_set_color_and_brightness(DRIVEN_ENCODER_GEAR, ENCODER_LIGHT_COLOR_BLUE, encoder_light_max_brightness);
}
driven_encoder_light_state = !driven_encoder_light_state;
HAL_GPIO_WritePin(DIS_R2_GPIO_Port, DIS_R2_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(DIS_G2_GPIO_Port, DIS_G2_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(DIS_B2_GPIO_Port, DIS_B2_Pin, GPIO_PIN_SET);
} }
else else
{ {

13
usersrc/encoder.h

@ -11,13 +11,6 @@ typedef enum
typedef enum typedef enum
{ {
STANDBY = 0X00,
WORKING = 0X01,
ENCODER_STATE_NUMBER_AND_ERR_STATE,
} encoder_light_state_t;
typedef enum
{
ENCODER_LIGHT_COLOR_RED = 0X00, ENCODER_LIGHT_COLOR_RED = 0X00,
ENCODER_LIGHT_COLOR_GREEN = 0X01, ENCODER_LIGHT_COLOR_GREEN = 0X01,
ENCODER_LIGHT_COLOR_BLUE = 0X02, ENCODER_LIGHT_COLOR_BLUE = 0X02,
@ -31,15 +24,13 @@ typedef struct
uint16_t last_count; uint16_t last_count;
} encoder_t; } encoder_t;
#define encoder_light_max_brightness 1000
void encoder_all_start(void); void encoder_all_start(void);
void encoder_all_stop(void); void encoder_all_stop(void);
void encoder_all_clear_counter(void); void encoder_all_clear_counter(void);
void encoder_switch_clear_counter(encoder_usage_t encoder);
void encoder_read_with_encoder(encoder_usage_t encoder, uint32_t *encoder_value); void encoder_read_with_encoder(encoder_usage_t encoder, uint32_t *encoder_value);
void encoder_light_schedule(void); void encoder_light_schedule(void);
void encoder_light_switch_set_color_and_brightness(encoder_usage_t encoder, encoder_light_color_table_t color, uint16_t brightness);
void encoder_light_switch_set_color(encoder_usage_t encoder, encoder_light_color_table_t color);
void encoder_switch_close_light(encoder_usage_t encoder); void encoder_switch_close_light(encoder_usage_t encoder);
void encoder_switch_toggle_on_off_state(encoder_usage_t encoder);
encoder_t *encoder_get_camera_encoder_structer(void); encoder_t *encoder_get_camera_encoder_structer(void);
encoder_t *encoder_get_driven_encoder_gear_structer(void); encoder_t *encoder_get_driven_encoder_gear_structer(void);

14
usersrc/usermain.c

@ -51,13 +51,11 @@ static void onkey(zkey_t *key, zkey_state_t key_state)
{ {
if (strcmp(key->name, CHEAR_ENCODER_1_KEY_NAME) == 0) if (strcmp(key->name, CHEAR_ENCODER_1_KEY_NAME) == 0)
{ {
encoder_switch_encoder_clear_count_and_structer_count(CAMERA_ENCODER);
printf("clear encoder 1 count\r\n");
encoder_switch_clear_counter(CAMERA_ENCODER);
} }
else if (strcmp(key->name, CHEAR_ENCODER_2_KEY_NAME) == 0) else if (strcmp(key->name, CHEAR_ENCODER_2_KEY_NAME) == 0)
{ {
encoder_switch_encoder_clear_count_and_structer_count(DRIVEN_ENCODER_GEAR);
printf("clear encoder 2 count\r\n");
encoder_switch_clear_counter(DRIVEN_ENCODER_GEAR);
} }
} }
@ -118,14 +116,14 @@ int32_t compute_uint16_t_minus_the_numbers(uint16_t now, uint16_t last)
void netif_link_up_user_func(void) void netif_link_up_user_func(void)
{ {
encoder_light_switch_set_color_and_brightness(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_GREEN, encoder_light_max_brightness);
encoder_light_switch_set_color_and_brightness(DRIVEN_ENCODER_GEAR, ENCODER_LIGHT_COLOR_GREEN, encoder_light_max_brightness);
encoder_light_switch_set_color(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_GREEN);
encoder_light_switch_set_color(DRIVEN_ENCODER_GEAR, ENCODER_LIGHT_COLOR_GREEN);
} }
void netif_link_down_user_func(void) void netif_link_down_user_func(void)
{ {
encoder_light_switch_set_color_and_brightness(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_RED, encoder_light_max_brightness);
encoder_light_switch_set_color_and_brightness(DRIVEN_ENCODER_GEAR, ENCODER_LIGHT_COLOR_RED, encoder_light_max_brightness);
encoder_light_switch_set_color(CAMERA_ENCODER, ENCODER_LIGHT_COLOR_RED);
encoder_light_switch_set_color(DRIVEN_ENCODER_GEAR, ENCODER_LIGHT_COLOR_RED);
} }
static void encoder_get_and_calculation(void) static void encoder_get_and_calculation(void)

Loading…
Cancel
Save