Ver Fonte

Clean code from sensor, top buton, fade in/out.

Vladimir N. Shilov há 2 anos atrás
pai
commit
f19757dcdf
7 ficheiros alterados com 59 adições e 255 exclusões
  1. 1 1
      Inc/board.h
  2. 16 0
      ReadMe.txt
  3. 16 14
      Src/board.c
  4. 22 206
      Src/clock.c
  5. 2 1
      Src/event-system.c
  6. 1 1
      Src/main.c
  7. 1 32
      Src/stm32g0xx_it.c

+ 1 - 1
Inc/board.h

@@ -162,7 +162,7 @@ typedef union {
 #define UART_ST_Pin GPIO_PIN_15
 
 /* BTNs */
-#define BTN_NUM             4
+#define BTN_NUM             3
 #define BTN1_PIN            GPIO_IDR_ID2
 #define BTN2_PIN            GPIO_IDR_ID12
 #define BTN3_PIN            GPIO_IDR_ID4

+ 16 - 0
ReadMe.txt

@@ -111,3 +111,19 @@ Segger убрал, в хардфаулт падает только он.
 код цвета дня, код цвета ночи - 2 байта (0..59).
 Пока ужиматься не нужно - будет 8 байт, при необходимости можно сократить до 6-ти,
 освободив 2 байта для чего-то другого.
+---
+23.08.2022
+
+У нас тут война с 24-го февраля...
+Напали на нас ебаные москали...
+
+По часам, что я последнее помню: в корпусе, с сенсорной "кнопкой" - полный 
+капец... Ёмкостной датчик срабытвает хаотично когда и как попало.
+Сенсор BME временами выдёт хрень, особенно по давлению.
+Средний индикатор (-, + и т.д.) иногда не гасится, иногда гасится - выглядит 
+это всё довольно убого. Эти плавные переключения - отстой.
+
+Хочу одни часы сделать без датчика и, соотвественно, с отключеной сенсорной 
+кнопкой - тупо часы, и отдать их тёще. Больше года просит, пиздец стыдно...
+
+Пока оставил эффекты при смене цифр. Возможно их тоже стоит убрать.

+ 16 - 14
Src/board.c

@@ -37,9 +37,9 @@ static void SPI1_Init(void);
 static void TIM1_Init(void);
 static void TIM3_Init(void);
 static void TIM14_Init(void);
-static void TIM16_Init(void);
-static void TIM17_Init(void);
-static void USART1_UART_Init(void);
+//static void TIM16_Init(void);
+//static void TIM17_Init(void);
+//static void USART1_UART_Init(void);
 
 /* Board perephireal Configuration  */
 void Board_Init(void)
@@ -91,7 +91,7 @@ void Board_Init(void)
   /* Tube Blink timer */
   TIM14_Init();
   /* IN15 Fade In/Out timer */
-  TIM16_Init();
+  //TIM16_Init();
   //TIM17_Init();
 
   //USART1_UART_Init();
@@ -366,8 +366,6 @@ static void GPIO_Init(void)
   /* EXTI Line: falling, no pull, input */
   // interrupt on line 14
   EXTI->IMR1 |= EXTI_IMR1_IM14;
-  // wake-up with event ?
-  //EXTI->EMR1 |= EXTI_EMR1_EM14;
   // TRIGGER FALLING
   EXTI->FTSR1 = EXTI_FTSR1_FT14;
   // external interrupt selection - PC14 to EXTI14
@@ -687,31 +685,30 @@ void Blink_Stop(void)
   /* disable timer */
   TIM14->CR1 &= ~(TIM_CR1_CEN);
 
-  /* enable channels */
+  /* enable channels & clean flag */
   if (Flag.Blink_1 != 0) {
     TUBE_A_ON;
+    Flag.Blink_1 = 0;
   }
   if (Flag.Blink_2 != 0) {
     TUBE_B_ON;
+    Flag.Blink_2 = 0;
   }
   if (Flag.Blink_3 != 0) {
     TUBE_C_ON;
+    Flag.Blink_3 = 0;
   }
   if (Flag.Blink_4 != 0) {
     TUBE_D_ON;
+    Flag.Blink_4 = 0;
   }
   if (Flag.Blink_5 != 0) {
     TUBE_E_ON;
+    Flag.Blink_5 = 0;
   }
-
-	/* clear flags */
-	Flag.Blink_1 = 0;
-	Flag.Blink_2 = 0;
-	Flag.Blink_3 = 0;
-	Flag.Blink_4 = 0;
-	Flag.Blink_5 = 0;
 }
 
