From 52e92feae7f2a33ed301ba18aae4ffa14f75d22e Mon Sep 17 00:00:00 2001 From: "Ben V. Brown" Date: Tue, 20 Sep 2016 23:11:36 +1000 Subject: [PATCH] Moved to use EXTI to read button status Temperature sensor appears to work (may need calibration work still) --- workspace/ts100/inc/Analog.h | 3 + workspace/ts100/inc/Bios.h | 35 +- workspace/ts100/inc/CTRL.h | 71 --- workspace/ts100/inc/Font.h | 2 + workspace/ts100/inc/Hardware.h | 49 -- workspace/ts100/inc/Interrupt.h | 15 + workspace/ts100/inc/Modes.h | 11 +- workspace/ts100/inc/Oled.h | 2 + workspace/ts100/inc/S100V0_1.h | 9 +- workspace/ts100/inc/UI.h | 46 -- workspace/ts100/src/Analog.c | 2 +- workspace/ts100/src/Bios.c | 69 ++- workspace/ts100/src/CTRL.c | 441 ------------- workspace/ts100/src/Hardware.c | 225 ------- workspace/ts100/src/Interrupt.c | 201 ++++-- workspace/ts100/src/MMA8652FC.c | 3 +- workspace/ts100/src/Main.c | 42 +- workspace/ts100/src/Modes.c | 59 +- workspace/ts100/src/Oled.c | 46 +- workspace/ts100/src/UI.c | 1025 ------------------------------- 20 files changed, 321 insertions(+), 2035 deletions(-) delete mode 100644 workspace/ts100/inc/CTRL.h delete mode 100644 workspace/ts100/inc/Hardware.h delete mode 100644 workspace/ts100/inc/UI.h delete mode 100644 workspace/ts100/src/CTRL.c delete mode 100644 workspace/ts100/src/Hardware.c delete mode 100644 workspace/ts100/src/UI.c diff --git a/workspace/ts100/inc/Analog.h b/workspace/ts100/inc/Analog.h index ca8dcee7..3ca5fcd4 100644 --- a/workspace/ts100/inc/Analog.h +++ b/workspace/ts100/inc/Analog.h @@ -8,6 +8,9 @@ #ifndef ANALOG_H_ #define ANALOG_H_ #include "stm32f10x.h" +#include "S100V0_1.h" +#include "Bios.h" +extern volatile uint16_t ADC1ConvertedValue[2]; uint16_t Get_ADC1Value(uint8_t i); uint16_t readIronTemp(uint16_t calibration); diff --git a/workspace/ts100/inc/Bios.h b/workspace/ts100/inc/Bios.h index aa3e5bef..987e0f16 100644 --- a/workspace/ts100/inc/Bios.h +++ b/workspace/ts100/inc/Bios.h @@ -1,33 +1,25 @@ /********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ******************** -File Name : Bios.h -Version : S100 APP Ver 2.11 -Description: -Author : bure & Celery -Data: 2015/08/03 -History: -2015/08/03 ͳһ������ -*******************************************************************************/ + File Name : Bios.h + Version : S100 APP Ver 2.11 + Description: + Author : bure & Celery + Data: 2015/08/03 + History: + 2015/08/03 ͳһ������ + *******************************************************************************/ #ifndef __BIOS_H #define __BIOS_H #include "stm32f10x.h" #include "S100V0_1.h" +#include "Analog.h" extern volatile u32 gTime[]; +extern volatile uint32_t gHeat_cnt; +inline void setIronTimer(uint32_t time) { + gHeat_cnt = time; +} -#define USB_DN_OUT() GPIOA->CRH = (GPIOA->CRH & 0xFFFF3FFF) | 0x00003000 -#define USB_DP_OUT() GPIOA->CRH = (GPIOA->CRH & 0xFFF3FFFF) | 0x00030000 - -#define USB_DN_EN() GPIOA->CRH = (GPIOA->CRH & 0xFFFFBFFF) | 0x0000B000 -#define USB_DP_EN() GPIOA->CRH = (GPIOA->CRH & 0xFFFBFFFF) | 0x000B0000 - -#define USB_DP_PD() GPIOA->CRH = (GPIOA->CRH & 0xFFF3FFFF) | 0x00030000 - -#define USB_DN_HIGH() GPIOA->BSRR = GPIO_Pin_11 -#define USB_DP_HIGH() GPIOA->BSRR = GPIO_Pin_12 - -#define USB_DN_LOW() GPIOA->BRR = GPIO_Pin_11 -#define USB_DP_LOW() GPIOA->BRR = GPIO_Pin_12 #define LOW 0 #define HIGH 1 @@ -35,7 +27,6 @@ extern volatile u32 gTime[]; #define BLINK 1 // Bit0 : 0/1 ��ʾ/��˸״̬��־ #define WAIT_TIMES 100000 - #define SECTOR_SIZE 512 #define SECTOR_CNT 4096 #define HEAT_T 200 diff --git a/workspace/ts100/inc/CTRL.h b/workspace/ts100/inc/CTRL.h deleted file mode 100644 index cca59dbf..00000000 --- a/workspace/ts100/inc/CTRL.h +++ /dev/null @@ -1,71 +0,0 @@ -/********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ********************** - File Name : CTRL.h - Version : S100 APP Ver 2.11 - Description: - Author : Celery - Data: 2015/07/07 - History: - 2015/07/07 ͳһ������ - *******************************************************************************/ -#ifndef _CTRL_H -#define _CTRL_H - -#include "stm32f10x.h" -#include "Bios.h" - -#define TEMPSHOW_TIMER gTime[0]/*TEMPSHOW_TIMER*/ -#define HEATING_TIMER gTime[1]/*HEATING_TIMER*/ -#define ENTER_WAIT_TIMER gTime[2]/*ENTER_WAIT_TIMER*/ -#define EFFECTIVE_KEY_TIMER gTime[3]/*EFFECTIVE_KEY_TIMER*/ -#define LEAVE_WAIT_TIMER gTime[4]/*LEAVE_WAIT_TIMER*/ -#define G6_TIMER gTime[5]/*SWITCH_SHOW_TIMER*/ -#define UI_TIMER gTime[6]/*UI_TIMER */ -#define KD_TIMER gTime[7]/**/ - -///^^-- All the times in gTime are decremented by 1 if >0 by timer2 tick -//------------------------------ ------------------------------------// -#define KEY_ST(KEY_PIN) GPIO_ReadInputDataBit(GPIOA, KEY_PIN) -#define NO_KEY 0x0 /*NO Keys pressed*/ -#define KEY_A 0x0100/*V1 key pressed*/ -#define KEY_B 0x0040/*V2 Key pressed*/ -#define KEY_CN 0X8000/*(Long key press)*/ -#define KEY_V3 (KEY_A|KEY_B)/*Both Keys pressed*/ - -typedef enum WORK_STATUS { - IDLE = 1, //System is idle - THERMOMETER, //Thermometer mode, basically reads sensor and shows temp - SOLDERING_MODE, //Soldering Mode (Temp Controlled) - WAIT, //System in wait state - TEMP_SET, //Setting the soldering temp - SETTINGS_MENU, // Show the user the settings menu - USB_POWER, //USB Powered Mode - MODE_CNG, //DFU mode i think?? - ALARM, //An alarm has been fired -} WORK_STATUS; - -typedef enum WARNING_STATUS { - NORMAL_TEMP = 1, HIGH_TEMP, SEN_ERR, HIGH_VOLTAGE, LOW_VOLTAGE, -} WARNING_STATUS; - -typedef struct { - u8 ver[16]; - s16 t_standby; // 200��C=1800 2520,�����¶� - s16 t_work; // 350��C=3362, �����¶� - s16 t_step; //���ò��� - u32 wait_time; //3*60*100 3 mintute - u32 idle_time; //6*60*100 6 minute -} DEVICE_INFO_SYS; - -extern DEVICE_INFO_SYS device_info; -void Set_PrevTemp(s16 Temp); -u8 Get_CtrlStatus(void); -void Set_CtrlStatus(u8 status); -s16 Get_TempVal(void); -u16 Get_HtFlag(void); -void System_Init(void); -void Pid_Init(void); -u16 Pid_Realize(s16 temp); -u32 Heating_Time(s16 temp, s16 wk_temp); -void Status_Tran(void); -#endif -/******************************** END OF FILE *********************************/ diff --git a/workspace/ts100/inc/Font.h b/workspace/ts100/inc/Font.h index dcba5523..9f30c91b 100644 --- a/workspace/ts100/inc/Font.h +++ b/workspace/ts100/inc/Font.h @@ -81,6 +81,8 @@ const u8 FONT[]={ 0x00,0x00,0x00,0x00,0x00,0x1F,0x1F,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/*Y*/ 0x00,0x02,0x02,0x02,0xC2,0xE2,0x3A,0x0E,0x02,0x00,0x00,0x00,0x00,0x00, 0x00,0x10,0x1C,0x17,0x11,0x10,0x10,0x10,0x10,0x00,0x00,0x00,0x00,0x00,/*Z*/ + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, + 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,/* */ }; diff --git a/workspace/ts100/inc/Hardware.h b/workspace/ts100/inc/Hardware.h deleted file mode 100644 index 62ae094b..00000000 --- a/workspace/ts100/inc/Hardware.h +++ /dev/null @@ -1,49 +0,0 @@ -/********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ********************** -File Name : CTRL.h -Version : S100 APP Ver 2.11 -Description: -Author : Celery -Data: 2015/07/07 -History: -2015/07/07 ͳһ������ -*******************************************************************************/ -#ifndef _HARDWARE_H -#define _HARDWARE_H - -#include "stm32f10x.h" - -#define SI_COE 8//56 -#define SI_THRESHOLD 60 - -typedef enum VOL_CLASS { - H_ALARM = 0, - VOL_24, - VOL_19, - VOL_12, - VOL_5, - L_ALARM, -} VOL_CLASS; - -extern s32 gZerop_ad; -extern u8 gCalib_flag; -extern u32 gTurn_offv; - -u32 Get_gKey(void); -void Set_gKey(u32 key); -void Set_LongKeyFlag(u32 flag); -void Zero_Calibration(void); -int Read_Vb(u8 flag); -void Scan_Key(void); -u32 Get_SlAvg(u32 avg_data); -int Get_TempSlAvg(int avg_data); -u32 Get_AvgAd(void); -int Get_SensorTmp(void); -u16 Get_ThermometerTemp(void); -s16 Get_Temp(s16 wk_temp); -void Clear_Watchdog(void); -u32 Start_Watchdog(u32 ms); -u8 Get_AlarmType(void); -void Set_AlarmType(u8 type); -u32 Get_CalFlag(void); -#endif -/******************************** END OF FILE *********************************/ diff --git a/workspace/ts100/inc/Interrupt.h b/workspace/ts100/inc/Interrupt.h index bbde6c3a..1106cb05 100644 --- a/workspace/ts100/inc/Interrupt.h +++ b/workspace/ts100/inc/Interrupt.h @@ -30,10 +30,25 @@ void TIM2_IRQHandler(void); void TIM3_IRQHandler(void); extern volatile uint32_t system_Ticks; +void delayMs(uint32_t ticks); +volatile extern uint32_t lastKeyPress; +volatile extern uint32_t lastMovement; + +volatile extern uint16_t keyState; inline uint32_t millis() { return system_Ticks; } +inline uint32_t getLastButtonPress() { + return lastKeyPress; +} +inline uint32_t getLastMovement(){ +return lastMovement; +} + +inline uint16_t getButtons() { + return keyState; +} void WWDG_IRQHandler(void); void PVD_IRQHandler(void); diff --git a/workspace/ts100/inc/Modes.h b/workspace/ts100/inc/Modes.h index e167d954..dcc4ab17 100644 --- a/workspace/ts100/inc/Modes.h +++ b/workspace/ts100/inc/Modes.h @@ -7,12 +7,10 @@ #ifndef MODES_H_ #define MODES_H_ -#include "CTRL.h" -#include "Hardware.h" #include "Interrupt.h" +#include "S100V0_1.h" #include "Oled.h" -uint32_t LastButtonPushTime; -uint32_t LastMovementTime; + enum { STARTUP, //we are sitting on the prompt to push a button SOLDERING, @@ -25,10 +23,15 @@ enum { UVLO = 0, SLEEP_TEMP, SLEEP_TIME, } settingsPage; + struct { uint32_t SolderingTemp; //current setpoint for the iron uint8_t SleepTime; //minutes to sleep uint32_t SleepTemp; //temp to drop to in sleep uint8_t cutoutVoltage; //X10 the voltage we cutout at for undervoltage + uint8_t movementEnabled; } systemSettings; + +void ProcessUI(); +void DrawUI(); #endif /* MODES_H_ */ diff --git a/workspace/ts100/inc/Oled.h b/workspace/ts100/inc/Oled.h index 0a8280ac..a09d16c3 100644 --- a/workspace/ts100/inc/Oled.h +++ b/workspace/ts100/inc/Oled.h @@ -12,6 +12,7 @@ #define DEVICEADDR_OLED 0x3c #include "stm32f10x.h" +#include "Interrupt.h" void Sc_Pt(u8 Co); void Oled_DisplayOn(void); void Oled_DisplayOff(void); @@ -32,6 +33,7 @@ void Display_BG(void); void OLED_DrawString(char* string, uint8_t length); void OLED_DrawChar(char c, uint8_t x); void OLED_DrawTwoNumber(uint8_t in, uint8_t x); +void OLED_DrawThreeNumber(uint16_t in, uint8_t x); #endif /******************************** END OF FILE *********************************/ diff --git a/workspace/ts100/inc/S100V0_1.h b/workspace/ts100/inc/S100V0_1.h index efe53064..dd18df0b 100644 --- a/workspace/ts100/inc/S100V0_1.h +++ b/workspace/ts100/inc/S100V0_1.h @@ -8,15 +8,19 @@ #define MCU_TYPE "STM32F103T8" #define SCH_VER "2.46" - #define SPIx SPI1 //--------------------------- key Definitions ------------------------------// #define KEY1_PIN GPIO_Pin_9 //PA8 #define KEY2_PIN GPIO_Pin_6 //PA6 + +#define KEY_A KEY1_PIN +#define KEY_B KEY2_PIN +#define BUT_A 0x01 +#define BUT_B 0x02 +#define BUT_AB BUT_A|BUT_B #define KEY_1 !(GPIOA->IDR & KEY1_PIN) #define KEY_2 !(GPIOA->IDR & KEY2_PIN) #define KEY_DFU KEY_1 -#define KEY_ON 0 #define I2C1_DMA_CHANNEL_TX DMA1_Channel6 #define I2C1_DMA_CHANNEL_RX DMA1_Channel7 @@ -27,7 +31,6 @@ #define I2C1_DR_Address 0x40005410 #define I2C2_DR_Address 0x40005810 - //--------------------------- OLED ------------------------------// #define OLED_RST_PIN GPIO_Pin_8 //PA9 #define OLED_RST() GPIO_ResetBits(GPIOA, OLED_RST_PIN) diff --git a/workspace/ts100/inc/UI.h b/workspace/ts100/inc/UI.h deleted file mode 100644 index 400eb42d..00000000 --- a/workspace/ts100/inc/UI.h +++ /dev/null @@ -1,46 +0,0 @@ -/********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ********************** - File Name : UI.h - Version : S100 APP Ver 2.11 - Description: - Author : Celery - Data: 2015/07/07 - History: - 2015/07/07 ͳһ������ - *******************************************************************************/ -#ifndef _UI_H -#define _UI_H - -#include "stm32f10x.h" - -u32 Get_UpdataFlag(void); -void Set_UpdataFlag(u32 Cont); -void APP_Init(void); -u32 Calculation_TWork(u8 Flag); -void Temp_SetProc(void); -void Display_Temp(u8 x, s16 Temp); -void Show_Notice(void); -void Show_Warning(void); -void Show_MiniTS(void); -void Show_TempDown(s16 Temp, s16 Dst_Temp); -void Set_TemperatureShowFlag(u8 flag); -s16 TemperatureShow_Change(u8 flag, s16 Tmp); -u8 Get_TemperatureShowFlag(void); - -void Show_Triangle(u8 empty, u8 fill); -void Shift_Char(u8* ptr, u8 pos); -void Show_Set(void); -void Show_OrderChar(u8* ptr, u8 num, u8 width); -u8 Reverse_Bin8(u8 data); -void Show_ReverseChar(u8* ptr, u8 num, u8 width, u8 direction); -u8 Show_TempReverse(u8 num, u8 width, u8 direction); -void Show_HeatingIcon(u32 ht_flag, u16 active); -void Display_Str(u8 x, char* str); -void Display_Str10(u8 x, char* str); -void Clear_Pervious(u16 data); -void Print_Integer(s32 data, u8 posi); -u8 Roll_Num(u16 Step, u8 Flag); -void OLed_Display(void); -void Show_Cal(u8 flag); -void Show_Config(void); -#endif -/******************************** END OF FILE *********************************/ diff --git a/workspace/ts100/src/Analog.c b/workspace/ts100/src/Analog.c index df059a3f..5bcf790e 100644 --- a/workspace/ts100/src/Analog.c +++ b/workspace/ts100/src/Analog.c @@ -32,7 +32,7 @@ int16_t readTipTemp() { uint32_t max = 0, min; uint32_t ad_value, avg_data; - Set_HeatingTime(0); //set the remaining time to zero + setIronTimer(0); //set the remaining time to zero HEAT_OFF(); //heater must be off delayMs(50); //wait for the heater to time out uint8_t gMeas_cnt = 9; //how many measurements to make diff --git a/workspace/ts100/src/Bios.c b/workspace/ts100/src/Bios.c index 78ddd10f..a54006b8 100644 --- a/workspace/ts100/src/Bios.c +++ b/workspace/ts100/src/Bios.c @@ -11,11 +11,10 @@ #include "APP_Version.h" #include "Bios.h" #include "I2C.h" -#include "CTRL.h" -#include + /******************************************************************************/ #define ADC1_DR_Address ((u32)0x4001244C) -vu32 gHeat_cnt = 0; +volatile uint32_t gHeat_cnt = 0; /******************************************************************************* Function:RCC_Config @@ -48,7 +47,7 @@ void RCC_Config(void) { RCC_ClocksTypeDef RCC_Clocks; RCC_GetClocksFreq(&RCC_Clocks); - SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000);//Enable the systick timer + SysTick_Config(RCC_Clocks.HCLK_Frequency / 1000); //Enable the systick timer } /******************************************************************************* Function: NVIC_Config @@ -253,6 +252,57 @@ void Init_Timer3(void) { NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } +//We want to enable the EXTI IRQ for the two buttons on PA6 and PA9 +void Init_EXTI(void) { + EXTI_InitTypeDef EXTI_InitStructure; + NVIC_InitTypeDef NVIC_InitStructure; + + GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, + GPIO_PinSource6 | GPIO_PinSource9); + + /* Configure EXTI0 line */ + EXTI_InitStructure.EXTI_Line = EXTI_Line6 | EXTI_Line9; + EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt; + EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising_Falling; //trigger on up and down + EXTI_InitStructure.EXTI_LineCmd = ENABLE; + EXTI_Init(&EXTI_InitStructure); + + /* Enable and set EXTI0 Interrupt to the lowest priority */ + NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQn; + NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x0F; + NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0F; + NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; + NVIC_Init(&NVIC_InitStructure); + +} +/******************************************************************************* + Function:Start_Watchdog + Description: Starts the system watchdog timer + *******************************************************************************/ +u32 Start_Watchdog(u32 ms) { + IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); + + /* IWDG counter clock: 40KHz(LSI) / 32 = 1.25 KHz (min:0.8ms -- max:3276.8ms */ + IWDG_SetPrescaler(IWDG_Prescaler_32); + + /* Set counter reload value to XXms */ + IWDG_SetReload(ms * 10 / 8); + + /* Reload IWDG counter */ + IWDG_ReloadCounter(); + + /* Enable IWDG (the LSI oscillator will be enabled by hardware) */ + IWDG_Enable(); + return 1; +} +/******************************************************************************* + Function:Clear_Watchdog + Description:Resets the watchdog timer + *******************************************************************************/ +void Clear_Watchdog(void) { + IWDG_ReloadCounter(); + +} /******************************************************************************* Function:TIM2_ISR Description:Handles Timer 2 tick. (10mS) @@ -260,15 +310,9 @@ void Init_Timer3(void) { Also reads the buttons every 4 ticks *******************************************************************************/ void TIM2_ISR(void) { - volatile static u8 buttonReadDivider; TIM_ClearITPendingBit(TIM2, TIM_IT_Update); // Clear interrupt flag - for (u8 i = 0; i < 8; i++) - if (gTime[i] > 0) - gTime[i]--; - if (++buttonReadDivider % 4 == 0) - Scan_Key(); } /******************************************************************************* Function: TIM3_ISR @@ -280,11 +324,6 @@ void TIM3_ISR(void) { TIM_ClearITPendingBit(TIM3, TIM_IT_Update); // Clear interrupt flag - if (gTimeOut > 0) - gTimeOut--; - if (gMs_timeout > 0) - gMs_timeout--; - if (gHeat_cnt > 0) { --gHeat_cnt; if (heat_flag) diff --git a/workspace/ts100/src/CTRL.c b/workspace/ts100/src/CTRL.c deleted file mode 100644 index ef059fb5..00000000 --- a/workspace/ts100/src/CTRL.c +++ /dev/null @@ -1,441 +0,0 @@ -/********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ********************** - File Name : CTRL.c - Version : S100 APP Ver 2.11 - Description: - Author : Celery - Data: 2015/08/03 - History: - 2015/07/07 ͳһ������ - 2015/08/03 �Ż��ƶ��ж� - *******************************************************************************/ -#include -#include -#include "CTRL.h" -#include "Bios.h" -#include "UI.h" -#include "Hardware.h" -#include "S100V0_1.h" -#include "MMA8652FC.h" - -#define HEATINGCYCLE 30 -/******************************************************************************/ -DEVICE_INFO_SYS device_info; -/******************************************************************************/ - -u8 gCtrl_status = 1; -//^ System current status / operating mode. -u16 gHt_flag = 0; -vs16 gTemp_data = 250; // -s16 gPrev_temp = 250; // -u8 gIs_restartkey = 0; // -u8 gPre_status = 1; // - -const DEVICE_INFO_SYS info_def = { "2.13", //Ver - 1000, //T_Standby; // 200C=1800 2520 - 1000, // T_Work; // 350C=3362, - 100, //T_Step; - 3 * 60 * 100, //Wait_Time; //3*60*100 3 minutes - 6 * 60 * 100 // Idle_Time; //6*60*100 6 minutes -}; -struct _pid { - s16 settemp; //Current ideal setpoint for the temp - s16 actualtemp; //Actual current temp of the tip - s16 err; //Error term - s16 err_last; //last error term - s32 ht_time; // - u16 kp, ki, kd; //Constants for the PID Controller - s32 integral; // -} pid; - -/******************************************************************************* - Function: Get_Ctrl_Status - Description: Returns the current operating Mode - Input:Void - Output:Current System Status - *******************************************************************************/ -u8 Get_CtrlStatus(void) { - return gCtrl_status; -} -/******************************************************************************* - Function: Set_CtrlStatus - Description: Set the current operating Mode - Input:status uint8_t - Output:Void - *******************************************************************************/ -void Set_CtrlStatus(u8 status) { - gCtrl_status = status; -} -/******************************************************************************* - Function: Set_PrevTemp - Description:Set the previous temp record for the PID - Input:Previous Temp (int16_t) - Output:Void - *******************************************************************************/ -void Set_PrevTemp(s16 temp) { - gPrev_temp = temp; -} - -/******************************************************************************* - Function: Get_HtFlag - Description: - Input:Void - Output:Void - - *******************************************************************************/ -u16 Get_HtFlag(void) { - return gHt_flag; -} -/******************************************************************************* - Function:Get_TempVal - Description: - Input:Void - Output:Void - *******************************************************************************/ -s16 Get_TempVal(void) { - return gTemp_data; -} - -/******************************************************************************* - Function:System_Init - Description:Init the device info to be a known start value (as defined at top of CTRL.c) - Input:Void - Output:Void - *******************************************************************************/ -void System_Init(void) { - memcpy((void*) &device_info, (void*) &info_def, sizeof(device_info)); -} -/******************************************************************************* - Function:Pid_Init - Description:Inits the PID values to defaults (0 usually) - Input:Void - Output:Void - *******************************************************************************/ -void Pid_Init(void) { - pid.settemp = 0; - pid.actualtemp = 0; - pid.err = 0; - pid.err_last = 0; - pid.integral = 0; - pid.ht_time = 0; - pid.kp = 15; - pid.ki = 2; - pid.kd = 1; -} - -/******************************************************************************* - Function:Pid_Realize - Description: Calculates the next heating value using the PID algorithum - Input:Current temp from the tip - Output: - *******************************************************************************/ -u16 Pid_Realize(s16 temp) { - u8 index = 0, index1 = 1; - s16 d_err = 0; - - pid.actualtemp = temp; - pid.err = pid.settemp - pid.actualtemp; // - - if (pid.err >= 500)//error is > 50 degrees - index = 0; - else { - index = 1; - pid.integral += pid.err; // - } -//////////////////////////////////////////////////////////////////////////////// -// - if (pid.settemp < pid.actualtemp) {//cooling down - d_err = pid.actualtemp - pid.settemp; - if (d_err > 20) { - pid.integral = 0; // - index1 = 0; - index = 0; - } - } -//////////////////////////////////////////////////////////////////////////////// - if (pid.err <= 30) - index1 = 0; - else - index1 = 1; - pid.ht_time = pid.kp * pid.err + pid.ki * index * pid.integral - + pid.kd * (pid.err - pid.err_last) * index1; - pid.err_last = pid.err; - - if (pid.ht_time <= 0) - pid.ht_time = 0; - else if (pid.ht_time > 30 * 200) - pid.ht_time = 30 * 200; - - return pid.ht_time; - -} - -/******************************************************************************* - Function:Heating_Time - Description:Calcuates the on time for the heating element - Input: (temp) current Tip Temp, (wk_temp) current ideal setpoint temp - Output: The ON time for the heater element - *******************************************************************************/ -u32 Heating_Time(s16 temp, s16 wk_temp) { - u32 heat_timecnt; - - pid.settemp = wk_temp; - if (wk_temp > temp) { - if (wk_temp - temp >= 18) - gHt_flag = 0; //���� - else - gHt_flag = 2; //���� - } else { - if (temp - wk_temp <= 18) - gHt_flag = 2; //���� - else - gHt_flag = 1; //���� - } - - heat_timecnt = Pid_Realize(temp); //Sub_data * 1000; - - return heat_timecnt; -} -/******************************************************************************* - Function:Status_Tran - Description: Handles the current status of the unit, and task selection - Basically this is called in main() repeatedly - Input:Void - Output:Void - *******************************************************************************/ -void Status_Tran(void) // -{ - static u16 init_waitingtime = 0; - static u8 back_prestatus = 0; - s16 heat_timecnt = 0, wk_temp; - u16 mma_active; - - switch (Get_CtrlStatus()) { - case IDLE: - switch (Get_gKey()) { //Read current switch positions - case KEY_A: //If V1 key is pressed - if (gIs_restartkey != 1) { //check we are not in a soft restart situation - if (Read_Vb(1) < 4) { //Read that the input voltage is acceptable?? - Set_CtrlStatus(SOLDERING_MODE); //Set to temperature controlled mode (Aka soldering mode) - init_waitingtime = 0; //Initialize the wait count to 0 - TEMPSHOW_TIMER= 0; //Initialize the timer to 0 - UI_TIMER= 0; - G6_TIMER= 0; - } - } - break; - case KEY_B: //check if V2 key is pressed - if(gIs_restartkey != 1) { //check this is not a soft restart situation - Set_CtrlStatus(THERMOMETER);//Change system to Thermometer mode instead (ie reading temp only, no drive) - UI_TIMER = 0; - Set_LongKeyFlag(1);//Set the long key pressed flag?? - } - break; - case KEY_CN|KEY_V3: //If A&B pressed at the same time, no action - break; - } - if(gIs_restartkey && (KD_TIMER == 0)) { //This is a soft restart situation instead - gIs_restartkey = 0;//reset the flag for soft restart - Set_gKey(NO_KEY);//reset keys pressed - } - if(Read_Vb(1) == 0) { //Invalid voltage, I think this means no input power detected - if(Get_UpdataFlag() == 1) Set_UpdataFlag(0); - Set_CtrlStatus(ALARM); - } - if(gPre_status != WAIT && gPre_status != IDLE) { //System has been left alone, turn off screen to stop burn in - G6_TIMER = device_info.idle_time; - Set_gKey(NO_KEY); - gPre_status = IDLE; - } - break; - case SOLDERING_MODE: //We are in soldering mode - switch(Get_gKey()) { //switch on the pressed key - case KEY_CN|KEY_A: - case KEY_CN|KEY_B://if either key long pressed - Set_HeatingTime(0);//turn off heater - Set_CtrlStatus(TEMP_SET);//Goto temperature set mode - HEATING_TIMER = 0;//reset heating timer - EFFECTIVE_KEY_TIMER = 500; - break; - case KEY_CN|KEY_V3://Both keys pressed - Set_HeatingTime(0);//Stop the heater - Set_LongKeyFlag(0);//Reset the long key press flag - Set_CtrlStatus(IDLE);//Change the system back to IDLE state (stop soldering) - gPre_status = SOLDERING_MODE;//Set previous status - gIs_restartkey = 1; - KD_TIMER = 50;// - break; - } - - if(Read_Vb(1) >= 4) { //Check input voltage is in the acceptable range - Set_HeatingTime(0);//Turn of heater as we are out of range - Set_LongKeyFlag(0);//reset key flag - Set_CtrlStatus(IDLE);//reset to IDLE state - gPre_status = SOLDERING_MODE;//set previous state - gIs_restartkey = 1; - KD_TIMER = 50;// - } - - wk_temp = device_info.t_work; //update setpoint temp from the struct - if(HEATING_TIMER == 0) { - gTemp_data = Get_Temp(wk_temp); - heat_timecnt = Heating_Time(gTemp_data,wk_temp); //Calculate the on time for the heating cycle - Set_HeatingTime(heat_timecnt);//set the on time for the heating cycle - HEATING_TIMER = HEATINGCYCLE; - } - - if(Get_HeatingTime() == 0) { //If calcuated heater time is 0 stop the timer ? - HEATING_TIMER = 0; - } - - /* - * The logic here is : - * If the device is moving then disarm the timer and mark it as needed a re-init - * else check if the timer needs init, if it does set it up and exit - * if the timer does not need init, then check if the timer has expired (its a count down) - * If the timer has expired goto wait state instead and shutdown iron - */ - mma_active = Get_MmaShift(); //check the accelerometer for movement - if(mma_active == 0) { //MMA_active = 0 ==> static ,MMA_active = 1 ==>move - if(init_waitingtime == 0) { //If the waiting countdown timer is not initialized - init_waitingtime = 1;//we initialize it and set this <- flag. - ENTER_WAIT_TIMER = device_info.wait_time; - } - if((init_waitingtime != 0) && (ENTER_WAIT_TIMER == 0)) { //if timeout has been initalized and enter_wait_timer has reached 0 - gHt_flag = 0;//reset heating flags - UI_TIMER = 0;//reset ui timers - Set_HeatingTime(0);//turn off the soldering iron - Set_gKey(0);//clear keys - G6_TIMER = device_info.idle_time;//set the device to idle timer move - Set_CtrlStatus(WAIT);//Set system mode to waiting for movement - } - } else { //The iron is moving - init_waitingtime = 0;//mark the waiting timer for needing reset if movement stops again - } - - if(Get_AlarmType() > NORMAL_TEMP) { // - if(Get_UpdataFlag() == 1) Set_UpdataFlag(0); - Set_CtrlStatus(ALARM);//Change to alarm state - } - break; - - case WAIT: - //This mode (WAIT) occures when the iron has been idling on a desk for too long (ie someone forgot it was left on) - //In this state we drop to a lower, safer temp and wait for movement or button push to wake up to operating temp again - wk_temp = device_info.t_standby; - if(device_info.t_standby > device_info.t_work) { - //Check if the set temp was greater than the idle temp, if it was we set the idle temp to the set temp - //This is done to avoid standby going to a higher temp - wk_temp = device_info.t_work; - } - //if the heating timer has expired, update the readings - if(HEATING_TIMER == 0) { - gTemp_data = Get_Temp(wk_temp); //read the tip temp - heat_timecnt = Heating_Time(gTemp_data,wk_temp);//calculate the new heating timer value from temps - Set_HeatingTime(heat_timecnt);//apply the new heating timer - HEATING_TIMER = 30;//set update rate for heating_timer - } - - if(Read_Vb(1) >= 4) { //If the input voltage is not valid - Set_HeatingTime(0);//turn off heater - Set_LongKeyFlag(0);//reset key press flag - Set_CtrlStatus(IDLE);//goto IDLE state - G6_TIMER = device_info.idle_time; - gPre_status = WAIT;//set previous state - gIs_restartkey = 1; - KD_TIMER = 50;// - } - - if(G6_TIMER == 0) { // - Set_HeatingTime(0); - Set_LongKeyFlag(0); - gIs_restartkey = 1; - KD_TIMER = 200;// - gPre_status = WAIT; - Set_CtrlStatus(IDLE); - } - - //If movement has occurred OR a key has been pressed -> Wakeup back to soldering - mma_active = Get_MmaShift();//read accelerometer - if(mma_active == 1 || Get_gKey() != 0) { - UI_TIMER = 0; //reset the un-needed timers - G6_TIMER = 0; - init_waitingtime = 0; - Set_CtrlStatus(SOLDERING_MODE);//Go back to soldering iron mode - } - - if(Get_AlarmType() > NORMAL_TEMP) { //If an alarm has occurred?? - if(Get_UpdataFlag() == 1) Set_UpdataFlag(0); - Set_CtrlStatus(ALARM);//goto alarm error state - } - break; - - case TEMP_SET: //We are in the setting soldering iron temp mode - if(EFFECTIVE_KEY_TIMER == 0) { - gCalib_flag = 1; - - gCalib_flag = 0; - Set_CtrlStatus(SOLDERING_MODE); //return to soldering mode - TEMPSHOW_TIMER = 0;//turn off the timer - } - break; - - case THERMOMETER: //we are measuring the tip temp without applying any power - if(KD_TIMER > 0) { - Set_gKey(NO_KEY); - break; - } - - switch(Get_gKey()) { - case KEY_CN|KEY_A: - case KEY_CN|KEY_B: - back_prestatus = 1; - break; - case KEY_CN|KEY_V3: - Zero_Calibration(); //Calibrate the temperature (i think??) - if(Get_CalFlag() == 1) { - } - KD_TIMER = 200; //20150717 �޸� - break; - default: - break; - } - if(back_prestatus == 1) { //we are exiting - back_prestatus = 0;//clear flag - Set_HeatingTime(0);//turn off heater? (not sure why this is done again) - Set_CtrlStatus(IDLE);//Goto IDLE state - gPre_status = THERMOMETER;//set previous state - gIs_restartkey = 1;//signal soft restart required as we may have done a calibration - Set_LongKeyFlag(0);//reset long key hold flag - KD_TIMER = 50;// - } - break; - case ALARM: //An error has occured so we are in alarm state - switch(Get_AlarmType()) { - case HIGH_TEMP: //over temp condition - case SEN_ERR://sensor reading error - wk_temp = device_info.t_work; - gTemp_data = Get_Temp(wk_temp); - if(Get_AlarmType() == NORMAL_TEMP) { - Set_CtrlStatus(SOLDERING_MODE); - Set_UpdataFlag(0); - } - break; - case HIGH_VOLTAGE: //over voltage - case LOW_VOLTAGE://under voltage - if(Read_Vb(1) >= 1 && Read_Vb(1) <= 3) { - Set_HeatingTime(0); //turn off heater - Set_LongKeyFlag(0);//reset key flag - gIs_restartkey = 1; - UI_TIMER = 2;// 2�� - gPre_status = THERMOMETER; - Set_CtrlStatus(IDLE); - } - break; - } - break; - default: - break; - } -} - -/******************************** END OF FILE *********************************/ diff --git a/workspace/ts100/src/Hardware.c b/workspace/ts100/src/Hardware.c deleted file mode 100644 index 9c203d13..00000000 --- a/workspace/ts100/src/Hardware.c +++ /dev/null @@ -1,225 +0,0 @@ -/********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ********************** - File Name : CTRL.c - Version : S100 APP Ver 2.11 - Description: - Author : Celery - Data: 2015/07/07 - History: - 2015/07/07 ͳһ������ - 2015/07/20 �Ӵ��¶ȱ������� - *******************************************************************************/ -#include -#include -#include "APP_Version.h" -#include "Hardware.h" -#include "CTRL.h" -#include "Bios.h" -#include "UI.h" -/******************************************************************************/ -#define CAL_AD 250 -const u32 gVol[] = { 3900, 2760, 1720, 584 }; -const u16 gRate[] = { 300, 150, 90, 40 }; -s32 gZerop_ad = 239; -u32 gTurn_offv = 100; -u8 gCalib_flag = 0; -vu16 gMeas_cnt = 0;/* Measure*/ -u32 gKey_in; -u8 gLongkey_flag = 0; -u8 gAlarm_type = 1; -/******************************************************************************* - - *******************************************************************************/ -u32 Get_CalFlag(void) { - return gCalib_flag; -} - -/******************************************************************************* - - *******************************************************************************/ -u32 Get_gKey(void) { - return gKey_in; -} -/******************************************************************************* - - *******************************************************************************/ -void Set_gKey(u32 key) { - gKey_in = key; -} -/******************************************************************************* - - *******************************************************************************/ -void Set_LongKeyFlag(u32 flag) { - gLongkey_flag = flag; -} -/******************************************************************************* - - *******************************************************************************/ -u8 Get_AlarmType(void) { - return gAlarm_type; -} -/******************************************************************************* - - *******************************************************************************/ -void Set_AlarmType(u8 type) { - gAlarm_type = type; -} -/******************************************************************************* - Function: Read_Vb - Description:Reads the input voltage and compares it to the thresholds?? - Input:Selects which threshold we are comparing to - Output:Returns a key for if the voltage is in spec (I think) - *******************************************************************************/ -int Read_Vb(u8 flag) { - u32 tmp, i, sum = 0; - - for (i = 0; i < 10; i++) { - tmp = ADC_GetConversionValue(ADC2); - sum += tmp; - } - tmp = sum / 10; - if (tmp >= (gVol[0] + gVol[0] / 100)) { - gAlarm_type = HIGH_VOLTAGE; - return H_ALARM; //����3500 - } - tmp = (tmp * 10 / 144); //��ѹvb = 3.3 * 85 *ad / 40950 -> In X10 voltage - - for (i = 0; i < 4; i++) { - if (i == 2) { - if (flag == 0) { - if (tmp >= gRate[i]) - break; - } else { - if (tmp >= gTurn_offv) - break; - } - } else { - if (tmp >= gRate[i]) - break; - } - } - return (i + 1); -} -/******************************************************************************* - - *******************************************************************************/ -void Scan_Key(void) { - static u32 p_cnt = 0, key_statuslast = 0; - u32 key_state = 0; - - if ((~GPIOA->IDR) & 0x0200) - key_state |= KEY_A; //KEY_V1 - if ((~GPIOA->IDR) & 0x0040) - key_state |= KEY_B; //KEY_V2 - - if (key_state == 0) - return; - - if (gLongkey_flag == 1) { //LongKey_flag -> we are looking for a long press or a quick press - if (key_statuslast == key_state) { - p_cnt++; - if (p_cnt > 21) - Set_gKey(KEY_CN | key_state); - } else { - p_cnt = 0; - key_statuslast = key_state; - Set_gKey(key_state); - } - } else { - p_cnt = 0; - key_statuslast = key_state; - Set_gKey(key_state); - } - -} - -/******************************************************************************* - Function: - Description: Reads the Zero Temp.. And does something.. - *******************************************************************************/ -void Zero_Calibration(void) { - u32 zerop; - int cool_tmp; - - zerop = Get_AvgAd(); //get the current - cool_tmp = Get_SensorTmp(); //get the temp of the onboard sensor - - if (zerop >= 400) { //If the tip is too hot abort - gCalib_flag = 2; - } else { - if (cool_tmp < 300) { //If cool temp is cool enough continue - gZerop_ad = zerop; //store the zero point - gCalib_flag = 1; - } else { //abort if too warm - gCalib_flag = 2; - } - } -} -/******************************************************************************* - - *******************************************************************************/ -s16 Get_Temp(s16 wk_temp) { - int ad_value, cool_tmp, compensation = 0; - static u16 cnt = 0, h_cnt = 0; - - ad_value = Get_AvgAd(); - cool_tmp = Get_SensorTmp(); - - if (ad_value == 4095) - h_cnt++; - else { - h_cnt = 0; - if (ad_value > 3800 && ad_value < 4095) - cnt++; - else - cnt = 0; - } - if (h_cnt >= 60 && cnt == 0) - gAlarm_type = SEN_ERR; //Sensor error -- too many invalid readings - if (h_cnt == 0 && cnt >= 10) - gAlarm_type = HIGH_TEMP; //Stuck at a really high temp -> Has mosfet failed - if (h_cnt < 60 && cnt < 10) - gAlarm_type = NORMAL_TEMP; //No errors so far - - compensation = 80 + 150 * (wk_temp - 1000) / 3000; - if (wk_temp == 1000) - compensation -= 10; - - if (wk_temp != 0) { - if (ad_value > (compensation + gZerop_ad)) - ad_value -= compensation; - } - if (cool_tmp > 400) - cool_tmp = 400; //cap cool temp at 40C - - return (ad_value * 1000 + 806 * cool_tmp - gZerop_ad * 1000) / 806; -} - -/******************************************************************************* - Function:Start_Watchdog - Description: Starts the system watchdog timer - *******************************************************************************/ -u32 Start_Watchdog(u32 ms) { - IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable); - - /* IWDG counter clock: 40KHz(LSI) / 32 = 1.25 KHz (min:0.8ms -- max:3276.8ms */ - IWDG_SetPrescaler(IWDG_Prescaler_32); - - /* Set counter reload value to XXms */ - IWDG_SetReload(ms * 10 / 8); - - /* Reload IWDG counter */ - IWDG_ReloadCounter(); - - /* Enable IWDG (the LSI oscillator will be enabled by hardware) */ - IWDG_Enable(); - return 1; -} -/******************************************************************************* - Function:Clear_Watchdog - Description:Resets the watchdog timer - *******************************************************************************/ -void Clear_Watchdog(void) { - IWDG_ReloadCounter(); - -} -/******************************** END OF FILE *********************************/ diff --git a/workspace/ts100/src/Interrupt.c b/workspace/ts100/src/Interrupt.c index eda231ac..42e5e723 100644 --- a/workspace/ts100/src/Interrupt.c +++ b/workspace/ts100/src/Interrupt.c @@ -7,17 +7,16 @@ #include "I2C.h" volatile uint32_t system_Ticks; -void delayMs(uint32_t ticks) -{ - uint32_t endtime = ticks+millis(); - while(millis() #include #include "APP_Version.h" - +#include "Modes.h" #include "Bios.h" #include "I2C.h" #include "MMA8652FC.h" -#include "UI.h" + #include "Oled.h" -#include "CTRL.h" -#include "Hardware.h" #include "Interrupt.h" int main(void) { RCC_Config(); //setup system clock - //NVIC_Config(0x4000); + //NVIC_Config(0x4000);//this shifts the NVIC table to be offset NVIC_Config(0x0000); - Init_Timer2(); //init the timers - GPIO_Config(); //setup all the GPIO pins + Init_EXTI(); + //Init_Timer2(); //init the timers + Init_Timer3(); I2C_Configuration(); //init the i2c bus Adc_Init(); //init adc and dma StartUp_Accelerated(); //start the accelerometer - System_Init(); //load known safe values Init_Oled(); //init the OLED display Clear_Screen(); //clear the display buffer to black - Init_Gtime(); //init the count down timers - APP_Init(); //pick operating mode via input voltage - - Pid_Init(); //init the pid to starting values - Set_gKey(NO_KEY); //reset keys to all off + systemSettings.SleepTemp = 200; + systemSettings.SleepTime = 1; + systemSettings.SolderingTemp = 320; + readIronTemp(239);//load the default calibration value //OLED_DrawString("TEST012",7); - for (;;) { + /*for (;;) { - OLED_DrawTwoNumber((millis() / 100) % 100, (millis()/100)%80); - } - - Start_Watchdog(3000); //start the system watchdog as 3 seconds + OLED_DrawTwoNumber((millis() / 100) % 100, (millis() / 100) % 80); + }*/ + //Start_Watchdog(3000); //start the system watchdog as 3 seconds while (1) { - Clear_Watchdog(); //reset the Watchdog - if (Get_CtrlStatus() != USB_POWER && LEAVE_WAIT_TIMER== 0) { - Check_Accelerated(); //update readings from the accelerometer - LEAVE_WAIT_TIMER = 50;//reset timer so we dont poll accelerometer for another 500ms - } - OLed_Display(); //Draw in the Oled display for this mode - Status_Tran(); //Handle user input and mode changing + // Clear_Watchdog(); //reset the Watchdog + ProcessUI(); + DrawUI(); } } /******************************** END OF FILE *********************************/ diff --git a/workspace/ts100/src/Modes.c b/workspace/ts100/src/Modes.c index d52a10ed..e1486f81 100644 --- a/workspace/ts100/src/Modes.c +++ b/workspace/ts100/src/Modes.c @@ -7,18 +7,18 @@ #include "Modes.h" //This does the required processing and state changes void ProcessUI() { - uint8_t Buttons = Get_gKey(); //read the buttons status + uint8_t Buttons = getButtons(); //read the buttons status - if (millis() - LastButtonPushTime < 50) + if (millis() - getLastButtonPress() < 100) Buttons = 0; //rough prevention for debouncing and allocates settling time - + //OLED_DrawThreeNumber(Buttons, 0); switch (operatingMode) { case STARTUP: - if (Buttons & KEY_A) { + if (Buttons & BUT_A) { //A key pressed so we are moving to soldering mode operatingMode = SOLDERING; - } else if (Buttons & KEY_B) { + } else if (Buttons & BUT_B) { //B Button was pressed so we are moving to the Settings menu operatingMode = SETTINGS; } @@ -26,42 +26,41 @@ void ProcessUI() { break; case SOLDERING: //We need to check the buttons if we need to jump out - if (Buttons & KEY_A) { + if (Buttons & BUT_A) { //A key pressed so we are moving to temp set operatingMode = TEMP_ADJ; - } else if (Buttons & KEY_B) { + } else if (Buttons & BUT_B) { //B Button was pressed so we are moving back to idle operatingMode = STARTUP; } else { //We need to check the timer for movement in case we need to goto idle - if (millis() - LastMovementTime > (systemSettings.SleepTime * 60000) - && millis() - LastMovementTime - > (systemSettings.SleepTime * 60000)) { - operatingMode = SLEEP; //Goto Sleep Mode - return; - } + if (systemSettings.movementEnabled) + if (millis() - getLastMovement() + > (systemSettings.SleepTime * 60000)) { + operatingMode = SLEEP; //Goto Sleep Mode + return; + } //If no buttons pushed we need to read the current temperatures // and then setup the drive signal time for the iron - } break; case TEMP_ADJ: - if (Buttons & KEY_A) { + if (Buttons & BUT_A) { //A key pressed so we are moving down in temp - } else if (Buttons & KEY_B) { + } else if (Buttons & BUT_B) { //B key pressed so we are moving up in temp } else { //we check the timeout for how long the buttons have not been pushed //if idle for > 3 seconds then we return to soldering - if (millis() - LastButtonPushTime > 3000) + if (millis() - getLastButtonPress() > 3000) operatingMode = SOLDERING; } break; case SETTINGS: //Settings is the mode with the most logic //Here we are in the menu so we need to increment through the sub menus / increase the value - if (Buttons & KEY_A) { + if (Buttons & BUT_A) { //A key iterates through the menu if (settingsPage == 2) { //Roll off the end @@ -70,7 +69,7 @@ void ProcessUI() { //TODO Save settings } else ++settingsPage; //move to the next option - } else if (Buttons & KEY_B) { + } else if (Buttons & BUT_B) { //B changes the value selected switch (settingsPage) { case UVLO: @@ -97,6 +96,17 @@ void ProcessUI() { break; case SLEEP: //The iron is sleeping at a lower temperature due to lack of movement + if (Buttons & BUT_A) { + //A Button was pressed so we are moving back to soldering + operatingMode = SOLDERING; + } else if (Buttons & BUT_B) { + //B Button was pressed so we are moving back to soldering + operatingMode = SOLDERING; + } else if (systemSettings.movementEnabled) + if (millis() - getLastMovement() > 100) { + operatingMode = SOLDERING; //Goto active mode again + return; + } break; default: @@ -109,30 +119,35 @@ void DrawUI() { case STARTUP: //We are chilling in the idle mode //Check if movement in the last 5 minutes , if not sleep OLED - if (millis() - LastMovementTime > (5 * 60 * 1000)) { + if (millis() - getLastMovement() > (5 * 60 * 1000)) { //OLED off Oled_DisplayOff(); } else { Oled_DisplayOn(); - OLED_DrawString("IDLE ", 0); //write the word IDLE + OLED_DrawString("IDLE ", 6); //write the word IDLE } break; case SOLDERING: //The user is soldering //We draw in the current system temp and an indicator if the iron is heating or not + //First lets draw the current tip temp + //OLED_DrawString("SOLD ", 6); + OLED_DrawThreeNumber(readIronTemp(0), 0); break; case TEMP_ADJ: //We are prompting the user to change the temp so we draw the current setpoint temp //With the nifty arrows + OLED_DrawString("TEMP ", 6); break; case SETTINGS: //We are prompting the user the setting name + OLED_DrawString("SETT ", 6); break; case SLEEP: //The iron is in sleep temp mode //Draw in temp and sleep - + OLED_DrawString("SLEP ", 6); break; default: break; diff --git a/workspace/ts100/src/Oled.c b/workspace/ts100/src/Oled.c index f476ea45..f575aa15 100644 --- a/workspace/ts100/src/Oled.c +++ b/workspace/ts100/src/Oled.c @@ -14,25 +14,15 @@ #include "Oled.h" #include "Bios.h" #include "I2C.h" -#include "Hardware.h" -#include "UI.h" + #include "Font.h" -//Setup params depending on oled model -#ifdef SSD1316 -u8 gOled_param[50] = {0x80,0xAE,0x80,0x00,0x80,0x10,0x80,0x40,0x80,0xB0,0x80, - 0x81,0x80,0xFF,0x80,0xA0,0x80,0xA6,0x80,0xA8,0x80,0x1F, - 0x80,0xC8,0x80,0xD3,0x80,0x00,0x80,0xD5,0x80,0x80,0x80, - 0xD9,0x80,0x22,0x80,0xDA,0x80,0x12,0x80,0xDB,0x80,0x40, - 0x80,0x8D,0x80,0x14,0x80,0xAF, -}; -#else u8 gOled_param[46] = { 0x80, 0xAE, 0x80, 0xD5, 0x80, 0x52, 0x80, 0xA8, 0x80, 0x0f, 0x80, 0xC0, 0x80, 0xD3, 0x80, 0x00, 0x80, 0x40, 0x80, 0xA0, 0x80, 0x8D, 0x80, 0x14, 0x80, 0xDA, 0x80, 0x02, 0x80, 0x81, 0x80, 0x33, 0x80, 0xD9, 0x80, 0xF1, 0x80, 0xDB, 0x80, 0x30, 0x80, 0xA4, 0x80, 0XA6, 0x80, 0xAF }; -#endif + /******************************************************************************* *******************************************************************************/ @@ -152,16 +142,10 @@ void Init_Oled(void) { u8 param_len; OLED_RST(); - Delay_Ms(2); //reset the oled + delayMs(2); //reset the oled OLED_ACT(); - Delay_Ms(2); - -#ifdef SSD1316 - param_len = 50; -#else + delayMs(2); param_len = 46; -#endif - I2C_PageWrite((u8 *) gOled_param, param_len, DEVICEADDR_OLED); } @@ -187,11 +171,16 @@ void OLED_DrawChar(char c, uint8_t x) { u8* ptr; ptr = (u8*) FONT; if (c >= 'A' && c <= 'Z') { - ptr += (c - 'A' + 10) * (14 * 2); + ptr += (c - 'A' + 10) * (14 * 2); //alpha is ofset 10 chars into the array } else if (c >= '0' && c <= '9') ptr += (c - '0') * (14 * 2); else if (c < 10) ptr += (c) * (14 * 2); + else if (c == ' ') { + //blank on space bar + ptr += (36) * (14 * 2); + } + Oled_DrawArea(x, 0, 14, 16, (u8*) ptr); } /* @@ -200,7 +189,20 @@ void OLED_DrawChar(char c, uint8_t x) { void OLED_DrawTwoNumber(uint8_t in, uint8_t x) { OLED_DrawChar(in / 10, x); OLED_DrawChar(in % 10, x + 14); - } +void OLED_DrawThreeNumber(uint16_t in, uint8_t x) { + + OLED_DrawChar((in / 100)%10, x); + OLED_DrawChar((in / 10)%10, x + 14); + OLED_DrawChar(in % 10, x + 28); +} +void OLED_DrawFourNumber(uint16_t in, uint8_t x) { + + OLED_DrawChar((in / 1000)%10, x); + OLED_DrawChar((in / 100)%10, x+14); + OLED_DrawChar((in / 10)%10, x + 28); + OLED_DrawChar(in % 10, x + 32); +} + /******************************** END OF FILE *********************************/ diff --git a/workspace/ts100/src/UI.c b/workspace/ts100/src/UI.c deleted file mode 100644 index 6c21b399..00000000 --- a/workspace/ts100/src/UI.c +++ /dev/null @@ -1,1025 +0,0 @@ -/********************* (C) COPYRIGHT 2015 e-Design Co.,Ltd. ********************** - File Name : UI.c - Version : S100 APP Ver 2.11 - Description: - Author : Celery - Data: 2015/08/03 - History: - 2015/07/07 ͳһ������ - 2015/08/03 �Ż��ƶ��ж� - *******************************************************************************/ -#include -#include -#include "APP_Version.h" -#include "UI.h" -#include "CTRL.h" -#include "WordLib.h" -#include "Bios.h" -#include "Oled.h" -#include "Hardware.h" - -#include "MMA8652FC.h" -/******************************************************************************/ -u8 gTemp_array[16 * 16 + 16]; -u8 gTemperatureshowflag = 0; -u8 gUp_flag = 0, gDown_flag = 0, gLevel_flag = 0, gTempset_showctrl = 0; -u16 gTemp_array_u16[208]; -u16 gSet_table[2] = { 4000, 1000 }; -u32 gCont = 0; -/******************************************************************************/ - -/******************************************************************************* - Function: - Description: - *******************************************************************************/ -u32 Get_UpdataFlag(void) { - return gCont; -} -/******************************************************************************* - Function: - Description: - *******************************************************************************/ -void Set_UpdataFlag(u32 cont) { - gCont = cont; -} -/******************************************************************************* - Function: - Description: - *******************************************************************************/ -void Set_TemperatureShowFlag(u8 flag) { - gTemperatureshowflag = flag; -} -/******************************************************************************* - Function: - Description:־ - *******************************************************************************/ -u8 Get_TemperatureShowFlag(void) { - return gTemperatureshowflag; -} -/******************************************************************************* - Function: - Description: Converts F to C or C to F. - Input: flag = if flag==0 converts C to F - *******************************************************************************/ -s16 TemperatureShow_Change(u8 flag, s16 tmp) { - if (flag == 0) { - return (320 + tmp * 9 / 5); - } else { - return (5 * tmp - 1600) / 9; - } -} -/******************************************************************************* - Function:APP_Init - Description:Init the operating mode by looking at input voltage to pick USB or normal - *******************************************************************************/ -void APP_Init(void) { - int rev; - - HEATING_TIMER= 0; - UI_TIMER= 0; - - rev = Read_Vb(0); //Read input voltage - if (rev == 0) //no input volatage == error state - Set_CtrlStatus(ALARM); - else if (rev >= 4) { //We are USB powered (5V approx at input) - Set_LongKeyFlag(1); - Set_CtrlStatus(USB_POWER); - } else { //Normal mode > ~9V at input - Set_CtrlStatus(IDLE); - G6_TIMER= device_info.idle_time; - } - -} - -/******************************************************************************* - Function: - Description: - *******************************************************************************/ -void Display_Temp(u8 x, s16 temp) { - char Str[8]; - - memset(Str, 0x0, 6); - sprintf(Str, "%d", temp); - - if (gTemperatureshowflag == 0) { - if (temp > 99) - Str[3] = 'C'; - else if (temp > 9) { - Str[2] = 'C'; - Str[3] = ' '; - } else if (temp < 0) { - if (temp + 9 >= 0) { - Str[2] = 'C'; - Str[3] = ' '; - } else { - Str[3] = 'C'; - } - } else { - Str[1] = 'C'; - Str[2] = ' '; - Str[3] = ' '; - } - } else { - if (temp > 99) - Str[3] = 'E'; - else if (temp > 9) { - Str[2] = 'E'; - Str[3] = ' '; - } else if (temp < 0) { - if (temp + 9 >= 0) { - Str[2] = 'E'; - Str[3] = ' '; - } else { - Str[3] = 'E'; - } - } else { - Str[1] = 'E'; - Str[2] = ' '; - Str[3] = ' '; - } - } - Display_Str(x, Str); - TEMPSHOW_TIMER= 20; //200ms -} -/******************************************************************************* - Function: - Description: Shows the press the button to start screen - *******************************************************************************/ -void Show_Notice(void) { - int j, k; - static u8* ptr0; - static u8 posi = 0, i = 0; -//This draws the soldering iron logo to prompt the user to press the button to wake - if (i == 0) { //1 Button up - ptr0 = Oled_DrawArea(0, 0, 96, 16, (u8*) Maplib); - } else if (i == 1) { //2 Button down - ptr0 = Oled_DrawArea(0, 0, 96, 16, ptr0); - } else if (i == 2) { //3 Button up - ptr0 = Oled_DrawArea(0, 0, 96, 16, (u8*) Maplib); - } else if (i == 3) { //4 Draw sliding text in - for (j = 0; j < 6; j++) { - k = 84; - while (k >= posi) { - ptr0 = (u8*) Maplib1 + j * 28; - Clean_Char(k + 7, 14); - ptr0 = Oled_DrawArea(k, 0, 14, 16, ptr0); - k -= 7; - Delay_Ms(10); - } - posi += 14; - } - posi = 0; - } - i++; - if (i == 4) - i = 0; -} - -/******************************************************************************* - Function: - Description: Draws the word CONFIG to the screen - *******************************************************************************/ -void Show_Config(void) { - u8* ptr; - u8 j; - - ptr = (u8*) Config; - for (j = 0; j < 6; j++) { - ptr = Oled_DrawArea(j * 16, 0, 16, 16, ptr); - } -} - -/******************************************************************************* - Function: - Description: - *******************************************************************************/ -void Show_TempDown(s16 temp, s16 dst_temp) { - static u8 guide_ui = 0; - char str[8]; - - memset(str, 0x0, 6); - sprintf(str, "%d", temp); - if (gTemperatureshowflag == 0) { - if (temp > 99) - str[3] = 'C'; - else { - str[2] = 'C'; - str[3] = ' '; - } - } else { - if (temp > 99) - str[3] = 'E'; - else { - str[2] = 'E'; - str[3] = ' '; - } - } - - Display_Str10(1, str); - - Oled_DrawArea(41, 0, 16, 16, (u8*) (Guide + (guide_ui++) * 32)); - - if (guide_ui == 3) - guide_ui = 0; - - memset(str, 0x0, 6); - sprintf(str, "%d", dst_temp); - if (gTemperatureshowflag == 0) { - if (temp > 99) - str[3] = 'C'; - else { - str[2] = 'C'; - str[3] = ' '; - } - } else { - if (temp > 99) - str[3] = 'E'; - else { - str[2] = 'E'; - str[3] = ' '; - } - } - - Display_Str10(56, str); -} -/******************************************************************************* - Function: - Description: - *******************************************************************************/ -void Show_Cal(u8 flag) { - u8 i; - u8* ptr = 0; - - if (flag == 1) - ptr = (u8*) Cal_Done; - else if (flag == 2) - ptr = (u8*) Cal_UnDone; - - ptr = Oled_DrawArea(0, 0, 16, 16, (u8*) ptr); - - for (i = 1; i < 6; i++) - ptr = Oled_DrawArea(16 * i, 0, 16, 16, (u8*) ptr); - Delay_Ms(1000); - Clear_Watchdog(); -} -/******************************************************************************* - Function: - Description: - *******************************************************************************/ -void Show_Warning(void) { - u8 i; - u8* ptr = 0; - static u8 flag = 0; - - switch (Get_AlarmType()) { - case HIGH_TEMP: - ptr = (u8*) Warning; - break; - case SEN_ERR: - ptr = (u8*) SenErr; - break; - case HIGH_VOLTAGE: - ptr = (u8*) HighVt; - break; - case LOW_VOLTAGE: - ptr = (u8*) LowVot; - break; - } - - Oled_DrawArea(0, 0, 16, 16, (u8*) Warning + 20 * 7); - if (flag == 0) { - for (i = 2; i < 9; i++) - Oled_DrawArea(10 * i, 0, 10, 16, (u8*) ptr + (i - 2) * 20); - flag = 1; - } else { - Clean_Char(16, 80); - flag = 0; - } -} - -/***************************************************************** - Function: Show_Triangle - Description:Draws in a triangle - Input:(empty_trgl) - - empty_trgl: 0,1,2 ���Ӵ�,��Ӵ�,�ҼӴ� - fill_trgl: 0,1,2 ��ʵ��,��ʵ��,��ʵ�� - *******************************************************************/ -void Show_Triangle(u8 empty_trgl, u8 fill_trgl) { - u8* ptr; - ptr = (u8*) Triangle; //Get pointer to the pre-computed triangle array - if ((empty_trgl == 0) && (fill_trgl == 0)) { - ptr = Oled_DrawArea(0, 0, 16, 16, (u8*) ptr); - ptr = Oled_DrawArea(5 * 16, 0, 16, 16, (u8*) ptr); - } else if ((empty_trgl != 0) && (fill_trgl == 0)) { - if (empty_trgl == 1) { - ptr += 32; - Oled_DrawArea(5 * 16, 0, 16, 16, (u8*) ptr); - ptr += 32; - Oled_DrawArea(0, 0, 16, 16, (u8*) ptr); - } else if (empty_trgl == 2) { - Oled_DrawArea(0, 0, 16, 16, (u8*) ptr); - ptr += 32 * 3; - Oled_DrawArea(5 * 16, 0, 16, 16, (u8*) ptr); - } - } else if ((empty_trgl == 0) && (fill_trgl != 0)) { - if (fill_trgl == 1) { - ptr += 32; - Oled_DrawArea(5 * 16, 0, 16, 16, (u8*) ptr); - ptr += 32 * 3; - Oled_DrawArea(0, 0, 16, 16, (u8*) ptr); - } else if (fill_trgl == 2) { - Oled_DrawArea(0, 0, 16, 16, (u8*) ptr); - ptr += 32 * 5; - Oled_DrawArea(5 * 16, 0, 16, 16, (u8*) ptr); - } - } -} -/******************************************************************************* - ������: Shift_Char - ��������:�ַ����������ƶ���ָ��λ�� - �������:ptr �ƶ����ַ� pos �ƶ�����ָ��λ�� - ���ز���:NULL - *******************************************************************************/ -void Shift_Char(u8* ptr, u8 pos) { - int k; - u8* ptr0; - - k = 80; - pos = pos * 16; //λ��* �ַ�= �ַ�����λ�� - while (k >= pos) { - ptr0 = (u8*) ptr; - Clean_Char(k + 16, 16); - ptr0 = Oled_DrawArea(k, 0, 16, 16, (u8*) ptr0); - k -= 16; - Delay_Ms(25); - } -} - -/******************************************************************************* - Function:Show_Set - Description: Show the setpoint temp on the Oled - *******************************************************************************/ -void Show_Set(void) { - u8 m, k; - s16 num_temp; - - if (Get_TemperatureShowFlag() == 1) { - num_temp = TemperatureShow_Change(0, device_info.t_work); - } else { - num_temp = device_info.t_work; - } - - Shift_Char((u8*) Triangle + 0 * 32, 0); - m = num_temp / 1000; //�� - Shift_Char((u8*) wordlib + m * 32, 1); - k = (num_temp - m * 1000) / 100; //ʮ - Shift_Char((u8*) wordlib + k * 32, 2); - m = (num_temp - m * 1000 - k * 100) / 10; - Shift_Char((u8*) wordlib + m * 32, 3); - Shift_Char((u8*) wordlib + 13 * 32, 4); - Shift_Char((u8*) Triangle + 1 * 32, 5); -} -/******************************************************************************* - - *******************************************************************************/ -void Show_OrderChar(u8* ptr, u8 num, u8 width) { - static u8 i = 1, j = 0, k = 0, m = 10; - - if (gLevel_flag == 0) { //ǰһ״̬���Ǻ��� - i = 1; - j = 0; - m = 8; - gUp_flag = 0; - gDown_flag = 0; - gLevel_flag = 1; - } - - if (i == 0) { - for (k = 0; k <= m; k++) { - gTemp_array[k] = *(ptr + 52 + j + k - 1); - gTemp_array[k + width] = *(ptr + 52 + width + k + j - 1); - } - m++; - j--; - if (m == 11) { - m--; - j = 0; - i = 1; - return; - } - } - - if (j == 0) { - for (k = 1; k < m; k++) { - gTemp_array[k + i] = *(ptr + 52 + j + k - 1); - gTemp_array[k + i + width] = *(ptr + 52 + width + k + j - 1); - } - m--; - i++; - if (m == 0) { - m++; - j = 9; - i = 0; - } - } -} - -/******************************************************************************* - Function:Reverse_Bin8 - Description:Reverses the bit order of a uint8_t - Input:Value to reverse - Output:Reversed Value - *******************************************************************************/ -u8 Reverse_Bin8(u8 data) { - u8 i, cache, result = 0; - - for (i = 0; i < 8; i++) { - cache = data & (1 << i); - if (i < 4) { - cache <<= 7 - 2 * i; - } else { - cache >>= 2 * i - 7; - } - result += cache; - } - return result; -} -/******************************************************************************* - - *******************************************************************************/ -void Show_ReverseChar(u8* ptr, u8 num, u8 width, u8 direction) { - static u32 j = 0, m = 0, po_j[3] = { 0, 0, 0 }, po_m[3] = { 0, 0, 16 }; - u32 i, k; - - if (direction == 0) { //up - if (gUp_flag == 0) { // - j = 0; - m = 0; - gUp_flag = 1; - gDown_flag = 0; - gLevel_flag = 0; - } else { - j = po_j[0]; - m = po_m[0]; - } - } else if (direction == 1) { - if (gDown_flag == 0) { // - j = 0; - m = 0; - gUp_flag = 0; - gDown_flag = 1; - gLevel_flag = 0; - } else { - j = po_j[1]; - m = po_m[1]; - } - } else { - j = po_j[2]; - m = po_m[2]; - } - for (i = 0; i < width * 2 * num; i++) - gTemp_array[i] = Reverse_Bin8(*(ptr + i)); // - - for (k = 0; k < width * 2 * num; k += width * 2) - for (i = 0; i < width; i++) { - gTemp_array_u16[i + k] = ((gTemp_array[i + k] & 0x00FF) << 8) - | gTemp_array[i + k + width]; // - if (direction == 1) { - if (j == 0) - gTemp_array_u16[i + k] <<= m; // - else - gTemp_array_u16[i + k] >>= j; // - } else { //�� - if (m == 0) - gTemp_array_u16[i + k] <<= j; // - else - gTemp_array_u16[i + k] >>= m; // - } - gTemp_array[i + k] = (gTemp_array_u16[i + k] & 0xFF00) >> 8; - gTemp_array[i + k + width] = gTemp_array_u16[i + k] & 0x00FF; - } - - for (i = 0; i < width * 2 * num; i++) - gTemp_array[i] = Reverse_Bin8(gTemp_array[i]); // - - if (m == 0 && j == 16) { - j = 0; - m = 16; - } - if (m == 0) - j++; - else - m--; - - if (direction == 0) { //up - po_j[0] = j; - po_m[0] = m; - } else if (direction == 1) { - po_j[1] = j; - po_m[1] = m; - } else { - po_j[2] = j; - po_m[2] = m; - } -} - -/******************************************************************************* - Show_TempReverse - word_num: - word_width: - direction : ���� (0 up, 1 down) - *******************************************************************************/ -u8 Show_TempReverse(u8 num, u8 width, u8 direction) { - static int i, j = 0, m = 16, k; - u8 g, s, b; - u8* ptr; - s16 num_temp; - - if (Get_TemperatureShowFlag() == 1) { - num_temp = TemperatureShow_Change(0, device_info.t_work); - } else { - num_temp = device_info.t_work; - } - - num_temp = num_temp / 10; - b = num_temp / 100; - s = (num_temp - b * 100) / 10; - g = (num_temp - b * 100 - s * 10); - - if (gTempset_showctrl == 1) { - j = 1; - m = 0; - gTempset_showctrl = 0; - } else if (gTempset_showctrl == 2) { - j = 0; - m = 16; - gTempset_showctrl = 0; - } - for (i = 0; i < width * 2; i++) { - gTemp_array[0 * 32 + i] = Reverse_Bin8(*(wordlib + b * 32 + i)); - gTemp_array[1 * 32 + i] = Reverse_Bin8(*(wordlib + s * 32 + i)); - gTemp_array[2 * 32 + i] = Reverse_Bin8(*(wordlib + g * 32 + i)); - if (Get_TemperatureShowFlag() == 1) { - gTemp_array[3 * 32 + i] = Reverse_Bin8(*(wordlib + 15 * 32 + i)); - } else { - gTemp_array[3 * 32 + i] = Reverse_Bin8(*(wordlib + 13 * 32 + i)); - } - } - - for (k = (3 - num) * width * 2; k < width * 2 * 3; k += width * 2) - for (i = 0; i < width; i++) { - gTemp_array_u16[i + k] = ((gTemp_array[i + k] & 0x00FF) << 8) - | gTemp_array[i + k + width]; - if (direction == 0) { - if (m == 0) - gTemp_array_u16[i + k] <<= j; - else - gTemp_array_u16[i + k] >>= m; - } else { - if (j == 0) - gTemp_array_u16[i + k] <<= m; - else - gTemp_array_u16[i + k] >>= j; - } - gTemp_array[i + k] = (gTemp_array_u16[i + k] & 0xFF00) >> 8; - gTemp_array[i + k + width] = gTemp_array_u16[i + k] & 0x00FF; - } - for (i = 0; i < width * 2; i++) { - gTemp_array[0 * 32 + i] = Reverse_Bin8(gTemp_array[0 * 32 + i]); - gTemp_array[1 * 32 + i] = Reverse_Bin8(gTemp_array[1 * 32 + i]); - gTemp_array[2 * 32 + i] = Reverse_Bin8(gTemp_array[2 * 32 + i]); - gTemp_array[3 * 32 + i] = Reverse_Bin8(gTemp_array[3 * 32 + i]); - } - - ptr = (u8*) gTemp_array; - for (i = 1; i <= 4; i++) - ptr = Oled_DrawArea(16 * i, 0, 16, 16, (u8*) ptr); - if ((m == 0 && j == 0) || (m == 0 && j == 16)) - return 0; - if (m == 0) - j++; - else - m--; - return 1; -} - -/******************************************************************************* - Function: Show_HeatingIcon - Draws the heating iron icon on the screen - *******************************************************************************/ -void Show_HeatingIcon(u32 ht_flag, u16 active) { - u8* ptr; - - memset(gTemp_array, 0, 20); - if (ht_flag == 0) - Show_ReverseChar((u8*) TempIcon, 1, 10, 0); //(5,ptr,16);//����// - else if (ht_flag == 1) - Show_ReverseChar((u8*) TempIcon + 32, 1, 10, 1); //(5,ptr+32,16);//����// - else if (ht_flag == 2) - Show_OrderChar((u8*) TempIcon, 1, 10); //(5,ptr+64,16);//����// - - ptr = (u8*) gTemp_array; - Oled_DrawArea(86, 0, 10, 16, (u8*) ptr); - - if (Get_CtrlStatus() == WAIT) - Oled_DrawArea(80, 0, 6, 16, (u8*) IhIcon + 12); - else { - if (active == 0) - Oled_DrawArea(80, 0, 6, 16, (u8*) TempIcon + 20); - else - Oled_DrawArea(80, 0, 6, 16, (u8*) IhIcon); - } -} -/******************************************************************************* - Function:Display_Str - Description: Draws certain chars to the screen at certain locations - *******************************************************************************/ -void Display_Str(u8 x, char* str) { - u8* ptr; - u8 temp; - - if ((x < 1) || (x > 8)) - x = 0; - else - x--; - while (*str != 0) { - temp = *str++; - if (temp == ' ') - temp = 10; - else if (temp == '-') - temp = 12; - else { - if ((temp >= 0x30) && (temp < 0x3a)) - temp = temp - 0x30; /* 0 --9 */ - else { - if ((temp >= 0x41) && (temp <= 0x47)) - temp = temp - 0x41 + 11;/*ABD*/ - else - return; - } - } - ptr = (u8*) wordlib; - ptr += temp * 32; - Oled_DrawArea(x * 16, 0, 16, 16, (u8*) ptr); - x++; - } -} -/******************************************************************************* - ������: Display_Str10 - ��������:��ʾ���Ϊ10���ַ��� - �������:x: λ�� str :��ʾ�ַ��� - ���ز���:NULL - *******************************************************************************/ -void Display_Str10(u8 x, char* str) { - u8* ptr; - u8 temp; - u8 position = 0; - - while (*str != 0) { - temp = *str++; - if (temp == 'C') - temp = 11; - else if (temp == 'E') - temp = 12; - else { - if ((temp >= 0x30) && (temp < 0x3a)) - temp = temp - 0x30; /* 0 --9 */ - else { - temp = 10; - } - } - ptr = (u8*) Number10; - ptr += temp * 20; - Oled_DrawArea(x + position * 10, 0, 10, 16, (u8*) ptr); - position++; - } -} - -/******************************************************************************* - ������: Print_Integer - ��������:�������ݴ�ӡ���� - �������:data ����,posi λ�� - ���ز���:NULL - *******************************************************************************/ -void Print_Integer(s32 data, u8 posi) { - char str[8]; - - Clear_Screen(); - sprintf(str, "%ld", data); - Display_Str(posi, str); -} -/******************************************************************************* - ������: Calculation_TWork - ��������:���������¶ȵ�ֵ(�Ӽ����ò�����Ľ��) - �������:Flag (0+ or 1-) - ���ز���:�¶ȼӼ����ò�����Ľ�� - *******************************************************************************/ -u32 Calculation_TWork(u8 Flag) { - s16 num_temp; - - if (Get_TemperatureShowFlag() == 1) { - num_temp = TemperatureShow_Change(0, device_info.t_work); - if (Flag == 0) - num_temp += device_info.t_step; - else - num_temp -= device_info.t_step; - return TemperatureShow_Change(1, num_temp); - } else { - if (Flag == 0) - return (device_info.t_work + device_info.t_step); - else - return (device_info.t_work - device_info.t_step); - } -} -/******************************************************************************* - ������: Roll_Num - ��������:�����У���Ҫ�������¶�ֵ��λ�� - �������:step ����,Flag (0+ or 1-) - ���ز���:��Ҫ�����ĸ��� - *******************************************************************************/ -u8 Roll_Num(u16 step, u8 flag) { - u16 b1, b2, g1, g2; - s16 num_temp; - - if (Get_TemperatureShowFlag() == 1) { - num_temp = TemperatureShow_Change(0, device_info.t_work); - } else { - num_temp = device_info.t_work; - } - b2 = (num_temp) / 1000; - g2 = (num_temp) / 100; - - if (flag == 0) { - b1 = (num_temp + step) / 1000; - g1 = (num_temp + step) / 100; - if (b1 != b2) - return 3; - else if (g1 != g2) - return 2; - else - return 1; - } else { - b1 = (num_temp - step) / 1000; - g1 = (num_temp - step) / 100; - - if (b1 != b2) - return 3; - else if (g1 != g2) - return 2; - else - return 1; - } -} -/******************************************************************************* - ������: Temp_SetProc - ��������:�����¶� - �������:NULL - ���ز���:NULL - *******************************************************************************/ -void Temp_SetProc(void) { - u8 theRoll_num = 3; - static u16 cont = 0; - - if (device_info.t_step == 10) - cont = 1; - - if (EFFECTIVE_KEY_TIMER> 0) { - if(gCont != 0) { - //���ý������������� - gCont = 0; - Set_LongKeyFlag(0); - Clear_Screen(); - - Show_Set(); - } - switch(Get_gKey()) { - case KEY_A: - - if(device_info.t_work > gSet_table[1]) { - gTempset_showctrl = 1; - theRoll_num = Roll_Num(device_info.t_step,1); - while(Show_TempReverse(theRoll_num,16,1)); - device_info.t_work = Calculation_TWork(1); - if(device_info.t_work < gSet_table[1]) device_info.t_work = gSet_table[1]; - gTempset_showctrl = 2; - while(Show_TempReverse(theRoll_num,16,1)); - Show_Triangle(1,0); - } - if(device_info.t_work == gSet_table[1]) Show_Triangle(0,1); - break; - case KEY_B: - - if(device_info.t_work < gSet_table[0]) { - gTempset_showctrl = 1; - theRoll_num = Roll_Num(device_info.t_step,0); - while(Show_TempReverse(theRoll_num,16,0)); - device_info.t_work = Calculation_TWork(0); - if(device_info.t_work > gSet_table[0]) device_info.t_work = gSet_table[0]; - gTempset_showctrl = 2; - while(Show_TempReverse(theRoll_num,16,0)); - Show_Triangle(2,0); - } - - if(device_info.t_work == gSet_table[0]) Show_Triangle(0,2); - break; - default: - break; - } - if(Get_gKey() > NO_KEY) { - if(cont > 0 && EFFECTIVE_KEY_TIMER > 260) { - device_info.t_step = 10 + cont * 50; - cont++; - } - EFFECTIVE_KEY_TIMER = 300; - Set_gKey(NO_KEY); - } - if(cont > 0 && EFFECTIVE_KEY_TIMER <= 260) { - device_info.t_step = 10; - cont = 1; - } - } -} - -/******************************************************************************* - Function: - Description: This function draws in the appropriate content to the Oled as per the current program status - *******************************************************************************/ -void OLed_Display(void) { - u16 ht_flag; - s16 temp_val, dst_temp; - static u8 td_flag = 0, config_show = 0; - static u16 td_cnt = 0; - static u16 bk = 0x33, id_cnt = 0; - - switch (Get_CtrlStatus()) { - case IDLE: - if (gCont == 1) { - gCont = 0; - Clear_Screen(); - } - - if (UI_TIMER== 0 && G6_TIMER != 0) { - Show_Notice(); - UI_TIMER = 50; - } - if(G6_TIMER == 0) { - id_cnt++; - if(id_cnt == 50)Sc_Pt(bk--); - if(bk == 0) Oled_DisplayOff(); - } - if((Get_MmaShift() == 1) || (Get_gKey() != NO_KEY)) { - G6_TIMER = device_info.idle_time; //reset the idle timer - bk = 0x33; - Sc_Pt(bk); - Oled_DisplayOn(); - } - break; - case SOLDERING_MODE: - if(gCont == 0) { - gCont = 1; - Set_LongKeyFlag(1); - Clear_Screen(); - } - ht_flag = Get_HtFlag(); - if(ht_flag != 1) { - if(td_flag == 1) Clear_Screen(); - td_cnt = 0; - td_flag = 0; - } - - if(td_cnt == 75 && td_flag == 0) { - Clear_Screen(); - td_flag = 1; - } - - if(td_flag && UI_TIMER == 0) { - temp_val = Get_TempVal(); - dst_temp = device_info.t_work; - if(Get_TemperatureShowFlag() == 1) { - temp_val = TemperatureShow_Change(0,temp_val); - dst_temp = TemperatureShow_Change(0,dst_temp); - } - Show_TempDown(temp_val,dst_temp); - UI_TIMER = 50; - } - if((TEMPSHOW_TIMER == 0) && (!td_flag)) { - temp_val = Get_TempVal(); - if((temp_val > device_info.t_work) && (temp_val - device_info.t_work < 18)) temp_val = device_info.t_work; - else if((temp_val <= device_info.t_work) && (device_info.t_work - temp_val < 18)) temp_val = device_info.t_work; - if(Get_TemperatureShowFlag() == 1) { - temp_val = TemperatureShow_Change(0,temp_val); - } - - Display_Temp(1,temp_val/10); - Show_HeatingIcon(ht_flag,Get_MmaActive()); - td_cnt++; - } - break; - case TEMP_SET: - Temp_SetProc(); - break; - case USB_POWER: - if(gCont == 1) { - gCont = 0; - Clear_Screen(); - } - switch(Get_gKey()) { - case KEY_CN|KEY_A: - config_show = 1; - break; - case KEY_CN|KEY_B: - config_show = 2; - break; - case KEY_CN|KEY_V3: - config_show = 0; - break; - default: - break; - } - if(config_show == 0) { - Show_Config(); - } - if(config_show != 3) { - Set_gKey(NO_KEY); - config_show = 3; - } - break; - case THERMOMETER: - if(gCont == 0) { - gCont = 1; - Clear_Screen(); - } - if(gCalib_flag != 0) { - //��ʾУ׼��� - Show_Cal(gCalib_flag); - gCalib_flag = 0; - Clear_Screen(); - } - if(UI_TIMER == 0) { - temp_val = Get_Temp(0); - if(Get_TemperatureShowFlag() == 1) { - temp_val = TemperatureShow_Change(0,temp_val); - } - Display_Temp(1,temp_val/10); - Display_Str(6,"F"); - UI_TIMER = 20; - } - break; - case ALARM: - if(gCont == 0) { - gCont = 1; - Clear_Screen(); - } - if(gCont == 1 && UI_TIMER == 0) { - Show_Warning(); - UI_TIMER = 50; - } - break; - case WAIT: - temp_val = Get_TempVal(); - if((temp_val > device_info.t_standby) && (temp_val - device_info.t_standby <= 18)) temp_val = device_info.t_standby; - else if((temp_val <= device_info.t_standby) && (device_info.t_standby - temp_val <= 18)) temp_val = device_info.t_standby; - - ht_flag = Get_HtFlag(); - - if(ht_flag != 1) { - if(td_flag == 1) Clear_Screen(); - td_cnt = 0; - td_flag = 0; - } - - if(td_cnt == 50 && td_flag == 0) { - Clear_Screen(); - td_flag = 1; - } - - if(td_flag && UI_TIMER == 0) { - dst_temp = device_info.t_standby; - if(Get_TemperatureShowFlag() == 1) { - temp_val = TemperatureShow_Change(0,temp_val); - dst_temp = TemperatureShow_Change(0,dst_temp); - } - Show_TempDown(temp_val,dst_temp); - UI_TIMER = 50; - } - if((TEMPSHOW_TIMER == 0) && (!td_flag)) { - if(Get_TemperatureShowFlag() == 1) { - temp_val = TemperatureShow_Change(0,temp_val); - } - Display_Temp(1,temp_val/10); - Show_HeatingIcon(ht_flag,Get_MmaActive()); //0����1����2���� - td_cnt++; - } - break; - case SETTINGS_MENU: - //We are in the menu structure. - //We need to move through the selected menu items, or if the user has hit the EOL then jump back to IDLE - - break; - default: - break; - } -} - -/******************************** END OF FILE *********************************/