From 53a1b9b7f419d4bb9b4c4e104201b0979a9492c1 Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Wed, 17 May 2017 22:53:16 +1000 Subject: [PATCH] Add sensitivity selection menu --- workspace/ts100/inc/Modes.h | 10 ++++- workspace/ts100/inc/Settings.h | 7 +++- workspace/ts100/src/MMA8652FC.c | 4 +- workspace/ts100/src/Modes.c | 68 +++++++++++++++++++++++++++++++-- workspace/ts100/src/Settings.c | 2 +- 5 files changed, 80 insertions(+), 11 deletions(-) diff --git a/workspace/ts100/inc/Modes.h b/workspace/ts100/inc/Modes.h index 9c44d5dff8..bcfb46247b 100644 --- a/workspace/ts100/inc/Modes.h +++ b/workspace/ts100/inc/Modes.h @@ -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(); diff --git a/workspace/ts100/inc/Settings.h b/workspace/ts100/inc/Settings.h index 25db9f151f..7c0582236c 100644 --- a/workspace/ts100/inc/Settings.h +++ b/workspace/ts100/inc/Settings.h @@ -12,7 +12,10 @@ #include #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(); diff --git a/workspace/ts100/src/MMA8652FC.c b/workspace/ts100/src/MMA8652FC.c index 2fdd95a68b..e6df4ab0f5 100644 --- a/workspace/ts100/src/MMA8652FC.c +++ b/workspace/ts100/src/MMA8652FC.c @@ -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 } diff --git a/workspace/ts100/src/Modes.c b/workspace/ts100/src/Modes.c index 8fab17e4e7..163292f42b 100644 --- a/workspace/ts100/src/Modes.c +++ b/workspace/ts100/src/Modes.c @@ -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; } diff --git a/workspace/ts100/src/Settings.c b/workspace/ts100/src/Settings.c index 49912c32a9..0a88a3c659 100644 --- a/workspace/ts100/src/Settings.c +++ b/workspace/ts100/src/Settings.c @@ -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 }