+#ifdef USE_TIM16
 /**
   * @brief TIM16 Initialization Function
   * @param None
@@ -745,7 +742,9 @@ static void TIM16_Init(void)
   /* TIM_EnableCounter */
   TIM16->CR1 |= TIM_CR1_CEN;
 }
+#endif /* USE_TIM16 */
 
+#ifdef USE_TIM17
 /**
   * @brief TIM17 Initialization Function
   * @param None
@@ -779,7 +778,9 @@ static void TIM17_Init(void)
   /* Enable IRQ */
   TIM17->DIER = TIM_DIER_UIE;
 }
+#endif /* USE_TIM17 */
 
+#ifdef USE_UART
 /**
   * @brief USART1 Initialization Function
   * @param None
@@ -815,3 +816,4 @@ static void USART1_UART_Init(void)
   {
   }
 }
+#endif /* USE_UART */

+ 22 - 206
Src/clock.c

@@ -16,16 +16,14 @@ static rtc_t setClock;
 static btn_t Button[BTN_NUM] = {
   {0, evBTN1Pressed, evBTN1Holded,  BTN1_PIN},
   {0, evBTN2Pressed, evBTN2Pressed, BTN2_PIN},
-  {0, evBTN3Pressed, evBTN3Pressed, BTN3_PIN},
-  {0, evBTN4Pressed, evBTN4Holded,  BTN4_PIN}
+  {0, evBTN3Pressed, evBTN3Pressed, BTN3_PIN} //,
+  //{0, evBTN4Pressed, evBTN4Holded,  BTN4_PIN}
 };
 //convert linear bright level to logariphmic
 const uint8_t cie[MAX_BRIGHT_LVL + 1] = {
   0, 2, 4, 8, 13, 20, 29, 40, 54, 72, 92, 116, 145, 177, 214, 255
 };
 volatile static uint8_t dispWDT = 0;
-volatile in15_pin_t SymbolIN15 = sym_None;
-static in15_pin_t symToFade = 0;
 static uint8_t LightingBright;
 static light_mode_t LightingMode;
 static uint8_t LightingColour;
@@ -34,13 +32,6 @@ static flash_data_t Lighting, setLighting;
 /* function prototypes */
 static void check_DayNight(void);
 static void HSV2LED(const uint8_t hue, const uint8_t val);
-static void MinusFadeIn(void);
-static void MinusFadeOut(void);
-static void PlusFadeIn(void);
-static void PercentFadeIn(void);
-static void PressureFadeIn(void);
-static void IN15_FadeIn(void);
-static void IN15_FadeOut(void);
 static void valIncrease(uint8_t * val, const uint8_t max);
 static void valDecrease(uint8_t * val, const uint8_t max);
 static void dvalIncrease(uint8_t * val, const uint8_t max);
