|
@@ -24,9 +24,11 @@
|
|
|
/* Private define ------------------------------------------------------------*/
|
|
|
#define PHOTO_LEVEL_ON (100)
|
|
|
#define PHOTO_LEVEL_OFF (1000)
|
|
|
+#define TIME_WAIT 1000
|
|
|
|
|
|
/* Private macro -------------------------------------------------------------*/
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
|
+volatile uint32_t timeOut;
|
|
|
static const char msg1[] = {"russian warship go fuck yourself!\nfeel free to contact shilvn@gmail.com"};
|
|
|
volatile flag_t Flag = {0};
|
|
|
volatile uint32_t photo_Value;
|
|
@@ -48,23 +50,17 @@ int main(void)
|
|
|
Board_Init();
|
|
|
|
|
|
#ifdef USE_SERVO_1
|
|
|
- Servo_1_ON;
|
|
|
+ Servo_1_CHNL = SERVO_CLOSE_VAL;
|
|
|
+ delay_ms(100);
|
|
|
Servo_1_CHNL = SERVO_INIT_VAL;
|
|
|
- Servo_1_OFF;
|
|
|
#endif
|
|
|
|
|
|
#ifdef USE_SERVO_2
|
|
|
- Servo_2_ON;
|
|
|
+ Servo_2_CHNL = SERVO_CLOSE_VAL;
|
|
|
+ delay_ms(100);
|
|
|
Servo_2_CHNL = SERVO_INIT_VAL;
|
|
|
- Servo_2_OFF;
|
|
|
#endif
|
|
|
-/*
|
|
|
- if ((Select_Port->IDR & Select_Pin) == 0) {
|
|
|
- Flag.ONE_CHANNEL = 1;
|
|
|
- } else {
|
|
|
- Flag.ONE_CHANNEL = 0;
|
|
|
- }
|
|
|
-*/
|
|
|
+
|
|
|
/* if light is on, wait for off */
|
|
|
while (photo_Value <= PHOTO_LEVEL_OFF) {
|
|
|
//IWDG->KR = 0xAAAA;
|
|
@@ -81,19 +77,20 @@ int main(void)
|
|
|
__WFI();
|
|
|
}
|
|
|
/* open servo 1 */
|
|
|
- Servo_1_ON;
|
|
|
Servo_1_CHNL = SERVO_OPEN_VAL;
|
|
|
- Servo_1_OFF;
|
|
|
|
|
|
/* wait for light off */
|
|
|
+ timeOut = TIME_WAIT;
|
|
|
while (photo_Value <= PHOTO_LEVEL_OFF) {
|
|
|
- //IWDG->KR = 0xAAAA;
|
|
|
+ if (timeOut == 0) {
|
|
|
+ Servo_1_CHNL = SERVO_INIT_VAL;
|
|
|
+ }
|
|
|
__WFI();
|
|
|
}
|
|
|
/* close servo 1 */
|
|
|
- Servo_1_ON;
|
|
|
+ Servo_1_CHNL = SERVO_CLOSE_VAL;
|
|
|
+ delay_ms(100);
|
|
|
Servo_1_CHNL = SERVO_INIT_VAL;
|
|
|
- Servo_1_OFF;
|
|
|
#endif
|
|
|
|
|
|
#ifdef USE_SERVO_2
|
|
@@ -102,71 +99,23 @@ int main(void)
|
|
|
//IWDG->KR = 0xAAAA;
|
|
|
__WFI();
|
|
|
}
|
|
|
- Servo_2_ON;
|
|
|
Servo_2_CHNL = SERVO_OPEN_VAL;
|
|
|
- Servo_2_OFF;
|
|
|
/* wait for light off */
|
|
|
+ timeOut = TIME_WAIT;
|
|
|
while (photo_Value <= PHOTO_LEVEL_OFF) {
|
|
|
- //IWDG->KR = 0xAAAA;
|
|
|
+ if (timeOut == 0) {
|
|
|
+ Servo_2_CHNL = SERVO_INIT_VAL;
|
|
|
+ }
|
|
|
__WFI();
|
|
|
}
|
|
|
- /* close servo 2 */
|
|
|
- Servo_2_ON;
|
|
|
+ /* close servo 1 */
|
|
|
+ Servo_2_CHNL = SERVO_CLOSE_VAL;
|
|
|
+ delay_ms(100);
|
|
|
Servo_2_CHNL = SERVO_INIT_VAL;
|
|
|
- Servo_2_OFF;
|
|
|
#endif
|
|
|
-
|
|
|
- /* end of life */
|
|
|
- //while (1) {
|
|
|
- // __WFI();
|
|
|
- //}
|
|
|
}
|
|
|
} /* End of mine() */
|
|
|
|
|
|
-/*
|
|
|
-static void servo_open(void) {
|
|
|
- int i;
|
|
|
- for (i=SERVO_INIT_VAL; i <= SERVO_OPEN_VAL; i+=50) {
|
|
|
- Servo_1_CHNL = i;
|
|
|
- Servo_2_CHNL = i;
|
|
|
- delay_ms(40);
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-static void servo_close(void) {
|
|
|
- int i;
|
|
|
- for (i=SERVO_OPEN_VAL; i >= SERVO_INIT_VAL; i-=50) {
|
|
|
- Servo_1_CHNL = i;
|
|
|
- Servo_2_CHNL = i;
|
|
|
- delay_ms(40);
|
|
|
- }
|
|
|
-}
|
|
|
-*/
|
|
|
-
|
|
|
-/*
|
|
|
-static void uart_init(uint32_t baud)
|
|
|
-{
|
|
|
- GPIO_SetPinMode(GPIOB, GPIO_PIN_6, GPIO_MODE_AFF);
|
|
|
-
|
|
|
- RCC->APBENR2 |= RCC_APBENR2_USART1EN;
|
|
|
-
|
|
|
- USART1->CR1 = USART_CR1_RE | USART_CR1_TE | USART_CR1_FIFOEN;
|
|
|
- USART1->BRR = (SystemCoreClock / baud);
|
|
|
- USART1->CR1 |= USART_CR1_UE;
|
|
|
-}
|
|
|
-
|
|
|
-static void uart_putc(char c)
|
|
|
-{
|
|
|
- while (0 == (USART1->ISR & USART_ISR_TXE_TXFNF));
|
|
|
- USART1->TDR = c;
|
|
|
-}
|
|
|
-
|
|
|
-static void uart_puts(char *s)
|
|
|
-{
|
|
|
- while (*s)
|
|
|
- uart_putc(*s++);
|
|
|
-}
|
|
|
-*/
|
|
|
|
|
|
/**
|
|
|
* @brief This function is executed in case of error occurrence.
|