Backend work for supporting adjusting movement sensitivity
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
#define __MMA8652FC__H
|
||||
|
||||
|
||||
void StartUp_Accelerometer(void);//This is the only function we expose
|
||||
void StartUp_Accelerometer(uint8_t sensitivity);//This is the only function we expose
|
||||
|
||||
//--------------MMA8652 Device ID----------------------------------------------//
|
||||
|
||||
|
||||
@@ -11,20 +11,22 @@
|
||||
#define SETTINGS_H_
|
||||
#include <stdint.h>
|
||||
#include "stm32f10x_flash.h"
|
||||
#define SETTINGSVERSION 0x02 /*Change this if you change the struct below to prevent people getting out of sync*/
|
||||
#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*/
|
||||
/*
|
||||
* This struct must be a multiple of 2 bytes as it is saved / restored from flash in uint16_t chunks
|
||||
*/
|
||||
struct {
|
||||
uint32_t SolderingTemp; //current setpoint for the iron
|
||||
uint32_t SleepTemp; //temp to drop to in sleep
|
||||
uint8_t version; //Used to track if a reset is needed on firmware upgrade
|
||||
uint8_t SleepTime; //minutes timeout to sleep
|
||||
uint8_t cutoutVoltage; //The voltage we cutout at for undervoltage
|
||||
uint8_t movementEnabled; //If movement is enabled
|
||||
uint8_t displayTempInF; //If we need to convert the C reading to F
|
||||
uint8_t flipDisplay; //If true we want to invert the display for lefties
|
||||
uint32_t SolderingTemp; //current setpoint for the iron
|
||||
uint32_t SleepTemp; //temp to drop to in sleep
|
||||
uint8_t version; //Used to track if a reset is needed on firmware upgrade
|
||||
uint8_t SleepTime; //minutes timeout to sleep
|
||||
uint8_t cutoutVoltage:1; //The voltage we cutout at for undervoltage
|
||||
uint8_t movementEnabled:1; //If movement is enabled
|
||||
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
|
||||
} systemSettings;
|
||||
|
||||
void saveSettings();
|
||||
|
||||
@@ -53,7 +53,7 @@ void TIM3_IRQHandler(void) {
|
||||
//used for buttons and movement
|
||||
void EXTI9_5_IRQHandler(void) {
|
||||
//we are interested in line 9 and line 6 for buttons
|
||||
//Lien 5 == movement
|
||||
//Line 5 == movement
|
||||
if (EXTI_GetITStatus(EXTI_Line9) != RESET) {
|
||||
if (GPIO_ReadInputDataBit(GPIOA, KEY_A) == SET)
|
||||
keyState &= ~(BUT_A);
|
||||
|
||||
@@ -29,12 +29,12 @@ uint8_t I2C_RegisterRead(uint8_t reg) {
|
||||
return tx_data[0];
|
||||
}
|
||||
|
||||
void StartUp_Accelerometer(void) {
|
||||
void StartUp_Accelerometer(uint8_t sensitivity) {
|
||||
I2C_RegisterWrite(CTRL_REG2, 0); //Normal mode
|
||||
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, 0x0F); // Set threshold
|
||||
I2C_RegisterWrite(FF_MT_THS_REG, sensitivity); // Set threshold
|
||||
I2C_RegisterWrite(FF_MT_COUNT_REG, 0x01); // Set debounce to 100ms
|
||||
|
||||
I2C_RegisterWrite( CTRL_REG4, 0x04); // Enable motion interrupt
|
||||
|
||||
@@ -14,29 +14,30 @@ void setup();
|
||||
int main(void) {
|
||||
setup();/*Setup the system*/
|
||||
while (1) {
|
||||
Clear_Watchdog(); //reset the Watchdog timer
|
||||
Clear_Watchdog(); //reset the Watch dog timer
|
||||
ProcessUI();
|
||||
DrawUI();
|
||||
delayMs(50); //Slow the system down a little bit
|
||||
}
|
||||
}
|
||||
void setup() {
|
||||
RCC_Config(); //setup system clock
|
||||
NVIC_Config(0x4000); //this shifts the NVIC table to be offset, for the usb bootloader's size
|
||||
GPIO_Config(); //setup all the GPIO pins
|
||||
Init_EXTI(); //init the EXTI inputs
|
||||
Init_Timer3(); //Used for the soldering iron tip
|
||||
Adc_Init(); //init adc and dma
|
||||
I2C_Configuration(); //Start the I2C hardware
|
||||
GPIO_Init_OLED(); //Init the GPIO ports for the OLED
|
||||
StartUp_Accelerometer(); //start the accelerometer
|
||||
RCC_Config(); //setup system clock
|
||||
NVIC_Config(0x4000); //this shifts the NVIC table to be offset, for the usb bootloader's size
|
||||
GPIO_Config(); //setup all the GPIO pins
|
||||
Init_EXTI(); //init the EXTI inputs
|
||||
Init_Timer3(); //Used for the soldering iron tip
|
||||
Adc_Init(); //init adc and dma
|
||||
I2C_Configuration(); //Start the I2C hardware
|
||||
GPIO_Init_OLED(); //Init the GPIO ports for the OLED
|
||||
restoreSettings(); //Load settings
|
||||
|
||||
setupPID(); //init the PID values
|
||||
readIronTemp(239, 0); //load the default calibration value
|
||||
restoreSettings(); //Load settings
|
||||
Init_Oled(systemSettings.flipDisplay);//init the OLED display
|
||||
StartUp_Accelerometer(systemSettings.sensitivity); //start the accelerometer
|
||||
|
||||
OLED_DrawString("VER 1.03",8);
|
||||
delayMs(800);
|
||||
Start_Watchdog(1000); //start the system watchdog as 1 seconds timeout
|
||||
setupPID(); //init the PID values
|
||||
readIronTemp(239, 0); //load the default calibration value
|
||||
Init_Oled(systemSettings.flipDisplay); //init the OLED display
|
||||
|
||||
OLED_DrawString("VER 1.03", 8); //1.settings version as of current
|
||||
delayMs(800); //Pause to show version number
|
||||
Start_Watchdog(1000); //start the system watch dog as 1 second timeout
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ void GPIO_Init_OLED(void) {
|
||||
}
|
||||
/*******************************************************************************
|
||||
Function: Init_Oled
|
||||
Description: Initalizes the Oled screen
|
||||
Description: Initializes the Oled screen
|
||||
*******************************************************************************/
|
||||
void Init_Oled(uint8_t leftHanded) {
|
||||
u8 param_len;
|
||||
|
||||
@@ -49,5 +49,8 @@ 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.tempCalibration=239; //Default to their calibration value
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user