Add sensitivity selection menu

This commit is contained in:
Ben V. Brown
2017-05-17 22:53:16 +10:00
parent c9d0d5bdb3
commit 53a1b9b7f4
5 changed files with 80 additions and 11 deletions

View File

@@ -25,11 +25,17 @@ enum {
COOLING,
UVLOWARN,
THERMOMETER,
DCINDISP,
} operatingMode;
enum {
UVCO = 0, SLEEP_TEMP, SLEEP_TIME, MOTIONDETECT, TEMPDISPLAY, LEFTY
UVCO = 0,
SLEEP_TEMP,
SLEEP_TIME,
MOTIONDETECT,
MOTIONSENSITIVITY,
TEMPDISPLAY,
LEFTY,
} settingsPage;
void ProcessUI();

View File

@@ -12,7 +12,10 @@
#include <stdint.h>
#include "stm32f10x_flash.h"
#define SETTINGSVERSION 0x03 /*Change this if you change the struct below to prevent people getting out of sync*/
#define SETTINGSOPTIONSCOUNT 5 /*Number of settings in the settings menu*/
#define SETTINGSOPTIONSCOUNT 6 /*Number of settings in the settings menu*/
#define MOTION_HIGH (0x00)
#define MOTION_MED (0x10)
#define MOTION_LOW (0x20)
/*
* This struct must be a multiple of 2 bytes as it is saved / restored from flash in uint16_t chunks
*/
@@ -26,7 +29,7 @@ struct {
uint8_t displayTempInF:1; //If we need to convert the C reading to F
uint8_t flipDisplay:1; //If true we want to invert the display for lefties
uint8_t sensitivity:7; //Sensitivity of accelerometer
uint16_t tempCalibration; // Temperature calibration value
uint16_t tempCalibration; //Temperature calibration value
} systemSettings;
void saveSettings();

View File

@@ -34,10 +34,10 @@ void StartUp_Accelerometer(uint8_t sensitivity) {
I2C_RegisterWrite( CTRL_REG2, 0x40); // Reset all registers to POR values
delayMs(2); // ~1ms delay
I2C_RegisterWrite(FF_MT_CFG_REG, 0x78); // Enable motion detection for X and Y axis, latch enabled
I2C_RegisterWrite(FF_MT_THS_REG, sensitivity); // Set threshold
I2C_RegisterWrite(FF_MT_THS_REG, sensitivity|0x0F); // Set threshold
I2C_RegisterWrite(FF_MT_COUNT_REG, 0x01); // Set debounce to 100ms
I2C_RegisterWrite( CTRL_REG4, 0x04); // Enable motion interrupt
I2C_RegisterWrite( CTRL_REG5, 0x04);// Route motion interrupts to INT1 ->PB5 ->EXTI
I2C_RegisterWrite( CTRL_REG5, 0x04);// Route motion interrupts to INT1 ->PB5 ->EXTI5
I2C_RegisterWrite( CTRL_REG1, 0x19); // ODR=100 Hz, Active mode
}

View File

@@ -137,6 +137,12 @@ void ProcessUI() {
break;
case LEFTY:
systemSettings.flipDisplay = !systemSettings.flipDisplay;
break;
case MOTIONSENSITIVITY:
systemSettings.sensitivity += 0x10;
if(systemSettings.sensitivity>0x20)
systemSettings.sensitivity=0;//reset to high on wrap
break;
default:
break;
@@ -193,13 +199,36 @@ void ProcessUI() {
break;
case THERMOMETER: {
//This lets the user check the tip temp without heating the iron.. And eventually calibration will be added here
if ((millis() - getLastButtonPress() > 1000))
if (Buttons == (BUT_A | BUT_B)) {
//If the user is holding both button, exit the temp screen
if ((millis() - getLastButtonPress() > 1000)) {
if ((Buttons == BUT_A) | (Buttons == BUT_B)) {
//Single button press, cycle over to the DC display
operatingMode = DCINDISP;
resetLastButtonPress();
resetButtons();
} else if (Buttons == (BUT_A | BUT_B)) {
//If the user is holding both button, exit the screen
operatingMode = STARTUP;
resetLastButtonPress();
resetButtons();
}
}
}
break;
case DCINDISP: {
//This lets the user check the input voltage
if ((millis() - getLastButtonPress() > 1000)) {
if ((Buttons == BUT_A) | (Buttons == BUT_B)) {
//Single button press, cycle over to the temp display
operatingMode = THERMOMETER;
resetLastButtonPress();
resetButtons();
} else if (Buttons == (BUT_A | BUT_B)) {
//If the user is holding both button, exit the screen
operatingMode = STARTUP;
resetLastButtonPress();
resetButtons();
}
}
}
break;
default:
@@ -302,6 +331,23 @@ void DrawUI() {
else
OLED_DrawString("FLPDSP F", 8);
break;
case MOTIONSENSITIVITY:
switch (systemSettings.sensitivity) {
case MOTION_HIGH:
OLED_DrawString("SENSE H ", 8);
break;
case MOTION_MED:
OLED_DrawString("SENSE M ", 8);
break;
case MOTION_LOW:
OLED_DrawString("SENSE L ", 8);
break;
default:
OLED_DrawString("SENSE ", 8);
break;
}
break;
default:
break;
}
@@ -321,10 +367,24 @@ void DrawUI() {
OLED_DrawString("LOW VOLT", 8);
break;
case THERMOMETER:
temp = readIronTemp(0, 1);//Force a reading as heater is off
temp = readIronTemp(0, 1); //Force a reading as heater is off
OLED_DrawString("TEMP ", 5);//extra one to it clears the leftover 'L' from IDLE
drawTemp(temp, 5);
break;
case DCINDISP: {
uint16_t voltage = readDCVoltage(); //get X10 voltage
OLED_DrawString("IN", 2);
OLED_DrawChar((voltage / 100) % 10, 2);
voltage -= (voltage / 100) * 100;
OLED_DrawChar((voltage / 10) % 10, 3);
voltage -= (voltage / 10) * 10;
OLED_DrawChar('.', 4);
OLED_DrawChar(voltage % 10, 5);
OLED_DrawChar('V', 6);
OLED_DrawChar(' ', 7);
}
break;
default:
break;
}

View File

@@ -49,7 +49,7 @@ void resetSettings() {
systemSettings.version = SETTINGSVERSION; //Store the version number to allow for easier upgrades
systemSettings.displayTempInF =0; //default to C
systemSettings.flipDisplay=0; //Default to right handed mode
systemSettings.sensitivity=0x0F; //Default high sensitivity
systemSettings.sensitivity=0x00; //Default high sensitivity
systemSettings.tempCalibration=239; //Default to their calibration value
}