Reworked light modes; now there are 3 modes cycled by a button taps - normal, manual on, manual off.
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1004726020860399773" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-637630535799412773" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
</provider>
|
</provider>
|
||||||
@@ -16,7 +16,7 @@
|
|||||||
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
|
||||||
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-1004726020860399773" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
<provider class="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" console="false" env-hash="-637630535799412773" id="com.st.stm32cube.ide.mcu.toolchain.armnone.setup.CrossBuiltinSpecsDetector" keep-relative-paths="false" name="MCU ARM GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}"" prefer-non-shared="true">
|
||||||
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
<language-scope id="org.eclipse.cdt.core.gcc"/>
|
||||||
<language-scope id="org.eclipse.cdt.core.g++"/>
|
<language-scope id="org.eclipse.cdt.core.g++"/>
|
||||||
</provider>
|
</provider>
|
||||||
|
@@ -41,6 +41,16 @@ struct FLASH_sector {
|
|||||||
uint32_t checksum; //Checksum to verify saved data
|
uint32_t checksum; //Checksum to verify saved data
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef enum DLMode_t_enum {
|
||||||
|
DL_normal = 0,
|
||||||
|
DL_manual_on,
|
||||||
|
DL_manual_off,
|
||||||
|
DL_need_config,
|
||||||
|
DL_config_waiting,
|
||||||
|
DL_config_accepted,
|
||||||
|
DL_error
|
||||||
|
} DLMode_t;
|
||||||
|
|
||||||
/* USER CODE END PTD */
|
/* USER CODE END PTD */
|
||||||
|
|
||||||
/* Private define ------------------------------------------------------------*/
|
/* Private define ------------------------------------------------------------*/
|
||||||
@@ -85,10 +95,12 @@ uint8_t TOF_Ready = 0; // Flag to ignore TOF IRQ before it is initialized
|
|||||||
uint8_t curLightLevel = 0; // Current light level (0-99)
|
uint8_t curLightLevel = 0; // Current light level (0-99)
|
||||||
uint16_t curDist = 0; // Current measured distance in mm
|
uint16_t curDist = 0; // Current measured distance in mm
|
||||||
uint16_t btn_ticks; // How many ticks the button is pressed (1 tick = 100ms)
|
uint16_t btn_ticks; // How many ticks the button is pressed (1 tick = 100ms)
|
||||||
uint8_t needConfig = 1; // Need to configure the device. Timers won't "react" to events
|
//uint8_t needConfig = 1; // Need to configure the device. Timers won't "react" to events
|
||||||
uint8_t startConfig = 0; // Flag to start configuration sequence
|
//uint8_t startConfig = 0; // Flag to start configuration sequence
|
||||||
int8_t dLevel = 1; // Direction of fade: -1 for fade out; 1 for fade in;
|
int8_t dLevel = 1; // Direction of fade: -1 for fade out; 1 for fade in;
|
||||||
uint8_t manualOn = 0; // Flag to indicate a manual on
|
//uint8_t manualOn = 0; // Flag to indicate a manual on
|
||||||
|
DLMode_t DLmode = DL_normal; // Global mode: DL_normal, DL_manual_on, DL_manual_off, DL_need_config, DL_config_waiting, DL_config_accepted, DL_error
|
||||||
|
DLMode_t prev_mode = DL_normal;
|
||||||
|
|
||||||
/* USER CODE END PV */
|
/* USER CODE END PV */
|
||||||
|
|
||||||
@@ -134,7 +146,6 @@ volatile void loadConfig(void) {
|
|||||||
saveConfig(); //Save dafault config
|
saveConfig(); //Save dafault config
|
||||||
} // else successfully read the configuration
|
} // else successfully read the configuration
|
||||||
|
|
||||||
needConfig = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//save configuration to FLASH
|
//save configuration to FLASH
|
||||||
@@ -199,15 +210,16 @@ void fastBlink(uint8_t count) {
|
|||||||
|
|
||||||
// Range configuration procedure (set on and off ranges)
|
// Range configuration procedure (set on and off ranges)
|
||||||
void configure(void) {
|
void configure(void) {
|
||||||
startConfig = 0;
|
//startConfig = 0;
|
||||||
|
DLmode = DL_config_waiting;
|
||||||
|
|
||||||
//Fast blink 3 times
|
//Fast blink 5 times
|
||||||
needConfig = 1;
|
//needConfig = 1;
|
||||||
fastBlink(3);
|
fastBlink(5);
|
||||||
|
|
||||||
//Configure ON distance
|
//Configure ON distance
|
||||||
needConfig = 1; // in case the button was touched during fast blinks
|
//needConfig = 1; // in case the button was touched during fast blinks
|
||||||
while (needConfig) {
|
while (DLmode == DL_config_waiting) {
|
||||||
HAL_Delay(250);
|
HAL_Delay(250);
|
||||||
if (curDist > MAX_DIST - MIN_DIST_GAP) setLightLevel(0);
|
if (curDist > MAX_DIST - MIN_DIST_GAP) setLightLevel(0);
|
||||||
// (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
|
// (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
|
||||||
@@ -219,12 +231,13 @@ void configure(void) {
|
|||||||
configuration.config.dist_on = curDist; // this will be checked during config save
|
configuration.config.dist_on = curDist; // this will be checked during config save
|
||||||
|
|
||||||
//Fast blink 2 times
|
//Fast blink 2 times
|
||||||
needConfig = 1;
|
//needConfig = 1;
|
||||||
|
DLmode = DL_config_waiting;
|
||||||
fastBlink(2);
|
fastBlink(2);
|
||||||
|
|
||||||
//Configure OFF distance
|
//Configure OFF distance
|
||||||
needConfig = 1; // in case the button was touched during fast blinks
|
//needConfig = 1; // in case the button was touched during fast blinks
|
||||||
while (needConfig) {
|
while (DLmode == DL_config_waiting) {
|
||||||
HAL_Delay(250);
|
HAL_Delay(250);
|
||||||
if (curDist > MAX_DIST) setLightLevel(0);
|
if (curDist > MAX_DIST) setLightLevel(0);
|
||||||
else setLightLevel((uint8_t)(50 - curDist * 50 / MAX_DIST)); // Map light level to the distance
|
else setLightLevel((uint8_t)(50 - curDist * 50 / MAX_DIST)); // Map light level to the distance
|
||||||
@@ -234,10 +247,10 @@ void configure(void) {
|
|||||||
saveConfig();
|
saveConfig();
|
||||||
|
|
||||||
//Fast blink 5 times
|
//Fast blink 5 times
|
||||||
needConfig = 1;
|
//needConfig = 1;
|
||||||
fastBlink(5);
|
fastBlink(5);
|
||||||
|
|
||||||
needConfig = 0;
|
//needConfig = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* USER CODE END 0 */
|
/* USER CODE END 0 */
|
||||||
@@ -312,8 +325,10 @@ int main(void)
|
|||||||
/* USER CODE BEGIN WHILE */
|
/* USER CODE BEGIN WHILE */
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (startConfig) {
|
if (DLmode == DL_need_config) {
|
||||||
|
prev_mode = DLmode;
|
||||||
configure();
|
configure();
|
||||||
|
DLmode = prev_mode;
|
||||||
}
|
}
|
||||||
|
|
||||||
HAL_Delay(100);
|
HAL_Delay(100);
|
||||||
@@ -643,7 +658,7 @@ void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin) {
|
|||||||
dist = readRangeContinuousMillimeters(0);
|
dist = readRangeContinuousMillimeters(0);
|
||||||
if (dist < MAX_DIST) curDist = dist;
|
if (dist < MAX_DIST) curDist = dist;
|
||||||
else curDist = MAX_DIST;
|
else curDist = MAX_DIST;
|
||||||
if (!needConfig && !manualOn) {
|
if (DLmode == DL_normal) {
|
||||||
if (curDist <= configuration.config.dist_on && curLightLevel < 90) {
|
if (curDist <= configuration.config.dist_on && curLightLevel < 90) {
|
||||||
//Turn on the lights
|
//Turn on the lights
|
||||||
dLevel = 2;
|
dLevel = 2;
|
||||||
@@ -662,38 +677,48 @@ void HAL_GPIO_EXTI_Falling_Callback(uint16_t GPIO_Pin) {
|
|||||||
HAL_TIM_Base_Stop_IT(&htim16);
|
HAL_TIM_Base_Stop_IT(&htim16);
|
||||||
if (btn_ticks < 60) {
|
if (btn_ticks < 60) {
|
||||||
// Button was not held for more than 6 seconds
|
// Button was not held for more than 6 seconds
|
||||||
if (needConfig) {
|
if (DLmode == DL_config_waiting) {
|
||||||
needConfig = 0;
|
//needConfig = 0;
|
||||||
|
DLmode = DL_config_accepted;
|
||||||
} else {
|
} else {
|
||||||
if (curLightLevel < 90){
|
switch (DLmode) {
|
||||||
//Manual turn on
|
case DL_normal:
|
||||||
manualOn = 1;
|
DLmode = DL_manual_on;
|
||||||
|
fastBlink(2);
|
||||||
dLevel = 2;
|
dLevel = 2;
|
||||||
HAL_TIM_Base_Start_IT(&htim17);
|
HAL_TIM_Base_Start_IT(&htim17);
|
||||||
} else {
|
break;
|
||||||
//Manual turn off
|
case DL_manual_on:
|
||||||
manualOn = 0;
|
DLmode = DL_manual_off;
|
||||||
|
fastBlink(3);
|
||||||
dLevel = -1;
|
dLevel = -1;
|
||||||
HAL_TIM_Base_Start_IT(&htim17);
|
HAL_TIM_Base_Start_IT(&htim17);
|
||||||
|
break;
|
||||||
|
case DL_manual_off:
|
||||||
|
DLmode = DL_normal;
|
||||||
|
fastBlink(1);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
setLightLevel(curLightLevel);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim) {
|
||||||
if(htim->Instance == TIM16) { //check if the interrupt comes from TIM16
|
if(htim->Instance == TIM16) { //check if the interrupt comes from TIM16 // TIM16 - ticks timer (10Hz - 100ms)
|
||||||
if (btn_ticks < 60) {
|
if (btn_ticks < 60) {
|
||||||
btn_ticks++;
|
btn_ticks++;
|
||||||
} else { // the button is held for more than 6 seconds
|
} else { // the button is held for more than 6 seconds
|
||||||
HAL_TIM_Base_Stop_IT(&htim16);
|
HAL_TIM_Base_Stop_IT(&htim16);
|
||||||
startConfig = 1;
|
//startConfig = 1;
|
||||||
|
DLmode = DL_need_config;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fade-in / fade-out animation
|
// Fade-in / fade-out animation
|
||||||
if(htim->Instance == TIM17) { //check if the interrupt comes from TIM17
|
if(htim->Instance == TIM17) { //check if the interrupt comes from TIM17 // TIM17 - timer for light fading
|
||||||
curLightLevel += dLevel;
|
curLightLevel += dLevel;
|
||||||
setLightLevel(curLightLevel);
|
setLightLevel(curLightLevel);
|
||||||
if (curLightLevel >= 99 || curLightLevel <= 0) {
|
if (curLightLevel >= 99 || curLightLevel <= 0) {
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"board": {
|
"board": {
|
||||||
"active_layer": 36,
|
"active_layer": 0,
|
||||||
"active_layer_preset": "",
|
"active_layer_preset": "",
|
||||||
"auto_track_width": true,
|
"auto_track_width": true,
|
||||||
"hidden_nets": [],
|
"hidden_nets": [],
|
||||||
|
Reference in New Issue
Block a user