@@ -142,197 +133,31 @@ void new_Second(void) {
   */
 void in15Off(void) {
   IN15_OFF;
-  //TUBE_C_OFF;
-	//while (SymbolIN15 != sym_None) {}
-  //SymbolIN15 = sym_Off;
+  TUBE_C_OFF;
 }
 
 void in15Minus(void) {
-  //IN15_OFF;
-  //IN15_Minus;
-  //TUBE_C_ON;
-	while (SymbolIN15 != sym_None) {}
-  SymbolIN15 = sym_Minus;
+  IN15_OFF;
+  IN15_Minus;
+  TUBE_C_ON;
 }
 
 void in15Plus(void) {
   IN15_OFF;
-  //IN15_Plus;
-  //TUBE_C_ON;
-  SymbolIN15 = sym_Plus;
+  IN15_Plus;
+  TUBE_C_ON;
 }
 
 void in15Percent(void) {
   IN15_OFF;
-  //IN15_Percent;
-  //TUBE_C_ON;
-  SymbolIN15 = sym_Percent;
+  IN15_Percent;
+  TUBE_C_ON;
 }
 
 void in15P(void) {
   IN15_OFF;
-  //IN15_P;
-  //TUBE_C_ON;
-  SymbolIN15 = sym_Pressure;
-}
-
-/** 'Faded' funcions */
-static void MinusFadeIn(void) {
-  static uint8_t on = FADE_START;
-  static uint8_t off = FADE_STOP;
-  static uint8_t st = 0;
-
-  if (st == 0) {
-    st = 1;
-    IN15_Minus;
-    on += FADE_STEP;
-    if (on < FADE_STOP) {
-      RTOS_SetTask(MinusFadeIn, on, 0);
-    } else {
-      on = FADE_START; off = FADE_STOP; st = 0;
-    }
-  } else {
-    st = 0;
-    IN15_OFF;
-    off -= FADE_STEP;
-    RTOS_SetTask(MinusFadeIn, off, 0);
-  }
-}
-
-static void MinusFadeOut(void) {
-  static uint8_t off = FADE_START;
-  static uint8_t on = FADE_STOP;
-  static uint8_t st = 0;
-
-  if (st == 0) {
-    st = 1;
-    IN15_OFF;
-    off += FADE_STEP;
-    if (off < FADE_STOP) {
-      RTOS_SetTask(MinusFadeOut, off, 0);
-    } else {
-      off = FADE_START; on = FADE_STOP; st = 0;
-    }
-  } else {
-    st = 0;
-    IN15_Minus;
-    on -= FADE_STEP;
-    RTOS_SetTask(MinusFadeOut, on, 0);
-  }
-}
-
-static void PlusFadeIn(void) {
-  static uint8_t on = FADE_START;
-  static uint8_t off = FADE_STOP;
-  static uint8_t st = 0;
-
-  if (st == 0) {
-    st = 1;
-    IN15_Plus;
-    on += FADE_STEP;
-    if (on < FADE_STOP) {
-      RTOS_SetTask(PlusFadeIn, on, 0);
-    } else {
-      on = FADE_START; off = FADE_STOP; st = 0;
-    }
-  } else {
-    st = 0;
-    IN15_OFF;
-    off -= FADE_STEP;
-    RTOS_SetTask(PlusFadeIn, off, 0);
-  }
-}
-
-static void PercentFadeIn(void) {
-  static uint8_t on = FADE_START;
-  static uint8_t off = FADE_STOP;
-  static uint8_t st = 0;
-
-  if (st == 0) {
-    st = 1;
-    IN15_Percent;
-    on += FADE_STEP;
-    if (on < FADE_STOP) {
-      RTOS_SetTask(PercentFadeIn, on, 0);
-    } else {
-      on = FADE_START; off = FADE_STOP; st = 0;
-    }
-  } else {
-    st = 0;
-    IN15_OFF;
-    off -= FADE_STEP;
-    RTOS_SetTask(PercentFadeIn, off, 0);
-  }
-}
-
-static void PressureFadeIn(void) {
-  static uint8_t on = FADE_START;
-  static uint8_t off = FADE_STOP;
-  static uint8_t st = 0;
-
-  if (st == 0) {
-    st = 1;
-    IN15_P;
-    on += FADE_STEP;
-    if (on < FADE_STOP) {
-      RTOS_SetTask(PressureFadeIn, on, 0);
-    } else {
-      on = FADE_START; off = FADE_STOP; st = 0;
-    }
-  } else {
-    st = 0;
-    IN15_OFF;
-    off -= FADE_STEP;
-    RTOS_SetTask(PressureFadeIn, off, 0);
-  }
-}
-
-static void IN15_FadeIn(void) {
-  static uint8_t on = FADE_START;
-  static uint8_t off = FADE_STOP;
-  static uint8_t st = 0;
-
-  if (symToFade != 0) {
-    if (st == 0) {
-      st = 1;
-      GPIOA->BSRR = symToFade;
-      on += FADE_STEP;
-      if (on < FADE_STOP) {
-        RTOS_SetTask(IN15_FadeIn, on, 0);
-      } else {
-        on = FADE_START; off = FADE_STOP; st = 0; symToFade = 0;
-      }
-    } else {
-      st = 0;
-      IN15_OFF;
-      off -= FADE_STEP;
-      RTOS_SetTask(IN15_FadeIn, off, 0);
-    }
-  }
-}
-
-static void IN15_FadeOut(void) {
-  static uint8_t off = FADE_START;
-  static uint8_t on = FADE_STOP;
-  static uint8_t st = 0;
-
-  if (symToFade != 0) {
-    if (st == 0) {
-      st = 1;
-      IN15_OFF;
-      off += FADE_STEP;
-      if (off < FADE_STOP) {
-        RTOS_SetTask(IN15_FadeOut, off, 0);
-      } else {
-        off = FADE_START; on = FADE_STOP; st = 0; symToFade = 0;
-      }
-    } else {
-      st = 0;
-      GPIOA->BSRR = symToFade;
-      on -= FADE_STEP;
-      RTOS_SetTask(IN15_FadeOut, on, 0);
-    }
-  }
+  IN15_P;
+  TUBE_C_ON;
 }
 
 /**
@@ -386,7 +211,6 @@ static void HSV2LED(const uint8_t hue, const uint8_t val) {
   */
 void showTime(void) {
   uint8_t hue;
-	//MinusFadeIn();
 	in15Minus();
   RTOS_SetTask(in15Off, 500, 0);
 
@@ -414,8 +238,7 @@ void showTime(void) {
 }
 
 void showMMSS(void) {
-  RTOS_DeleteTask(MinusFadeOut);
-  IN15_Minus;
+	in15Minus();
 
   uint8_t hue = bcd2bin(Clock.Sec);
   HSV2LED(hue, LightingBright);
@@ -430,7 +253,7 @@ void showMMSS(void) {
 
 void showWD(void) {
   dispWDT = DISP_WDT_TIME;
-  IN15_OFF;
+  in15Off();
 
   tube4_t buf;
   buf.s8.tA = TUBE_BLANK;
@@ -442,7 +265,7 @@ void showWD(void) {
 
 void showDayMon(void) {
   dispWDT = DISP_WDT_TIME;
-  IN15_OFF;
+  in15Off();
 
   tube4_t buf;
   buf.s8.tA = Clock.Day >> 4;
@@ -454,7 +277,7 @@ void showDayMon(void) {
 
 void showYear(void) {
   dispWDT = DISP_WDT_TIME;
-  IN15_OFF;
+  in15Off();
 
   tube4_t buf;
   buf.s8.tA = 2;
@@ -467,8 +290,7 @@ void showYear(void) {
 void showHumidity(void) {
   dispWDT = DISP_WDT_TIME/2;
   HSV2LED(COLOUR_BLUE, LightingBright);
-  symToFade = sym_Percent;
-  IN15_FadeIn();
+  in15Percent();
 
   tube4_t buf;
   buf.s8.tA = Humidity / 10;
@@ -481,10 +303,7 @@ void showHumidity(void) {
 void showTemperature(void) {
   dispWDT = DISP_WDT_TIME/2;
   HSV2LED(COLOUR_RED, LightingBright);
-  RTOS_DeleteTask(MinusFadeIn);
-  RTOS_DeleteTask(MinusFadeOut);
-  symToFade = sym_Plus;
-  IN15_FadeIn();
+  in15Plus();
 
   tube4_t buf;
   buf.s8.tA = TUBE_BLANK;
@@ -497,8 +316,7 @@ void showTemperature(void) {
 void showPressure(void) {
   dispWDT = DISP_WDT_TIME/2;
   HSV2LED(COLOUR_GREEN, LightingBright);
-  symToFade = sym_Pressure;
-  IN15_FadeIn();
+  in15P();
 
   tube4_t buf;
   int tmp;
@@ -512,7 +330,7 @@ void showPressure(void) {
 
 /* Simple function for cyclic show all sensor data */
 void showSensorData(void) {
-  RTOS_DeleteTask(MinusFadeOut);
+  in15Off();
 
   showTemperature();
   tdelay_ms(3000);
@@ -524,7 +342,6 @@ void showSensorData(void) {
   tdelay_ms(2700);
 
   ES_SetState(stShowTime);
-//  showTime();
 }
 
 void setTimeShow(void) {
@@ -539,7 +356,6 @@ void setTimeShow(void) {
 }
 
 void setTimeBegin(void) {
-  RTOS_DeleteTask(MinusFadeOut);
   in15Minus();
   HSV2LED(COLOUR_NIXIE, LightingBright);
   RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
@@ -593,7 +409,7 @@ void setTimeEnd(void) {
 }
 
 void setDateBegin(void) {
-  IN15_OFF;
+  in15Off();
   HSV2LED(COLOUR_NIXIE, LightingBright);
   RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
   RTC_ReadAll(&setClock);
@@ -794,7 +610,7 @@ void showDNcolour(void) {
 }
 
 void setDNbegin(void) {
-  IN15_OFF;
+  in15Off();
   RTOS_SetTask(btnProcess, BTN_TIME_HOLDED, BTN_SCAN_PERIOD);
   setLighting.u64 = Lighting.u64;
   //Flash_Read(&setLighting.u64);

+ 2 - 1
Src/event-system.c

@@ -44,12 +44,13 @@ const table_state_t stateTable[] = {
   // '+' Button pressed
   {stShowTime, evBTN2Pressed, stShowMMSS, showMMSS,   NULL},
   {stShowMMSS, evBTN2Pressed, stShowTime, showTime,   NULL},
+/*
   // Top Buton pressed
   {stShowTime,        evBTN4Pressed, stShowTemperature, showTemperature, NULL},
   {stShowTemperature, evBTN4Pressed, stShowHumidity,    showHumidity,    NULL},
   {stShowHumidity,    evBTN4Pressed, stShowPressure,    showPressure,    NULL},
   {stShowPressure,    evBTN4Pressed, stShowTime,        showTime,        NULL},
-
+*/
   /* display wdt events */
   {stShowWDay,        evDisplayWDT, stShowTime, showTime, NULL},
   {stShowDM,          evDisplayWDT, stShowTime, showTime, NULL},

+ 1 - 1
Src/main.c

@@ -47,7 +47,7 @@ int main(void)
 
   /* Init devices at I2C bus */
   RTC_Init();
-  sensor_Init();
+  //sensor_Init();
 
   /* Init Clock module */
   Clock_Init();

+ 1 - 32
Src/stm32g0xx_it.c

@@ -28,7 +28,6 @@
 /* Private function prototypes -----------------------------------------------*/
 /* Private user code ---------------------------------------------------------*/
 /* External variables --------------------------------------------------------*/
-extern volatile in15_pin_t SymbolIN15;
 
 /******************************************************************************/
 /*           Cortex-M0+ Processor Interruption and Exception Handlers          */
@@ -207,39 +206,9 @@ void TIM14_IRQHandler(void)
 #define STOP_FADE_TIME  20
 void TIM16_IRQHandler(void)
 {
-  static in15_pin_t sym_old = sym_Off;
-  static uint8_t ph = 0;
-  static uint8_t on = 0;
-  static uint8_t cnt = 0;
-
+  /* Clear interrupt flag */
   if ((TIM16->SR & TIM_SR_UIF) != 0) {
-    /* Clear interrupt flag */
     TIM16->SR = 0;
-
-    if (SymbolIN15 != sym_None) {
-      if (cnt > 0) {
-        cnt --;
-      } else {
-
-        if (ph == 0) {
-          ph = 1;
-          GPIOA->BSRR = SymbolIN15;
-          if (on < STOP_FADE_TIME) {
-            on += 2;
-            cnt = on;
-          } else {
-            ph = 0; on = 0; cnt = 0;
-            sym_old = SymbolIN15;
-            SymbolIN15 = sym_None;
-          }
-        } else {
-          ph = 0;
-          GPIOA->BSRR = sym_old;
-          cnt = STOP_FADE_TIME - on;
-        }
-
-      } /* cnt == 0 */
-    } /* SymbolIN15 not empty */
   }
 }