diff --git a/SystemDesign.md b/SystemDesign.md index 2a4d72c0..655e08e5 100644 --- a/SystemDesign.md +++ b/SystemDesign.md @@ -6,7 +6,7 @@ This is used for motion detection of the soldering iron. # USB Disk When the unit is plugged into the computer, it presents a FAT device to the operating system over the usb connection. -This is implimented using a ram buffer for the disk. +This is implemented using a ram buffer for the disk. @@ -14,10 +14,8 @@ This is implimented using a ram buffer for the disk. # Future improvements to be made These features are things I would like to add to the firmware -* Use hardware PWM for driving the heating element. * Use the sysTick hardware for timing of events * Move all the settings to an on device menu system instead of usb link * Move error codes into a unified struct * Rewrite most of the OLED stack to not require hardcoded values * Rework the modes of the unit to be neater - diff --git a/workspace/ts100/inc/CTRL.h b/workspace/ts100/inc/CTRL.h index 58745dfe..a05499de 100644 --- a/workspace/ts100/inc/CTRL.h +++ b/workspace/ts100/inc/CTRL.h @@ -19,11 +19,11 @@ #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]/*������ʱ*/ +#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_V1 0x0100/*V1 key pressed*/ @@ -34,10 +34,11 @@ typedef enum WORK_STATUS { IDLE = 1, //System is idle THERMOMETER, //Thermometer mode, basically reads sensor and shows temp - TEMP_CTR, //Soldering Mode (Temp Controlled) + SOLDERING_MODE, //Soldering Mode (Temp Controlled) WAIT, //System in wait state TEMP_SET, //Setting the soldering temp - CONFIG, //system config mode + 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; diff --git a/workspace/ts100/src/CTRL.c b/workspace/ts100/src/CTRL.c index a69f57f7..7ab8680e 100644 --- a/workspace/ts100/src/CTRL.c +++ b/workspace/ts100/src/CTRL.c @@ -215,7 +215,7 @@ void Status_Tran(void) // case KEY_V1: //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(TEMP_CTR); //Set to temperature controlled mode (Aka soldering mode) + 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; @@ -247,7 +247,7 @@ void Status_Tran(void) // gPre_status = IDLE; } break; - case TEMP_CTR: //We are in soldering mode + case SOLDERING_MODE: //We are in soldering mode switch(Get_gKey()) { //switch on the pressed key case KEY_CN|KEY_V1: case KEY_CN|KEY_V2://if either key long pressed @@ -260,7 +260,7 @@ void Status_Tran(void) // 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 = TEMP_CTR;//Set previous status + gPre_status = SOLDERING_MODE;//Set previous status gIs_restartkey = 1; KD_TIMER = 50;// break; @@ -270,7 +270,7 @@ void Status_Tran(void) // 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 = TEMP_CTR;//set previous state + gPre_status = SOLDERING_MODE;//set previous state gIs_restartkey = 1; KD_TIMER = 50;// } @@ -360,7 +360,7 @@ void Status_Tran(void) // UI_TIMER = 0; //reset the un-needed timers G6_TIMER = 0; init_waitingtime = 0; - Set_CtrlStatus(TEMP_CTR);//Go back to soldering iron mode + Set_CtrlStatus(SOLDERING_MODE);//Go back to soldering iron mode } if(Get_AlarmType() > NORMAL_TEMP) { //If an alarm has occurred?? @@ -374,7 +374,7 @@ void Status_Tran(void) // gCalib_flag = 1; gCalib_flag = 0; - Set_CtrlStatus(TEMP_CTR); //return to soldering mode + Set_CtrlStatus(SOLDERING_MODE); //return to soldering mode TEMPSHOW_TIMER = 0;//turn off the timer } break; @@ -416,7 +416,7 @@ void Status_Tran(void) // wk_temp = device_info.t_work; gTemp_data = Get_Temp(wk_temp); if(Get_AlarmType() == NORMAL_TEMP) { - Set_CtrlStatus(TEMP_CTR); + Set_CtrlStatus(SOLDERING_MODE); Set_UpdataFlag(0); } break; diff --git a/workspace/ts100/src/Main.c b/workspace/ts100/src/Main.c index e0b3819a..20e2092c 100644 --- a/workspace/ts100/src/Main.c +++ b/workspace/ts100/src/Main.c @@ -30,7 +30,7 @@ int main(void) { I2C_Configuration(); //init the i2c bus Adc_Init(); //init adc and dma - if (Get_CtrlStatus() != CONFIG) + if (Get_CtrlStatus() != USB_POWER) StartUp_Accelerated(); //start the accelerometer if not in config mode System_Init(); //load known safe values @@ -45,7 +45,7 @@ int main(void) { while (1) { Clear_Watchdog(); //reset the Watchdog - if (Get_CtrlStatus() != CONFIG && LEAVE_WAIT_TIMER== 0) { + 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 } diff --git a/workspace/ts100/src/Oled.c b/workspace/ts100/src/Oled.c index cc08f04e..0409e388 100644 --- a/workspace/ts100/src/Oled.c +++ b/workspace/ts100/src/Oled.c @@ -35,12 +35,9 @@ u8 gOled_param[46] = { 0x80, 0xAE, 0x80, 0xD5, 0x80, 0x52, 0x80, 0xA8, 0x80, 0xAF }; #endif /******************************************************************************* - ������: Sc_Pt - ��������:��Ļ�����ı���Ļ�Աȶ� - �������:Co��Ļ�ԱȶȲ��� - ���ز���:NULL + *******************************************************************************/ -void Sc_Pt(u8 Co) //��Ļ���� +void Sc_Pt(u8 Co) { u8 pt[4] = { 0x80, 0x81, 0x80, Co }; diff --git a/workspace/ts100/src/UI.c b/workspace/ts100/src/UI.c index 3137d883..ce4d1649 100644 --- a/workspace/ts100/src/UI.c +++ b/workspace/ts100/src/UI.c @@ -83,7 +83,7 @@ void APP_Init(void) { Set_CtrlStatus(ALARM); else if (rev >= 4) { //We are USB powered (5V approx at input) Set_LongKeyFlag(1); - Set_CtrlStatus(CONFIG); + Set_CtrlStatus(USB_POWER); } else { //Normal mode > ~9V at input Set_CtrlStatus(IDLE); G6_TIMER= device_info.idle_time; @@ -381,16 +381,10 @@ void Show_Set(void) { Shift_Char((u8*) Triangle + 1 * 32, 5); } /******************************************************************************* - ������: Show_OrderChar - ��������:����̬��ʾ�ַ� - �������: ptr:�ֽڿ�num:����width:��� - ���ز���:NULL + *******************************************************************************/ void Show_OrderChar(u8* ptr, u8 num, u8 width) { static u8 i = 1, j = 0, k = 0, m = 10; - //i��Դ���鿪ʼλ - //j��Ŀ�����鿪ʼλ - //m�������ij��� if (gLevel_flag == 0) { //ǰһ״̬���Ǻ��� i = 1; @@ -452,18 +446,14 @@ u8 Reverse_Bin8(u8 data) { return result; } /******************************************************************************* - ������: Show_ReverseChar - ��������:����̬��ʾ�ַ� - �������: ptr:�ֽڿ� num:���� - width:��� direction :���� (0 up, 1 down) - ���ز���:NULL + *******************************************************************************/ 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) { //ǰһ״̬���Ǽ��� + if (gUp_flag == 0) { // j = 0; m = 0; gUp_flag = 1; @@ -474,7 +464,7 @@ void Show_ReverseChar(u8* ptr, u8 num, u8 width, u8 direction) { m = po_m[0]; } } else if (direction == 1) { - if (gDown_flag == 0) { //ǰһ״̬���ǽ��� + if (gDown_flag == 0) { // j = 0; m = 0; gUp_flag = 0; @@ -489,31 +479,31 @@ void Show_ReverseChar(u8* ptr, u8 num, u8 width, u8 direction) { m = po_m[2]; } for (i = 0; i < width * 2 * num; i++) - gTemp_array[i] = Reverse_Bin8(*(ptr + i)); //����8λ + 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]; //�ϰ벿�°벿���u16 ������λ + | gTemp_array[i + k + width]; // if (direction == 1) { if (j == 0) - gTemp_array_u16[i + k] <<= m; //����գ�������ʾ + gTemp_array_u16[i + k] <<= m; // else - gTemp_array_u16[i + k] >>= j; //����գ�������ʾ + gTemp_array_u16[i + k] >>= j; // } else { //�� if (m == 0) - gTemp_array_u16[i + k] <<= j; //����գ�������ʾ + gTemp_array_u16[i + k] <<= j; // else - gTemp_array_u16[i + k] >>= m; //����գ�������ʾ + 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]); //��λ�������� + gTemp_array[i] = Reverse_Bin8(gTemp_array[i]); // - if (m == 0 && j == 16) { //ȫ��ʾ������ʾ'ͷ��' + if (m == 0 && j == 16) { j = 0; m = 16; } @@ -535,9 +525,9 @@ void Show_ReverseChar(u8* ptr, u8 num, u8 width, u8 direction) { } /******************************************************************************* - Show_TempReverse ����̬��ʾ�¶��ַ� - word_num: ���� - word_width: ��� + Show_TempReverse + word_num: + word_width: direction : ���� (0 up, 1 down) *******************************************************************************/ u8 Show_TempReverse(u8 num, u8 width, u8 direction) { @@ -567,30 +557,30 @@ u8 Show_TempReverse(u8 num, u8 width, u8 direction) { gTempset_showctrl = 0; } for (i = 0; i < width * 2; i++) { - gTemp_array[0 * 32 + i] = Reverse_Bin8(*(wordlib + b * 32 + i)); //����8λ - gTemp_array[1 * 32 + i] = Reverse_Bin8(*(wordlib + s * 32 + i)); //����8λ - gTemp_array[2 * 32 + i] = Reverse_Bin8(*(wordlib + g * 32 + i)); //����8λ + 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)); //����8λ + gTemp_array[3 * 32 + i] = Reverse_Bin8(*(wordlib + 15 * 32 + i)); } else { - gTemp_array[3 * 32 + i] = Reverse_Bin8(*(wordlib + 13 * 32 + i)); //����8λ + gTemp_array[3 * 32 + i] = Reverse_Bin8(*(wordlib + 13 * 32 + i)); } } - //�޸�K �ij�ʼֵ�ܸı俪ʼ�������ַ�λ�ø�λ����ʮλ���ǰ�λ + 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]; //�ϰ벿�°벿���u16 ������λ - if (direction == 0) { //�� + | gTemp_array[i + k + width]; + if (direction == 0) { if (m == 0) - gTemp_array_u16[i + k] <<= j; //����գ�������ʾ + gTemp_array_u16[i + k] <<= j; else - gTemp_array_u16[i + k] >>= m; //����գ�������ʾ + gTemp_array_u16[i + k] >>= m; } else { if (j == 0) - gTemp_array_u16[i + k] <<= m; //����գ�������ʾ + gTemp_array_u16[i + k] <<= m; else - gTemp_array_u16[i + k] >>= j; //����գ�������ʾ + 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; @@ -615,21 +605,19 @@ u8 Show_TempReverse(u8 num, u8 width, u8 direction) { } /******************************************************************************* - ������: Show_HeatingIcon - ��������:��̬ѡ����ȵ�״̬��ʶ - �������: ht_flag ���±�ʾ active �ƶ���ʶ - ���ز���:NULL + 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);//����// + 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);//����// + Show_OrderChar((u8*) TempIcon, 1, 10); //(5,ptr+64,16);//����// ptr = (u8*) gTemp_array; Oled_DrawArea(86, 0, 10, 16, (u8*) ptr); @@ -809,8 +797,7 @@ void Temp_SetProc(void) { } switch(Get_gKey()) { case KEY_V1: - //����,���·�,��ǰ����ʾ��ʧ - //����ֵ���� + if(device_info.t_work > gSet_table[1]) { gTempset_showctrl = 1; theRoll_num = Roll_Num(device_info.t_step,1); @@ -824,8 +811,7 @@ void Temp_SetProc(void) { if(device_info.t_work == gSet_table[1]) Show_Triangle(0,1); break; case KEY_V2: - //����,���Ϸ�,��ǰ����ʾ��ʧ - //����ֵ���� + if(device_info.t_work < gSet_table[0]) { gTempset_showctrl = 1; theRoll_num = Roll_Num(device_info.t_step,0); @@ -879,7 +865,7 @@ void OLed_Display(void) { Show_Notice(); UI_TIMER = 50; } - if(G6_TIMER == 0) { //���� + if(G6_TIMER == 0) { id_cnt++; if(id_cnt == 50)Sc_Pt(bk--); if(bk == 0) Oled_DisplayOff(); @@ -891,7 +877,7 @@ void OLed_Display(void) { Oled_DisplayOn(); } break; - case TEMP_CTR: + case SOLDERING_MODE: if(gCont == 0) { gCont = 1; Set_LongKeyFlag(1); @@ -935,7 +921,7 @@ void OLed_Display(void) { case TEMP_SET: Temp_SetProc(); //���� break; - case CONFIG: + case USB_POWER: if(gCont == 1) { gCont = 0; Clear_Screen(); @@ -1024,10 +1010,15 @@ void OLed_Display(void) { temp_val = TemperatureShow_Change(0,temp_val); } Display_Temp(1,temp_val/10); - Show_HeatingIcon(ht_flag,Get_MmaActive()); //0����1����2���� + 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; }