├── APK ├── README.md └── app-debug - 0.6.6.apk ├── Code ├── HWTest │ ├── ABM_Buttons.cpp │ ├── ABM_Buttons.h │ ├── ABM_Buzzer.cpp │ ├── ABM_Buzzer.h │ ├── ABM_Cfg.h │ ├── ABM_HW_switch.cpp │ ├── ABM_HW_switch.h │ ├── ABM_Port.h │ ├── HWTest.ino │ ├── PID_control.h │ ├── Sensors.cpp │ ├── Sensors.h │ ├── SmartPID_logo_1bit.c │ ├── WiFi.cpp │ ├── WiFi.h │ ├── delay.cpp │ ├── delay.h │ ├── hwTest.cpp │ ├── hwTest.h │ ├── pin_cfg.h │ ├── run_mode.h │ ├── storage_var.cpp │ ├── storage_var.h │ ├── u8g_port.cpp │ ├── utlts.cpp │ ├── utlts.h │ ├── vsd_GUI.cpp │ ├── vsd_GUI.h │ ├── vsd_Menu.cpp │ └── vsd_macros.h └── README.md ├── Driver ├── README.md ├── SPC1000 │ ├── arzaman-samd-1.0.1.tar.bz2 │ └── package_arzaman_index.json └── SmartPID-SPC1000-USB-DRIVER │ └── arzaman.inf ├── HW ├── AB1000_BB_V6_fin.PcbDoc ├── AB1000_BB_V6_fin.pdf ├── AB1000_FB_V6.1.PcbDoc ├── AB1000_RB_V6_fin.PcbDoc ├── FB_V6_schema.pdf ├── RB_V6_assembly.pdf ├── RB_V6_schema.pdf └── README.md ├── LICENSE.txt ├── Libraries ├── HWTest_libraries-v2.0-002.zip └── README.md ├── Manual ├── README.md ├── SmartPID SPC1000 USER MANUAL 1.0.pdf └── SmartPID SPC1000 installation and configuration manual 1.3.pdf ├── Picture ├── 2016-11-25 19_57_43-Greenshot (1).png ├── 2016-11-25 19_57_43-Greenshot.png ├── BANNER-2 (1).png ├── BANNER-2.png ├── BANNER-3 (1).png ├── BANNER-3.png ├── BANNER-4 (1).png ├── BANNER-4.png ├── BANNER-5 (1).png ├── BANNER-5.png ├── Pro101SmartID2 (1).jpg ├── Pro101SmartID2.jpg ├── arm+smad21 (1).jpg ├── arm+smad21.jpg ├── circuit-board.png ├── header.jpg ├── img-features (1).png ├── img-features.png ├── multipe smartpid applications.jpg ├── smarphone app smarpid (1).jpg ├── smarphone app smarpid.jpg ├── smartPID HW overview (1).jpg ├── smartPID HW overview.jpg ├── smartPID HW.jpg ├── smartPID assembling (1).jpg ├── smartPID assembling.jpg ├── smartpid APK install.png ├── specs (1).jpg └── specs.jpg └── README.md /APK/README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/APK/README.md -------------------------------------------------------------------------------- /APK/app-debug - 0.6.6.apk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/APK/app-debug - 0.6.6.apk -------------------------------------------------------------------------------- /Code/HWTest/ABM_Buttons.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "ABM_Buttons.h" 3 | #include "ABM_Buzzer.h" 4 | #include "ABM_Cfg.h" 5 | #include "utlts.h" 6 | 7 | 8 | volatile TButton_status Buttons_status[N_BUTTONS]; 9 | 10 | mOneButton Button_UP(PIN_BUTTON_UP, &Buttons_status[BUTTON_UP], HIGH); 11 | mOneButton Button_DOWN(PIN_BUTTON_DOWN, &Buttons_status[BUTTON_DOWN], HIGH); 12 | mOneButton Button_ENTER(PIN_BUTTON_ENTER, &Buttons_status[BUTTON_ENTER], HIGH); 13 | mOneButton Button_SS(PIN_BUTTON_SS, &Buttons_status[BUTTON_SS], HIGH); 14 | 15 | uint8_t buttons_tick_count; 16 | 17 | int autorepeat_factor; 18 | 19 | //****************************************************************************** 20 | uint8_t GetKeyPressMask(uint8_t mask) 21 | { 22 | uint8_t ret=NO_PRESS; 23 | for(uint8_t i=0;iN_BUTTONS) return BTN_NO_PRESS; 152 | 153 | TButton_status bstat; 154 | bstat.status_val=Buttons_status[n].status_val; 155 | Buttons_status[n].status_val=0; 156 | 157 | if(bstat.status.click) return BTN_CLICK; 158 | if(bstat.status.duble_click) return BTN_DOUBLE_CLICK; 159 | if(bstat.status.long_start) return BTN_LONG_START; 160 | if(bstat.status.long_stop) return BTN_LONG_STOP; 161 | if(bstat.status.long_press) return BTN_LONG_PRES; 162 | 163 | return BTN_NO_PRESS; 164 | } 165 | //****************************************************************************** 166 | void Button_UP_click(void) 167 | { 168 | Buttons_status[BUTTON_UP].status.click=1; 169 | } 170 | void Button_UP_doubleclick(void) 171 | { 172 | Buttons_status[BUTTON_UP].status.duble_click=1; 173 | } 174 | void Button_UP_longPressStart(void) 175 | { 176 | Buttons_status[BUTTON_UP].status.long_start=1; 177 | } 178 | void Button_UP_longPressStop(void) 179 | { 180 | Buttons_status[BUTTON_UP].status.long_stop=1; 181 | } 182 | void Button_UP_longPress(void) 183 | { 184 | Buttons_status[BUTTON_UP].status.long_press=1; 185 | } 186 | //****************************************************************************** 187 | void Button_DOWN_click(void) 188 | { 189 | Buttons_status[BUTTON_DOWN].status.click=1; 190 | } 191 | void Button_DOWN_doubleclick(void) 192 | { 193 | Buttons_status[BUTTON_DOWN].status.duble_click=1; 194 | } 195 | void Button_DOWN_longPressStart(void) 196 | { 197 | Buttons_status[BUTTON_DOWN].status.long_start=1; 198 | } 199 | void Button_DOWN_longPressStop(void) 200 | { 201 | Buttons_status[BUTTON_DOWN].status.long_stop=1; 202 | } 203 | void Button_DOWN_longPress(void) 204 | { 205 | Buttons_status[BUTTON_DOWN].status.long_press=1; 206 | } 207 | //****************************************************************************** 208 | void Button_ENTER_click(void) 209 | { 210 | Buttons_status[BUTTON_ENTER].status.click=1; 211 | } 212 | void Button_ENTER_doubleclick(void) 213 | { 214 | Buttons_status[BUTTON_ENTER].status.duble_click=1; 215 | } 216 | void Button_ENTER_longPressStart(void) 217 | { 218 | Buttons_status[BUTTON_ENTER].status.long_start=1; 219 | } 220 | void Button_ENTER_longPressStop(void) 221 | { 222 | Buttons_status[BUTTON_ENTER].status.long_stop=1; 223 | } 224 | void Button_ENTER_longPress(void) 225 | { 226 | Buttons_status[BUTTON_ENTER].status.long_press=1; 227 | } 228 | //****************************************************************************** 229 | void Button_SS_click(void) 230 | { 231 | Buttons_status[BUTTON_SS].status.click=1; 232 | } 233 | void Button_SS_doubleclick(void) 234 | { 235 | Buttons_status[BUTTON_SS].status.duble_click=1; 236 | } 237 | void Button_SS_longPressStart(void) 238 | { 239 | Buttons_status[BUTTON_SS].status.long_start=1; 240 | } 241 | void Button_SS_longPressStop(void) 242 | { 243 | Buttons_status[BUTTON_SS].status.long_stop=1; 244 | } 245 | void Button_SS_longPress(void) 246 | { 247 | Buttons_status[BUTTON_SS].status.long_press=1; 248 | } 249 | //****************************************************************************** 250 | 251 | //****************************************************************************** 252 | void ButtonsSetup(void) { 253 | /* 254 | Button_UP.attachClick(Button_UP_click); 255 | Button_UP.attachDoubleClick(Button_UP_doubleclick); 256 | Button_UP.attachLongPressStart(Button_UP_longPressStart); 257 | Button_UP.attachLongPressStop(Button_UP_longPressStop); 258 | Button_UP.attachDuringLongPress(Button_UP_longPress); 259 | 260 | Button_DOWN.attachClick(Button_DOWN_click); 261 | Button_DOWN.attachDoubleClick(Button_DOWN_doubleclick); 262 | Button_DOWN.attachLongPressStart(Button_DOWN_longPressStart); 263 | Button_DOWN.attachLongPressStop(Button_DOWN_longPressStop); 264 | Button_DOWN.attachDuringLongPress(Button_DOWN_longPress); 265 | 266 | Button_ENTER.attachClick(Button_ENTER_click); 267 | Button_ENTER.attachDoubleClick(Button_ENTER_doubleclick); 268 | Button_ENTER.attachLongPressStart(Button_ENTER_longPressStart); 269 | Button_ENTER.attachLongPressStop(Button_ENTER_longPressStop); 270 | Button_ENTER.attachDuringLongPress(Button_ENTER_longPress); 271 | 272 | Button_SS.attachClick(Button_SS_click); 273 | Button_SS.attachDoubleClick(Button_SS_doubleclick); 274 | Button_SS.attachLongPressStart(Button_SS_longPressStart); 275 | Button_SS.attachLongPressStop(Button_SS_longPressStop); 276 | Button_SS.attachDuringLongPress(Button_SS_longPress); 277 | */ 278 | } // setup 279 | 280 | void buttons_tick(void) 281 | { 282 | buttons_tick_count=(buttons_tick_count+1)%10; 283 | switch(buttons_tick_count) 284 | { 285 | case 0: Button_UP.tick(); break; 286 | case 2: Button_DOWN.tick(); break; 287 | case 3: Button_ENTER.tick(); break; 288 | case 4: Button_SS.tick(); break; 289 | } 290 | 291 | } 292 | 293 | void ButtonBeep(void) 294 | { 295 | Buzzer_wgen(50,10,1); 296 | } 297 | -------------------------------------------------------------------------------- /Code/HWTest/ABM_Buttons.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARDBUTTONS_H_ 2 | #define _ARDBUTTONS_H_ 3 | 4 | #include 5 | 6 | /* 7 | typedef struct _TButton_status{ 8 | union{ 9 | uint8_t status_val; 10 | struct{ 11 | uint8_t press:1; 12 | uint8_t click:1; 13 | uint8_t duble_click:1; 14 | uint8_t long_start:1; 15 | uint8_t long_stop:1; 16 | uint8_t long_press:1; 17 | }status; 18 | }; 19 | }TButton_status; 20 | 21 | enum e_button_status{ 22 | BTN_NO_PRESS=0, 23 | BTN_PRESS, 24 | BTN_CLICK, 25 | BTN_DOUBLE_CLICK, 26 | BTN_LONG_START, 27 | BTN_LONG_STOP, 28 | BTN_LONG_PRES 29 | }; 30 | */ 31 | 32 | extern volatile TButton_status Buttons_status[]; 33 | extern int autorepeat_factor; 34 | 35 | uint8_t GetStatusButtons(uint8_t n); 36 | uint8_t GetKeyPressF(void); 37 | uint8_t GetKeyPressL(void); 38 | uint8_t GetKeyPressMask(uint8_t mask); 39 | uint8_t GetAllKeyPress(void); 40 | void ClearAllKeyPress(void); 41 | uint8_t CheckAllLongPress(void); 42 | uint8_t CheckFreeAllKey(void); 43 | void WaitFreeAllKey(void); 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /Code/HWTest/ABM_Buzzer.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "ABM_Buzzer.h" 3 | #include "ABM_Cfg.h" 4 | #include "wiring_constants.h" 5 | #include "wiring_digital.h" 6 | 7 | TBuzzer_state Buzzer_state; 8 | 9 | //****************************************************************************** 10 | void tickBuzzer(void) 11 | { 12 | if(Buzzer_state.state_mach==stBuz_off) return; 13 | if(Buzzer_state.state_mach==stBuz_st1) 14 | { 15 | if(Buzzer_state.time_state_1<=(++(Buzzer_state.timer_state_1))) 16 | { 17 | Buzzer_state.state_mach=stBuz_st2; digitalWrite(PIN_BUZZER,LOW); Buzzer_state.timer_state_1=0; 18 | } 19 | else 20 | { 21 | } 22 | return; 23 | } 24 | if(Buzzer_state.state_mach==stBuz_st2) 25 | { 26 | if(Buzzer_state.time_state_2<=(++(Buzzer_state.timer_state_2))) 27 | { 28 | if(Buzzer_state.n_cycles>0) if ((--Buzzer_state.n_cycles)==0) {Buzzer_state.state_mach=stBuz_off; digitalWrite(PIN_BUZZER,LOW); return;} 29 | Buzzer_state.state_mach=stBuz_st1; digitalWrite(PIN_BUZZER,HIGH); Buzzer_state.timer_state_2=0; 30 | } 31 | else 32 | { 33 | } 34 | return; 35 | } 36 | } 37 | //****************************************************************************** 38 | void setupBuzzer(void) 39 | { 40 | pinMode(PIN_BUZZER, OUTPUT); 41 | digitalWrite(PIN_BUZZER,LOW); 42 | Buzzer_state.n_cycles=0; 43 | Buzzer_state.state_mach=0; 44 | Buzzer_state.timer_state_1=0; 45 | Buzzer_state.timer_state_2=0; 46 | Buzzer_state.time_state_1=0; 47 | Buzzer_state.time_state_2=0; 48 | } 49 | //****************************************************************************** 50 | void Buzzer_wgen(unsigned int t_st1, 51 | unsigned int t_st2, 52 | unsigned int n_cycles) 53 | { 54 | // _CLI(); 55 | // Buzzer_state.state_1=st1; 56 | Buzzer_state.time_state_1=t_st1; 57 | // Buzzer_state.state_2=st2; 58 | Buzzer_state.time_state_2=t_st2; 59 | Buzzer_state.n_cycles=n_cycles; 60 | Buzzer_state.state_mach=stBuz_st1; 61 | Buzzer_state.timer_state_1=0; 62 | Buzzer_state.timer_state_2=0; 63 | // Buzzer_state.end_state=end_st; 64 | 65 | digitalWrite(PIN_BUZZER,HIGH); 66 | 67 | // _SEI(); 68 | } 69 | //****************************************************************************** 70 | -------------------------------------------------------------------------------- /Code/HWTest/ABM_Buzzer.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARDBUZZER_H_ 2 | #define _ARDBUZZER_H_ 3 | 4 | //#include "ABM_Port.h" 5 | 6 | typedef struct TBuzzer_state 7 | { 8 | // RGB_state state_1; 9 | unsigned int time_state_1; 10 | // RGB_state state_2; 11 | unsigned int time_state_2; 12 | unsigned int n_cycles; 13 | unsigned char state_mach; 14 | unsigned int timer_state_1; 15 | unsigned int timer_state_2; 16 | // RGB_state end_state; 17 | }__TBuzzer; 18 | 19 | enum mStateRGB{ 20 | stBuz_off=0, 21 | stBuz_st1, 22 | stBuz_st2, 23 | }; 24 | 25 | void Buzzer_wgen(unsigned int t_st1, unsigned int t_st2, unsigned int n_cycles); 26 | 27 | #endif -------------------------------------------------------------------------------- /Code/HWTest/ABM_Cfg.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARDCFG_H_ 2 | #define _ARDCFG_H_ 3 | 4 | #define PIN_BUTTON_UP 14/*S1, PA02, 14 | A0 | PA02*/ 5 | #define PIN_BUTTON_DOWN 17/*S2, PA04, 17 | A3 | PA04*/ 6 | #define PIN_BUTTON_ENTER 8/*S3, PA06, 8 | ~8 | PA06*/ 7 | #define PIN_BUTTON_SS 9/*S4, PA07, 9 | ~9 | PA07*/ 8 | 9 | #define PIN_BUZZER 2/*PA14, 2 | 2 | PA14*/ 10 | 11 | #define PIN_RELAY1 6/*PA20, 6 | ~6 | PA20*/ 12 | #define PIN_RELAY2 7/*PA21, 7 | 7 | PA21*/ 13 | #define PIN_FET1 26/*PA27, 26 | | PA27*/ 14 | #define PIN_FET2 27/*PA28, 27 | | PA28*/ 15 | #define PIN_SSR1 22/*PA12, 22 | 1 | PA12*/ 16 | #define PIN_RES1 23/*PB10, 23 | 4 | PB10*/ 17 | 18 | #define PIN_SENS1 3/*PA09, 3 | ~3 | PA09*/ 19 | #define PIN_SENS2 4/*PA08, 4 | ~4 | PA08*/ 20 | #define PIN_NTC1 15/*PB08, 15 | A1 | PB08*/ 21 | #define PIN_NTC2 16/*PB09, 16 | A2 | PB09*/ 22 | 23 | #define NTC_ADC_CH_probe1 2 24 | #define NTC_ADC_CH_probe2 3 25 | 26 | #define NTC_PULL_RESISTOR 5100 27 | #define NTC_RESISTANCE 10000 28 | #define BCOEFFICIENT 3977 29 | #define TEMPERATURENOMINAL 25 30 | 31 | #define TEST_PIN_PA13 38 32 | 33 | #define HW_SERIAL_NUM_LEN 8 34 | #define HW_SERIAL_NUM_ADDR (0x4000 - HW_SERIAL_NUM_LEN) 35 | 36 | #define CELSIUS_TO_FAHRENHEIT(celsius) (32 + 1.8 * (celsius)) 37 | #define FAHRENHEIT_TO_CELSIUS(fahrenheit) (0.555555555F * ((fahrenheit) - 32)) 38 | 39 | #define DELTA_CELSIUS_TO_FAHRENHEIT(celsius) (1.8 * (celsius)) 40 | #define DELTA_FAHRENHEIT_TO_CELSIUS(fahrenheit) (0.555555555F * (fahrenheit)) 41 | 42 | #define TEMP_C_MIN -40 43 | #define TEMP_C_MAX 120 44 | 45 | #define TEMP_F_MIN CELSIUS_TO_FAHRENHEIT(TEMP_C_MIN) 46 | #define TEMP_F_MAX CELSIUS_TO_FAHRENHEIT(TEMP_C_MAX) 47 | 48 | #define RESET_TEMP_C_MIN 2 49 | #define RESET_TEMP_C_MAX 20 50 | 51 | #define RESET_TEMP_F_MIN DELTA_CELSIUS_TO_FAHRENHEIT(RESET_TEMP_C_MIN) 52 | #define RESET_TEMP_F_MAX DELTA_CELSIUS_TO_FAHRENHEIT(RESET_TEMP_C_MAX) 53 | 54 | #define HYST_TEMP_C_MAX 5 55 | 56 | #define HYST_TEMP_F_MAX DELTA_CELSIUS_TO_FAHRENHEIT(HYST_TEMP_C_MAX) 57 | 58 | //#define N_BUTTONS 4 59 | enum e_buttons{ 60 | BUTTON_UP, 61 | BUTTON_DOWN, 62 | BUTTON_ENTER, 63 | BUTTON_SS, 64 | N_BUTTONS, 65 | NO_PRESS, 66 | BUTTON_UP_LP=0x10, 67 | BUTTON_DOWN_LP, 68 | BUTTON_ENTER_LP, 69 | BUTTON_SS_LP, 70 | }; 71 | 72 | //#define N_DRIVERS # 73 | /* 74 | enum e_drivers{ 75 | RELAY1, 76 | RELAY2, 77 | FET1, 78 | FET2, 79 | SSR1, 80 | RES1, 81 | N_DRIVERS 82 | }; 83 | */ 84 | 85 | enum e_drivers_mode{ 86 | PWM_OUT, 87 | SWITCH_OUT, 88 | OFF_DRIVER 89 | }; 90 | 91 | enum e_switch_var{ 92 | CLR_OUT, 93 | SET_OUT 94 | }; 95 | 96 | enum e_contr_mode{HEATING,COOLING,T_STATIC}; 97 | //enum e_heat_mode{ELECTRIC,GAS}; 98 | enum e_cooling_mode{MODE_PID,MODE_ON_OFF,MODE_DISABLE}; 99 | enum e_multi_control{SINGLE,DUAL}; 100 | enum e_out_driver{OUT_SSR,OUT_DC1,OUT_DC2,OUT_REL1,OUT_REL2,N_DRIVERS,OUT_OFF=N_DRIVERS}; 101 | enum e_probe_mode{PROBE_OFF,PROBE_DS18B20,PROBE_NTC}; 102 | enum e_temp_scale{T_CELSIUS,T_FAHRENHEIT}; 103 | 104 | enum e_pid_num{PID_1,PID_2}; 105 | 106 | #endif 107 | -------------------------------------------------------------------------------- /Code/HWTest/ABM_HW_switch.cpp: -------------------------------------------------------------------------------- 1 | 2 | 3 | #include "ABM_HW_switch.h" 4 | #include "storage_var.h" 5 | #include "PID_control.h" 6 | //#include "ABM_Port.h" 7 | 8 | #define OUTPUT_INPUT 4 9 | 10 | TDrive DriveOut[N_DRIVERS]; 11 | 12 | _s_mode_switch SwitchMode[2]; 13 | 14 | #ifdef _WE 15 | void digitalWrite_alt(uint32_t pin, uint32_t val); 16 | #else 17 | extern const PinDescription g_APinDescription[]; 18 | #endif 19 | //****************************************************************************** 20 | #ifndef _WE 21 | void digitalWrite_alt( uint32_t ulPin, uint32_t ulVal ) 22 | { 23 | // Handle the case the pin isn't usable as PIO 24 | if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN ) 25 | { 26 | return ; 27 | } 28 | 29 | // Enable pull-up resistor 30 | // PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg=(uint8_t)(PORT_PINCFG_PULLEN) ; 31 | 32 | switch ( ulVal ) 33 | { 34 | case LOW: 35 | PORT->Group[g_APinDescription[ulPin].ulPort].OUTCLR.reg = (1ul << g_APinDescription[ulPin].ulPin) ; 36 | break ; 37 | 38 | default: 39 | PORT->Group[g_APinDescription[ulPin].ulPort].OUTSET.reg = (1ul << g_APinDescription[ulPin].ulPin) ; 40 | break ; 41 | } 42 | 43 | return ; 44 | } 45 | #endif 46 | //****************************************************************************** 47 | void pinMode_alt( uint32_t ulPin, uint32_t ulMode ) 48 | { 49 | #ifndef _WE 50 | if ( g_APinDescription[ulPin].ulPinType == PIO_NOT_A_PIN ) 51 | { 52 | return ; 53 | } 54 | switch ( ulMode ) 55 | { 56 | case OUTPUT_INPUT: 57 | // Set pin to input mode 58 | PORT->Group[g_APinDescription[ulPin].ulPort].PINCFG[g_APinDescription[ulPin].ulPin].reg=(uint8_t)(PORT_PINCFG_INEN) ; 59 | // PORT->Group[g_APinDescription[ulPin].ulPort].DIRCLR.reg = (uint32_t)(1<Group[g_APinDescription[ulPin].ulPort].DIRSET.reg = (uint32_t)(1<=DriveOut[i].pwm_max) DriveOut[i].pwm_count=0; 107 | if(DriveOut[i].pwm_count>=DriveOut[i].pwm_comp) DriveSwitch(i,CLR_OUT); else DriveSwitch(i,SET_OUT); 108 | DriveOut[i].pwm_count++; 109 | }break; 110 | } 111 | } 112 | } 113 | //****************************************************************************** 114 | void setupDrivers(void) 115 | { 116 | DriveOut[OUT_REL1].pin=PIN_RELAY1; 117 | DriveOut[OUT_REL2].pin=PIN_RELAY2; 118 | DriveOut[OUT_DC1].pin=PIN_FET1; 119 | DriveOut[OUT_DC2].pin=PIN_FET2; 120 | DriveOut[OUT_SSR].pin=PIN_SSR1; 121 | // DriveOut[OUT_RES1].pin=PIN_RES1; 122 | 123 | for(int i=0;idrive_clr_count=1; return;} 159 | 160 | //half_h=(float)_stv.ProcPar.hyster/2; 161 | hmin=*(pid->mySetpoint)-half_h; 162 | hmax=*(pid->mySetpoint)+half_h; 163 | if((digitalRead(drv->pin)==0)) 164 | { 165 | if(*(pid->myInput)<=hmin) {drv->drive_set_count=1; switch_mode->on_off=onoffSET; switch_mode->mode=mpsHEAT_ONOFF;} 166 | } 167 | else 168 | { 169 | if(*(pid->myInput)>=hmax) {drv->drive_clr_count=1; switch_mode->on_off=onoffCLR; switch_mode->mode=mpsHEAT_ONOFF;} 170 | } 171 | } 172 | //****************************************************************************** 173 | void SwitchForON_OFF_neg(uint8_t pidn,TDrive *drv, uint8_t lock) 174 | { 175 | PIDe *pid; 176 | _s_mode_switch *switch_mode; 177 | 178 | float hmin,hmax,half_h; 179 | 180 | switch_mode=&SwitchMode[pidn]; 181 | 182 | if(pidn==PID_1) { 183 | pid=&PID_n1; 184 | half_h=(float)_stv.ProcPar.hysteresis1/2; 185 | } 186 | else { 187 | pid=&PID_n2; 188 | half_h=(float)_stv.ProcPar.hysteresis2/2; 189 | } 190 | 191 | if(lock==1) {drv->drive_clr_count=1; return;} 192 | 193 | //half_h=(float)_stv.ProcPar.hyster/2; 194 | hmin=*(pid->mySetpoint)-half_h; 195 | hmax=*(pid->mySetpoint)+half_h; 196 | if((digitalRead(drv->pin)==0)) 197 | { 198 | if(*(pid->myInput)>=hmax) {drv->drive_set_count=1; switch_mode->on_off=onoffSET; switch_mode->mode=mpsCOOLING_ONOFF;} 199 | } 200 | else 201 | { 202 | if(*(pid->myInput)<=hmin) {drv->drive_clr_count=1; switch_mode->on_off=onoffCLR; switch_mode->mode=mpsCOOLING_ONOFF;} 203 | } 204 | } 205 | //****************************************************************************** 206 | void ManageOutAllCh(float in,uint8_t heat_n, uint8_t cool_n, uint8_t PID_n) 207 | { 208 | float positive,negative; 209 | positive=(in>=0?in:0); 210 | negative=(in<=0?0-in:0); 211 | TDrive *out_heater=0, *out_cooling=0; 212 | uint8_t lock=0; 213 | 214 | if(heat_n < N_DRIVERS) 215 | { 216 | if(_stv.HW_var.contr_mode==HEATING || _stv.HW_var.contr_mode==T_STATIC) 217 | { 218 | out_heater=&DriveOut[heat_n]; 219 | if(_stv.HW_var.heat_mode==MODE_PID/*ELECTRIC*/) { 220 | out_heater->pwm_comp=(uint32_t)((out_heater->pwm_max*positive)/100); 221 | if(0!=(uint8_t)positive || SwitchMode[PID_n].pwm!=0){ 222 | SwitchMode[PID_n].mode=mpsHEAT_PID; SwitchMode[PID_n].pwm=(uint8_t)positive;} 223 | } 224 | else{ 225 | if(cool_n < N_DRIVERS && negative>0 && _stv.HW_var.cool_mode==MODE_PID) lock=1; 226 | SwitchForON_OFF_pos(PID_n,out_heater,lock); 227 | } 228 | } 229 | } 230 | 231 | if(cool_n < N_DRIVERS) 232 | { 233 | if(_stv.HW_var.contr_mode==COOLING || _stv.HW_var.contr_mode==T_STATIC) 234 | { 235 | out_cooling=&DriveOut[cool_n]; 236 | if(_stv.HW_var.cool_mode==MODE_PID) { 237 | out_cooling->pwm_comp=(uint32_t)((out_cooling->pwm_max*negative)/100); 238 | if(0!=(uint8_t)negative || SwitchMode[PID_n].pwm!=0){ 239 | SwitchMode[PID_n].mode=mpsCOOLING_PID; SwitchMode[PID_n].pwm=(uint8_t)negative;} 240 | } 241 | else{ 242 | if(heat_n < N_DRIVERS && positive>0 && _stv.HW_var.heat_mode==MODE_PID) lock=1; 243 | SwitchForON_OFF_neg(PID_n,out_cooling,lock); 244 | } 245 | } 246 | } 247 | } 248 | //****************************************************************************** 249 | void MangeOutCn1(float in) 250 | { 251 | ManageOutAllCh(in,_stv.HW_var.out1_heat,_stv.HW_var.out1_cool,PID_1); 252 | } 253 | //****************************************************************************** 254 | void MangeOutCn2(float in) 255 | { 256 | ManageOutAllCh(in,_stv.HW_var.out2_heat,_stv.HW_var.out2_cool,PID_2); 257 | } 258 | //****************************************************************************** 259 | -------------------------------------------------------------------------------- /Code/HWTest/ABM_HW_switch.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARDHW_SWITCH_H_ 2 | #define _ARDHW_SWITCH_H_ 3 | 4 | #include 5 | 6 | #include "ABM_Cfg.h" 7 | 8 | typedef struct _TDrive{ 9 | uint8_t pin; 10 | uint8_t pin_mode; 11 | uint8_t drive_mode; 12 | bool drive_inverse; 13 | uint32_t pwm_count; 14 | uint32_t pwm_comp; 15 | uint32_t pwm_max; 16 | uint32_t drive_set_count; 17 | uint32_t drive_clr_count; 18 | }TDrive; 19 | 20 | enum mode_pid_switch{ 21 | mpsOFF, 22 | mpsHEAT_PID, 23 | mpsCOOLING_PID, 24 | mpsHEAT_ONOFF, 25 | mpsCOOLING_ONOFF 26 | }; 27 | 28 | enum onoffSETs{ 29 | onoffSET, 30 | onoffCLR 31 | }; 32 | 33 | struct _s_mode_switch{ 34 | uint8_t mode; 35 | uint8_t pwm; 36 | uint8_t on_off; 37 | }; 38 | 39 | extern _s_mode_switch SwitchMode[]; 40 | extern TDrive DriveOut[]; 41 | extern void DriveSwitch(uint8_t n_drv,enum e_switch_var s); 42 | void ToggleDriveSwitch(uint8_t m_indx); 43 | extern void MangeOutCn1(float in); 44 | extern void MangeOutCn2(float in); 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /Code/HWTest/ABM_Port.h: -------------------------------------------------------------------------------- 1 | #ifndef _ARD_PORT_ 2 | #define _ARD_PORT_ 3 | 4 | //#include "Arduino.h" 5 | #include "variant.h" 6 | #include "wiring_constants.h" 7 | #include "wiring_digital.h" 8 | #include "ABM_Cfg.h" 9 | 10 | //typedef bool boolean; 11 | 12 | #define itsc_func() 13 | 14 | #define __builtin_constant_p(x) 1 15 | 16 | #define __inline__ inline 17 | #ifndef NULL 18 | #define NULL _NULL 19 | #endif /* NULL */ 20 | 21 | //extern void yield(void); 22 | extern "C" int sysTickHook(void); 23 | void svcHook(void); 24 | void pendSVHook(void); 25 | void serialEventRun(void); 26 | 27 | //void setup(void); 28 | #ifdef __cplusplus 29 | extern "C" { 30 | #endif 31 | 32 | void init(void); 33 | void SysTick_DefaultHandler(void); 34 | 35 | #ifdef __cplusplus 36 | } 37 | #endif 38 | 39 | //void tickReset(void); 40 | //void yield(void); 41 | 42 | 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /Code/HWTest/HWTest.ino: -------------------------------------------------------------------------------- 1 | #include "Arduino.h" 2 | 3 | #include "hwtest.h" 4 | 5 | void setup() 6 | { 7 | hwTestSetup(); 8 | } 9 | 10 | void loop() 11 | { 12 | hwTestLoop(); 13 | } 14 | 15 | -------------------------------------------------------------------------------- /Code/HWTest/PID_control.h: -------------------------------------------------------------------------------- 1 | #ifndef __PID_CONTROL_H 2 | #define __PID_CONTROL_H 3 | 4 | #include 5 | #include "ABM_Port.h" 6 | 7 | class PIDe : public PID{ 8 | 9 | //friend unsigned long PID::SampleTime; 10 | 11 | public: 12 | //friend class PID; 13 | 14 | float defInput; 15 | float Input; 16 | float Output; 17 | float Setpoint; 18 | bool Enable; 19 | 20 | float f_min,f_max; 21 | int SampleTime; 22 | 23 | PIDe() : PID(&Input,&Output,&Setpoint,10,0.1,0,DIRECT){ 24 | Enable=false; 25 | defInput=1; 26 | // Input=&defInput; 27 | Setpoint=90; 28 | PositiveOutDrvSet=NULL; 29 | NegativeOutDrvSet=NULL; 30 | SetSampleTime(1500); 31 | SetOutputLimits(-100,100); 32 | }; 33 | 34 | void SetOutputLimits(float min, float max) 35 | { 36 | PID::SetOutputLimits(f_min=min,f_max=max); 37 | } 38 | 39 | void SetSampleTime(int stime) 40 | { 41 | PID::SetSampleTime(SampleTime=stime); 42 | } 43 | 44 | void SetOutputDrv(void); 45 | void (*PositiveOutDrvSet)(int); 46 | void (*NegativeOutDrvSet)(int); 47 | 48 | }; 49 | 50 | void PID_tick(void); 51 | 52 | extern PIDe PID_n1; 53 | extern PIDe PID_n2; 54 | 55 | #endif 56 | -------------------------------------------------------------------------------- /Code/HWTest/Sensors.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "ABM_Cfg.h" 3 | #include "Sensors.h" 4 | #include "storage_var.h" 5 | #include "vsd_macros.h" 6 | #include "pin_cfg.h" 7 | #include "delay.h" 8 | #include 9 | #include 10 | 11 | const int timing_ds[] = {6, 64, 60, 10, 9, 55, 0, 480, 70, 410}; 12 | //const int overdriveT[] = {1.5, 7.5, 7.5, 2.5, 0.75, 7, 2.5, 70, 8.5, 40}; 13 | 14 | uint32_t NTC1_ADC_val, NTC2_ADC_val; 15 | 16 | //uint8_t sensor1_mode=SENSOR_ONEWIRE, 17 | //uint8_t sensor2_mode=SENSOR_NTC; 18 | uint16_t sensor1_count, sensor2_count; 19 | uint8_t temp_sens1[9],temp_sens2[9]; 20 | float sensor1_fval,sensor2_fval; 21 | 22 | #define wait_us(x) delayMicroseconds(x) 23 | 24 | //****************************************************************************** 25 | void sync_ADC() { 26 | while (ADC->STATUS.bit.SYNCBUSY == 1) ; 27 | } 28 | //****************************************************************************** 29 | void writePin(PortGroup *port, uint8_t pin, uint8_t val) 30 | { 31 | if(val) port->OUTSET.reg = (uint32_t)(1<< pin); 32 | else port->OUTCLR.reg = (uint32_t)(1<< pin); 33 | } 34 | //****************************************************************************** 35 | void ADC_CannelSet(uint8_t chn) 36 | { 37 | sync_ADC(); 38 | ADC->INPUTCTRL.bit.MUXPOS = chn; 39 | } 40 | //****************************************************************************** 41 | void ADC_Enable(void) 42 | { 43 | sync_ADC(); 44 | ADC->CTRLA.bit.ENABLE = 0x01; // Enable ADC 45 | } 46 | //****************************************************************************** 47 | void ADC_FakeConversion(void) 48 | { 49 | sync_ADC(); 50 | ADC->CTRLA.bit.ENABLE = 0x01; // Enable ADC 51 | 52 | // Start conversion 53 | sync_ADC(); 54 | ADC->SWTRIG.bit.START = 1; 55 | 56 | // Clear the Data Ready flag 57 | ADC->INTFLAG.bit.RESRDY = 1; 58 | } 59 | //****************************************************************************** 60 | void ADC_StartConversion(void) 61 | { 62 | // Start conversion 63 | sync_ADC(); 64 | ADC->SWTRIG.bit.START = 1; 65 | } 66 | //****************************************************************************** 67 | uint32_t ADC_ValueRead(void) 68 | { 69 | uint32_t ret_val; 70 | while ( ADC->INTFLAG.bit.RESRDY == 0 ); // Waiting for conversion to complete 71 | ret_val = ADC->RESULT.reg; 72 | return ret_val; 73 | } 74 | //****************************************************************************** 75 | void ADC_Disable(void) 76 | { 77 | sync_ADC(); 78 | ADC->CTRLA.bit.ENABLE = 0x00; // Disable ADC 79 | sync_ADC(); 80 | } 81 | //****************************************************************************** 82 | void ADC_SetReference(void) 83 | { 84 | ADC->INPUTCTRL.bit.GAIN = ADC_INPUTCTRL_GAIN_1X_Val; // Gain Factor Selection 85 | ADC->REFCTRL.bit.REFSEL = ADC_REFCTRL_REFSEL_AREFA_Val; 86 | } 87 | //****************************************************************************** 88 | void SensorsSetup(void) 89 | { 90 | InitPin(NTC_probe1,INA); 91 | InitPin(NTC_probe2,INA); 92 | InitPin(ADC_REF,INA); 93 | ADC_SetReference(); 94 | ADC_Enable(); 95 | } 96 | //****************************************************************************** 97 | uint8_t onewire_readBit(void) 98 | { 99 | uint8_t result=0; 100 | 101 | system_interrupt_enter_critical_section(); 102 | if(_stv.HW_var.probe1_mode==SENSOR_ONEWIRE) InitPin(DSwire1,OUTL); 103 | if(_stv.HW_var.probe2_mode==SENSOR_ONEWIRE) InitPin(DSwire2,OUTL); 104 | 105 | wait_us(6/*6*//*timing[0]*/); 106 | if(_stv.HW_var.probe1_mode==SENSOR_ONEWIRE) InitPin(DSwire1,IN); 107 | if(_stv.HW_var.probe2_mode==SENSOR_ONEWIRE) InitPin(DSwire2,IN); 108 | wait_us(9/*9*//*timing[4]*/); 109 | if(_stv.HW_var.probe1_mode==SENSOR_ONEWIRE) result|=ReadPin(DSwire1); 110 | if(_stv.HW_var.probe2_mode==SENSOR_ONEWIRE) result|=ReadPin(DSwire2)<<1; 111 | system_interrupt_leave_critical_section(); 112 | 113 | return result; 114 | } 115 | //****************************************************************************** 116 | void onewire_writeBit(uint8_t bit1,uint8_t bit2) 117 | { 118 | bit1 = bit1 & 0x01; 119 | bit2 = bit2 & 0x01; 120 | uint8_t n=0,b=0; 121 | 122 | system_interrupt_enter_critical_section(); 123 | if(_stv.HW_var.probe1_mode==SENSOR_ONEWIRE) {InitPin(DSwire1,OUTL); n++;} 124 | if(_stv.HW_var.probe2_mode==SENSOR_ONEWIRE) {InitPin(DSwire2,OUTL); n++;} 125 | wait_us(6/*6*//*timing[0]*/); 126 | if((bit1!=0) && (_stv.HW_var.probe1_mode==SENSOR_ONEWIRE)) {InitPin(DSwire1,IN); b++;} 127 | if((bit2!=0) && (_stv.HW_var.probe2_mode==SENSOR_ONEWIRE)) {InitPin(DSwire2,IN); b++;} 128 | if(n==b) { 129 | system_interrupt_leave_critical_section(); 130 | return; 131 | } 132 | wait_us(60-3/*timing[2]*/); 133 | if(/*(bit1==0) && */(_stv.HW_var.probe1_mode==SENSOR_ONEWIRE)) {InitPin(DSwire1,IN);} 134 | if(/*(bit2==0) && */(_stv.HW_var.probe2_mode==SENSOR_ONEWIRE)) {InitPin(DSwire2,IN);} 135 | 136 | #if 0 137 | if (bit) 138 | { 139 | // InitPin(DSwire1,OUTL); 140 | wait_us(3/*6*//*timing[0]*/); 141 | InitPin(DSwire1,IN); 142 | } 143 | else 144 | { 145 | // InitPin(DSwire1,OUTL); 146 | wait_us(60/*timing[2]*/); 147 | InitPin(DSwire1,IN); 148 | } 149 | #endif 150 | system_interrupt_leave_critical_section(); 151 | } 152 | //****************************************************************************** 153 | void read_onewire_bit(uint8_t *data1, uint8_t *data2, uint8_t bit) 154 | { 155 | uint8_t bit_res=onewire_readBit(); 156 | (*data1)=((*data1)&~(1<>1) & 0x01)<>bit,data>>bit); 163 | } 164 | //****************************************************************************** 165 | float NTC_to_Temp(uint32_t in) 166 | { 167 | float tconv; 168 | tconv=in; 169 | // Convert value to resistance 170 | tconv = 1023 / tconv - 1; 171 | tconv = NTC_PULL_RESISTOR / tconv; 172 | 173 | //Calculate temperature using the Beta Factor equation 174 | float temperatura; 175 | temperatura = tconv / NTC_RESISTANCE; // (R/Ro) 176 | temperatura = log(temperatura); // ln(R/Ro) 177 | temperatura /= BCOEFFICIENT; // 1/B * ln(R/Ro) 178 | temperatura += 1.0 / (TEMPERATURENOMINAL + 273.15); // + (1/To) 179 | temperatura = 1.0 / temperatura; // Invert the value 180 | temperatura -= 273.15; // Convert it to Celsius 181 | if (_stv.UnitPar.temper_unit == T_CELSIUS) 182 | return temperatura; 183 | else 184 | return CELSIUS_TO_FAHRENHEIT(temperatura); 185 | } 186 | 187 | /* Convert a raw value read from DS18B20 to a temperature value 188 | * Parameters: 189 | * - in: raw 16-bit value read from DS18B20 190 | * Returns: temperature value, in either Celsius or Fahrenheit depending on the 191 | * current user setting 192 | */ 193 | float DS18B20_Temp(uint16_t in) 194 | { 195 | float val; 196 | 197 | val = in >> 4; 198 | val += (double)(in & 0x0f) * 0.0625; 199 | if (_stv.UnitPar.temper_unit == T_CELSIUS) 200 | return val; 201 | else 202 | return CELSIUS_TO_FAHRENHEIT(val); 203 | } 204 | //****************************************************************************** 205 | void MathSensorsValues(void) 206 | { 207 | uint16_t tsens; 208 | if(_stv.HW_var.probe1_mode==SENSOR_ONEWIRE) { 209 | sensor1_fval = DS18B20_Temp(*((uint16_t*)temp_sens1)); 210 | } 211 | if(_stv.HW_var.probe2_mode==SENSOR_ONEWIRE) { 212 | sensor2_fval = DS18B20_Temp(*((uint16_t*)temp_sens2)); 213 | } 214 | if(_stv.HW_var.probe1_mode==SENSOR_NTC) { 215 | sensor1_fval=NTC_to_Temp(NTC1_ADC_val); 216 | } 217 | if(_stv.HW_var.probe2_mode==SENSOR_NTC) { 218 | sensor2_fval=NTC_to_Temp(NTC2_ADC_val); 219 | } 220 | } 221 | //****************************************************************************** 222 | void SensorTick(void) 223 | { 224 | if((_stv.HW_var.probe1_mode!=SENSOR_OFF) || (_stv.HW_var.probe2_mode!=SENSOR_OFF)) 225 | { 226 | sensor1_count++; 227 | if(sensor1_count>=_stv.ProcPar.s_time) sensor1_count=0; 228 | { 229 | if(sensor1_count==0) { 230 | if(_stv.HW_var.probe1_mode==SENSOR_ONEWIRE) InitPin(DSwire1,IN); 231 | if(_stv.HW_var.probe2_mode==SENSOR_ONEWIRE) InitPin(DSwire2,IN); 232 | } 233 | else if(sensor1_count==1) { 234 | if(_stv.HW_var.probe1_mode==SENSOR_NTC) { 235 | InitPin(DSwire1,IN); InitPin(NTC_probe1,INA); // Prepare conversion for NTC1 236 | ADC_CannelSet(NTC_ADC_CH_probe1); ADC_FakeConversion(); 237 | } 238 | } 239 | else if(sensor1_count==2) { 240 | if(_stv.HW_var.probe1_mode==SENSOR_NTC) ADC_StartConversion(); // Start conversion for NTC1 241 | } 242 | else if(sensor1_count>=3 && sensor1_count<11) {write_onewire_bit(SKIP_ROM,(sensor1_count-3));} 243 | else if(sensor1_count>=11 && sensor1_count<19) {write_onewire_bit(0x44,(sensor1_count-11));} 244 | 245 | else if(sensor1_count==100) { 246 | if(_stv.HW_var.probe1_mode==SENSOR_NTC) NTC1_ADC_val=ADC_ValueRead(); // Get conversion from NTC1 probe 247 | if(_stv.HW_var.probe2_mode==SENSOR_NTC) 248 | InitPin(DSwire2,IN); InitPin(NTC_probe2,INA); // Prepare conversion for NTC1 249 | ADC_CannelSet(NTC_ADC_CH_probe2); ADC_FakeConversion(); 250 | } 251 | else if(sensor1_count==101) { 252 | if(_stv.HW_var.probe2_mode==SENSOR_NTC) ADC_StartConversion(); // Start conversion for NTC2 253 | } 254 | else if(sensor1_count==200) { 255 | if(_stv.HW_var.probe2_mode==SENSOR_NTC) NTC2_ADC_val=ADC_ValueRead(); // Get conversion from NTC2 probe 256 | } 257 | else if(sensor1_count==899) { 258 | if(_stv.HW_var.probe1_mode==SENSOR_ONEWIRE) InitPin(DSwire1,OUTL); 259 | if(_stv.HW_var.probe2_mode==SENSOR_ONEWIRE) InitPin(DSwire2,OUTL); 260 | } 261 | else if(sensor1_count==900) { 262 | if(_stv.HW_var.probe1_mode==SENSOR_ONEWIRE) InitPin(DSwire1,IN); 263 | if(_stv.HW_var.probe2_mode==SENSOR_ONEWIRE) InitPin(DSwire2,IN); 264 | } 265 | else if(sensor1_count>=902 && sensor1_count<910) {write_onewire_bit(SKIP_ROM,(sensor1_count-902));} 266 | else if(sensor1_count>=910 && sensor1_count<918) {write_onewire_bit(0xBE,(sensor1_count-910));} 267 | else if(sensor1_count>=920 && sensor1_count<992) { 268 | int bit_offs=sensor1_count-920; 269 | read_onewire_bit((uint8_t*)&temp_sens1[bit_offs/8],(uint8_t*)&temp_sens2[bit_offs/8],bit_offs%8); 270 | } 271 | else if(sensor1_count==992){ 272 | MathSensorsValues(); 273 | } 274 | else if(sensor1_count==999) { 275 | if(_stv.HW_var.probe1_mode==SENSOR_ONEWIRE) InitPin(DSwire1,OUTL); 276 | if(_stv.HW_var.probe2_mode==SENSOR_ONEWIRE) InitPin(DSwire2,OUTL); 277 | } 278 | 279 | } 280 | } 281 | } 282 | 283 | -------------------------------------------------------------------------------- /Code/HWTest/Sensors.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Code/HWTest/Sensors.h -------------------------------------------------------------------------------- /Code/HWTest/SmartPID_logo_1bit.c: -------------------------------------------------------------------------------- 1 | 2 | unsigned char SmartPID_128x39_1bit_horiz [] = { 3 | 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 4 | 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 5 | 0x00, 0x00, 0x0A, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 6 | 0x00, 0x00, 0x0B, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 7 | 0x00, 0x00, 0x09, 0x14, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 8 | 0x00, 0x00, 0x09, 0x14, 0x20, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 9 | 0x00, 0x00, 0x09, 0x14, 0x50, 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 10 | 0x00, 0x00, 0x09, 0x14, 0xD1, 0x23, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 11 | 0x00, 0x00, 0x09, 0x16, 0x99, 0x24, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 12 | 0x00, 0x00, 0x09, 0xB2, 0x89, 0x18, 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xE0, 13 | 0x00, 0x00, 0x08, 0xA2, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 14 | 0x0F, 0xFE, 0x08, 0xA2, 0x89, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0x06, 0x3F, 0xFF, 0x84, 15 | 0x1F, 0xFE, 0x08, 0xA3, 0x86, 0x00, 0x00, 0x00, 0x00, 0x00, 0x7F, 0xFF, 0x86, 0x3F, 0xFF, 0xE4, 16 | 0x38, 0x00, 0x08, 0xE1, 0x04, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x01, 0xC6, 0x30, 0x00, 0xF2, 17 | 0x70, 0x00, 0x08, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0xC6, 0x30, 0x00, 0x32, 18 | 0x60, 0x00, 0x08, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0xC6, 0x30, 0x00, 0x3A, 19 | 0x60, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x60, 0x60, 0x00, 0xC6, 0x30, 0x00, 0x1A, 20 | 0x70, 0x00, 0x08, 0x7E, 0x1F, 0x80, 0xFF, 0xC1, 0xBD, 0xFE, 0x60, 0x00, 0xC6, 0x30, 0x00, 0x1A, 21 | 0x38, 0x00, 0x0A, 0xFF, 0x3F, 0xC0, 0xFF, 0xE1, 0xFD, 0xFE, 0x60, 0x01, 0xC6, 0x30, 0x00, 0x1A, 22 | 0x1F, 0xFF, 0x8B, 0xC3, 0xF0, 0xE0, 0x00, 0x71, 0xE0, 0x60, 0x6F, 0xFF, 0x86, 0x30, 0x00, 0x1A, 23 | 0x0F, 0xFF, 0xCB, 0x81, 0xE0, 0x60, 0x00, 0x31, 0xC0, 0x60, 0x6F, 0xFF, 0x06, 0x30, 0x00, 0x1A, 24 | 0x00, 0x00, 0xEB, 0x00, 0xC0, 0x60, 0x00, 0x31, 0x80, 0x60, 0x60, 0x00, 0x06, 0x30, 0x00, 0x1A, 25 | 0x00, 0x00, 0x6B, 0x00, 0xC0, 0x61, 0xFF, 0xF1, 0x80, 0x60, 0x60, 0x00, 0x06, 0x30, 0x00, 0x1A, 26 | 0x00, 0x00, 0x6B, 0x00, 0xC0, 0x63, 0xFF, 0xF1, 0x80, 0x60, 0x60, 0x00, 0x06, 0x30, 0x00, 0x1A, 27 | 0x00, 0x00, 0x6B, 0x00, 0xC0, 0x67, 0x00, 0x31, 0x80, 0x60, 0x60, 0x00, 0x06, 0x30, 0x00, 0x3A, 28 | 0x00, 0x00, 0x6B, 0x00, 0xC0, 0x66, 0x00, 0x31, 0x80, 0x60, 0x60, 0x00, 0x06, 0x30, 0x00, 0x32, 29 | 0x00, 0x01, 0xEB, 0x00, 0xC0, 0x67, 0x01, 0xF1, 0x80, 0x60, 0x60, 0x00, 0x06, 0x30, 0x00, 0xF2, 30 | 0x7F, 0xFF, 0xCB, 0x00, 0xC0, 0x63, 0xFF, 0xF1, 0x80, 0x60, 0x60, 0x00, 0x06, 0x3F, 0xFF, 0xE2, 31 | 0x7F, 0xFF, 0x0B, 0x00, 0xC0, 0x61, 0xFF, 0x31, 0x80, 0x60, 0x60, 0x00, 0x06, 0x3F, 0xFF, 0x82, 32 | 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 33 | 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 34 | 0x00, 0x00, 0x08, 0x78, 0x78, 0x44, 0x7C, 0x78, 0x78, 0x40, 0x81, 0xF3, 0xC0, 0x01, 0x00, 0x02, 35 | 0x00, 0x00, 0x08, 0x80, 0x84, 0x64, 0x10, 0x44, 0x84, 0x40, 0x81, 0x02, 0x20, 0x02, 0x80, 0x02, 36 | 0x00, 0x00, 0x10, 0x80, 0x84, 0x54, 0x10, 0x44, 0x84, 0x40, 0x81, 0x02, 0x20, 0x04, 0x40, 0x04, 37 | 0x00, 0x3F, 0xE0, 0x80, 0x84, 0x54, 0x10, 0x78, 0x84, 0x40, 0x81, 0xF3, 0xC7, 0xF8, 0x43, 0xF8, 38 | 0x00, 0x00, 0x00, 0x80, 0x84, 0x54, 0x10, 0x50, 0x84, 0x40, 0x81, 0x02, 0x80, 0x00, 0x44, 0x00, 39 | 0x00, 0x00, 0x00, 0x80, 0x84, 0x4C, 0x10, 0x48, 0x84, 0x40, 0x81, 0x02, 0x40, 0x00, 0x28, 0x00, 40 | 0x00, 0x00, 0x00, 0x78, 0x78, 0x44, 0x10, 0x44, 0x78, 0x7C, 0xF9, 0xF2, 0x20, 0x00, 0x28, 0x00, 41 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00 42 | }; 43 | -------------------------------------------------------------------------------- /Code/HWTest/WiFi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * WiFi.cpp 3 | * 4 | * Wi-Fi communication manager 5 | */ 6 | 7 | #include 8 | #include 9 | #include "ABM_Cfg.h" 10 | #include "storage_var.h" 11 | #include "WiFi.h" 12 | 13 | /* Intervals expressed in milliseconds */ 14 | #define WIFI_STATUS_UPDATE_INTERVAL 10000 15 | #define WIFI_CONNECT_ATTEMPT_INTERVAL 30000 16 | 17 | /* Number of failed connection attempts in automatic mode before Wi-Fi network 18 | * information is reset and the controller is rebooted. */ 19 | #define WIFI_AUTO_CONN_RETRIES 3 20 | 21 | #define WIFI_SERVER_PORT 80 22 | 23 | enum wifi_async_resp { 24 | WIFI_ASYNC_NONE, 25 | WIFI_ASYNC_GENERIC, 26 | WIFI_ASYNC_CONNECT, 27 | WIFI_ASYNC_DHCP_STA, 28 | WIFI_ASYNC_SET_AP, 29 | WIFI_ASYNC_SET_DHCP_AP, 30 | WIFI_ASYNC_IP_ADDR, 31 | WIFI_ASYNC_DISCONNECT, 32 | WIFI_ASYNC_STATUS, 33 | }; 34 | 35 | static struct { 36 | int mode; 37 | unsigned int failedConns; 38 | const char *ssid, *pwd; 39 | IPAddress IPaddr; 40 | volatile int asyncResp; 41 | unsigned long lastStatusUpdate, lastConnectAttempt; 42 | } wifiPriv; 43 | 44 | /* Check for a response to a command previously sent to ESP8266 45 | * Parameters: none 46 | * Returns: none 47 | */ 48 | static void checkAsyncResp() { 49 | int16_t resp = esp8266.checkAsyncResp(); 50 | 51 | if (!resp) 52 | return; 53 | switch (wifiPriv.asyncResp) { 54 | case WIFI_ASYNC_GENERIC: 55 | wifiPriv.asyncResp = WIFI_ASYNC_NONE; 56 | break; 57 | case WIFI_ASYNC_CONNECT: 58 | if (resp > 0) { 59 | wifiPriv.asyncResp = WIFI_ASYNC_DHCP_STA; 60 | esp8266.setDHCP(ESP8266_MODE_STA, true, true); 61 | } else { 62 | wifiPriv.asyncResp = WIFI_ASYNC_NONE; 63 | wifiPriv.lastConnectAttempt = millis(); 64 | wifiPriv.failedConns++; 65 | if ((wifiPriv.mode == WiFi::MODE_AUTO) 66 | && (wifiPriv.failedConns == WIFI_AUTO_CONN_RETRIES)) { 67 | StvResetWiFiNwk(); 68 | wiFi.reset(); 69 | NVIC_SystemReset(); 70 | } 71 | } 72 | break; 73 | case WIFI_ASYNC_DHCP_STA: 74 | wiFi.staStatus = WiFi::STATUS_CONNECTED; 75 | wifiPriv.asyncResp = WIFI_ASYNC_NONE; 76 | break; 77 | case WIFI_ASYNC_SET_AP: 78 | wifiPriv.asyncResp = WIFI_ASYNC_SET_DHCP_AP; 79 | esp8266.setDHCP(ESP8266_MODE_AP, true, true); 80 | break; 81 | case WIFI_ASYNC_SET_DHCP_AP: 82 | wiFi.status = WiFi::STATUS_AP; 83 | wifiPriv.asyncResp = WIFI_ASYNC_NONE; 84 | break; 85 | case WIFI_ASYNC_IP_ADDR: 86 | if (resp > 0) 87 | wifiPriv.IPaddr = esp8266.localIPFromResp(); 88 | wifiPriv.asyncResp = WIFI_ASYNC_NONE; 89 | break; 90 | case WIFI_ASYNC_DISCONNECT: 91 | wifiPriv.asyncResp = WIFI_ASYNC_GENERIC; 92 | esp8266.setMode(ESP8266_MODE_STA, true); 93 | break; 94 | case WIFI_ASYNC_STATUS: 95 | if (resp > 0) { 96 | enum esp8266_connect_status status = 97 | (enum esp8266_connect_status) esp8266.statusFromResp(); 98 | 99 | if (status == ESP8266_STATUS_NOWIFI) { 100 | wiFi.staStatus = WiFi::STATUS_DISCONNECTED; 101 | wifiPriv.IPaddr = INADDR_NONE; 102 | } 103 | } 104 | wifiPriv.asyncResp = WIFI_ASYNC_NONE; 105 | break; 106 | } 107 | } 108 | 109 | WiFi wiFi; 110 | ESP8266Client wiFiClient; 111 | ESP8266Server wiFiServer(WIFI_SERVER_PORT); 112 | 113 | WiFi::WiFi() { 114 | client = &wiFiClient; 115 | server = &wiFiServer; 116 | wifiPriv.asyncResp = WIFI_ASYNC_NONE; 117 | } 118 | 119 | int WiFi::init(uint32_t baud) { 120 | uint8_t serNoBuf[NVMCTRL_PAGE_SIZE]; 121 | uint8_t *serNoPtr = 122 | serNoBuf + (HW_SERIAL_NUM_ADDR & (NVMCTRL_PAGE_SIZE - 1)); 123 | 124 | nvm_read_buffer(HW_SERIAL_NUM_ADDR & ~(NVMCTRL_PAGE_SIZE - 1), serNoBuf, 125 | sizeof(serNoBuf)); 126 | sprintf(own_ssid, "SPC1000_%02X%02X%02X%02X%02X%02X%02X", serNoPtr[1], 127 | serNoPtr[2], serNoPtr[3], serNoPtr[4], serNoPtr[5], serNoPtr[6], 128 | serNoPtr[7]); 129 | if (esp8266.begin(Serial1, baud) == true) 130 | { 131 | status = STATUS_OFF; 132 | } 133 | else if (esp8266.begin(Serial1, 9600) || esp8266.begin(Serial1, 19200) 134 | || esp8266.begin(Serial1, 38400)|| esp8266.begin(Serial1, 57600) 135 | || esp8266.begin(Serial1, 115200)) { 136 | esp8266.setBaud(baud); 137 | delay(10); 138 | esp8266.begin(Serial1, baud); 139 | status = STATUS_OFF; 140 | } 141 | else 142 | status = STATUS_NA; 143 | return status; 144 | } 145 | 146 | void WiFi::config(int mode, const char *ssid, const char *pwd) { 147 | switch (mode) { 148 | case MODE_OFF: 149 | status = STATUS_OFF; 150 | while (esp8266.disconnect(true) == ESP8266_CMD_BUSY) {} 151 | wifiPriv.asyncResp = WIFI_ASYNC_DISCONNECT; 152 | break; 153 | case MODE_STA: 154 | configSta(ssid, pwd); 155 | break; 156 | case MODE_AP: 157 | configAP(); 158 | break; 159 | case MODE_AUTO: 160 | if (*ssid && *pwd) { 161 | configSta(ssid, pwd); 162 | } else { 163 | configAP(); 164 | } 165 | break; 166 | default: 167 | return; 168 | } 169 | wifiPriv.mode = mode; 170 | wifiPriv.failedConns = 0; 171 | wifiPriv.IPaddr = INADDR_NONE; 172 | } 173 | 174 | void WiFi::configSta(const char *ssid, const char *pwd) { 175 | wifiPriv.ssid = ssid; 176 | wifiPriv.pwd = pwd; 177 | while (esp8266.setMode(ESP8266_MODE_STA) == ESP8266_CMD_BUSY) {} 178 | while (esp8266.connect(ssid, pwd, true) == ESP8266_CMD_BUSY) {} 179 | status = STATUS_STA; 180 | staStatus = STATUS_DISCONNECTED; 181 | wifiPriv.asyncResp = WIFI_ASYNC_CONNECT; 182 | } 183 | 184 | 185 | void WiFi::configAP(void) { 186 | char cur_ssid[SSID_MAX_LEN + 1]; /* null-terminated string */ 187 | char cur_pwd[PWD_MAX_LEN + 1]; /* null-terminated string */ 188 | 189 | while (esp8266.setMode(ESP8266_MODE_AP) == ESP8266_CMD_BUSY) {} 190 | while (esp8266.getAPConfig(cur_ssid, cur_pwd) == ESP8266_CMD_BUSY) {} 191 | if (strcmp(cur_ssid, own_ssid) || strcmp(cur_pwd, WIFI_OWN_PWD)) { 192 | while (esp8266.configAP(own_ssid, WIFI_OWN_PWD, true) 193 | == ESP8266_CMD_BUSY) {} 194 | wifiPriv.asyncResp = WIFI_ASYNC_SET_AP; 195 | } else { 196 | wifiPriv.asyncResp = WIFI_ASYNC_SET_DHCP_AP; 197 | } 198 | } 199 | 200 | IPAddress WiFi::getIP() { 201 | return wifiPriv.IPaddr; 202 | } 203 | 204 | int WiFi::getSSID(char *buf) { 205 | if (status == STATUS_STA) 206 | strcpy(buf, wifiPriv.ssid); 207 | else if (status == STATUS_AP) 208 | strcpy(buf, own_ssid); 209 | else 210 | return -1; 211 | return 0; 212 | } 213 | 214 | int WiFi::getPwd(char *buf) { 215 | if (status == STATUS_STA) 216 | strcpy(buf, wifiPriv.pwd); 217 | else if (status == STATUS_AP) 218 | strcpy(buf, WIFI_OWN_PWD); 219 | else 220 | return -1; 221 | return 0; 222 | } 223 | 224 | void WiFi::setServerPort(uint16_t port) { 225 | wiFiServer = ESP8266Server(port); 226 | } 227 | 228 | void WiFi::reset() 229 | { 230 | esp8266.reset(false); 231 | } 232 | 233 | void WiFi::tick() 234 | { 235 | /* Check if communication with ESP8266 is ongoing. */ 236 | if (wifiPriv.asyncResp == WIFI_ASYNC_NONE) { 237 | if ((status == STATUS_STA) && (staStatus == STATUS_DISCONNECTED) 238 | && (millis() - wifiPriv.lastConnectAttempt 239 | >= WIFI_CONNECT_ATTEMPT_INTERVAL)) { 240 | /* Retry to connect to the access point */ 241 | if (esp8266.connect(wifiPriv.ssid, wifiPriv.pwd, true) 242 | == ESP8266_RSP_SUCCESS) 243 | wifiPriv.asyncResp = WIFI_ASYNC_CONNECT; 244 | } else if ((status == STATUS_STA) && (staStatus == STATUS_CONNECTED) 245 | && (millis() - wifiPriv.lastStatusUpdate 246 | >= WIFI_STATUS_UPDATE_INTERVAL)) { 247 | /* Check if still connected. */ 248 | if (esp8266.updateStatus(true) == ESP8266_RSP_SUCCESS) { 249 | wifiPriv.asyncResp = WIFI_ASYNC_STATUS; 250 | wifiPriv.lastStatusUpdate = millis(); 251 | } 252 | } else if ((((status == STATUS_STA) && (staStatus == STATUS_CONNECTED)) 253 | || (status == STATUS_AP)) && (wifiPriv.IPaddr == INADDR_NONE)) { 254 | /* Retrieve local IP address */ 255 | if ((uint32_t) esp8266.localIP(true) == ESP8266_RSP_SUCCESS) 256 | wifiPriv.asyncResp = WIFI_ASYNC_IP_ADDR; 257 | } 258 | } 259 | if (wifiPriv.asyncResp) 260 | checkAsyncResp(); 261 | } 262 | void WiFiTick() 263 | { 264 | wiFi.tick(); 265 | } 266 | -------------------------------------------------------------------------------- /Code/HWTest/WiFi.h: -------------------------------------------------------------------------------- 1 | /* 2 | * WiFi.h 3 | * 4 | * Wi-Fi communication manager 5 | */ 6 | 7 | #ifndef WIFI_H_ 8 | #define WIFI_H_ 9 | 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #define WIFI_OWN_PWD "smartpid!" 16 | 17 | class WiFi { 18 | public: 19 | static const int BAUD_RATE_DEFAULT = 57600; 20 | static const int SSID_MAX_LEN = 32; 21 | static const int PWD_MAX_LEN = 63; 22 | enum { 23 | MODE_OFF, 24 | MODE_STA, 25 | MODE_AP, 26 | 27 | /* Automatic mode means station mode if parameters for connecting to an 28 | * access point are configured correctly, access point mode otherwise. 29 | */ 30 | MODE_AUTO, 31 | }; 32 | enum { 33 | STATUS_NA, /* Wi-Fi not available */ 34 | STATUS_OFF, 35 | STATUS_STA, 36 | STATUS_AP, 37 | } status; 38 | enum { 39 | STATUS_DISCONNECTED, 40 | STATUS_CONNECTED, 41 | } staStatus; 42 | AsyncClient *client; 43 | ESP8266Server *server; 44 | WiFi(); 45 | 46 | /* Initialize the Wi-Fi interface 47 | * Parameters: 48 | * - baud: baud rate for communication with Wi-Fi module 49 | * Returns: WiFi interface status (STATUS_* enum values) 50 | */ 51 | int init(uint32_t baud); 52 | 53 | /* Configure the Wi-Fi interface 54 | * Parameters: 55 | * - mode: Wi-Fi mode (MODE_* enum values) 56 | * - ssid: SSID of the access point to connect to (used only in MODE_STA and 57 | * MODE_AUTO 58 | * - pwd: password of the access point to connect to (used only in MODE_STA 59 | * and MODE_AUTO 60 | * Returns: none 61 | */ 62 | void config(int mode, const char *ssid, const char *pwd); 63 | 64 | /* Configure the Wi-Fi interface in station mode and connect to an access 65 | * point 66 | * Parameters: 67 | * - ssid: SSID of the access point to connect to 68 | * - pwd: password of the access point to connect to 69 | * Returns: none 70 | */ 71 | void configSta(const char *ssid, const char *pwd); 72 | 73 | /* Configure the Wi-Fi interface in access point mode 74 | * The SSID of the access point is built from the device serial number, 75 | * while the password is hard-coded. 76 | * Parameters: none 77 | * Returns: none 78 | */ 79 | void configAP(void); 80 | 81 | /* Get the IP address of the Wi-Fi interface 82 | * Parameters: none 83 | * Returns: IP address of the Wi-Fi interface (INADDR_NONE if no IP address 84 | * has been assigned to the interfaces) 85 | */ 86 | IPAddress getIP(); 87 | 88 | /* Get the SSID of the Wi-Fi interface. 89 | * If the interface is in station mode, this method returns the SSID of the 90 | * access point the interface is connected (or trying to connect) to; if the 91 | * interface is in access point mode, this method returns the interface's 92 | * own SSID. 93 | * Parameters: 94 | * - buf: Buffer where the returned SSID is stored 95 | * Returns: 0 if the interface is in either station or access point mode, a 96 | * negative value otherwise (in which case nothing is copied to the input 97 | * buffer) 98 | */ 99 | int getSSID(char *buf); 100 | 101 | /* Get the password of the Wi-Fi interface. 102 | * If the interface is in station mode, this method returns the password of 103 | * the access point the interface is connected (or trying to connect) to; if 104 | * the interface is in access point mode, this method returns the 105 | * interface's own password. 106 | * Parameters: 107 | * - buf: Buffer where the returned password is stored 108 | * Returns: 0 if the interface is in either station or access point mode, a 109 | * negative value otherwise (in which case nothing is copied to the input 110 | * buffer) 111 | */ 112 | int getPwd(char *buf); 113 | 114 | /* Set the port at which the TCP server will be listening 115 | * This method can be called to customize the server port before starting 116 | * the server with a call to ESP8266Server::begin() or 117 | * ESP8266Server::begin_check(). 118 | * Parameters: 119 | * - port: TPC port number 120 | * Returns: none 121 | */ 122 | void setServerPort(uint16_t port); 123 | 124 | /* Reset the Wi-Fi interface 125 | * Calling this method is equivalent to doing a hardware reset on the Wi-Fi 126 | * module. 127 | * Parameters: none 128 | * Returns: none 129 | */ 130 | void reset(); 131 | 132 | /* Method to be called periodically, that manages the Wi-Fi interface 133 | * This method is called by the WiFiTick() function. 134 | * Parameters: none 135 | * Returns: none 136 | */ 137 | void tick(); 138 | 139 | private: 140 | char own_ssid[SSID_MAX_LEN + 1]; /* null-terminated string */ 141 | }; 142 | 143 | extern WiFi wiFi; 144 | 145 | /* Function to be called periodically, that manages the Wi-Fi interface 146 | * Parameters: none 147 | * Returns: none 148 | */ 149 | void WiFiTick(); 150 | 151 | #endif /* WIFI_H_ */ 152 | -------------------------------------------------------------------------------- /Code/HWTest/delay.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include "delay.h" 20 | #include "Arduino.h" 21 | #include "vsd_macros.h" 22 | #include "PID_control.h" 23 | #include "WiFi.h" 24 | 25 | extern void frame_buffer_refresh(void); 26 | extern void buttons_tick(void); 27 | extern void tickBuzzer(void); 28 | extern void tickDrivers(void); 29 | extern void SensorTick(void); 30 | extern void SmallLogTick(void); 31 | extern void DownTimersHandler(void); 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | 38 | /** Tick Counter united by ms */ 39 | static volatile uint32_t _ulTickCount=0 ; 40 | volatile uint32_t _seconds_timer=0 ; 41 | 42 | uint32_t millis( void ) 43 | { 44 | // todo: ensure no interrupts 45 | return _ulTickCount ; 46 | } 47 | 48 | // Interrupt-compatible version of micros 49 | // Theory: repeatedly take readings of SysTick counter, millis counter and SysTick interrupt pending flag. 50 | // When it appears that millis counter and pending is stable and SysTick hasn't rolled over, use these 51 | // values to calculate micros. If there is a pending SysTick, add one to the millis counter in the calculation. 52 | uint32_t micros( void ) 53 | { 54 | uint32_t ticks, ticks2; 55 | uint32_t pend, pend2; 56 | uint32_t count, count2; 57 | 58 | ticks2 = SysTick->VAL; 59 | pend2 = !!(SCB->ICSR & SCB_ICSR_PENDSTSET_Msk) ; 60 | count2 = _ulTickCount ; 61 | 62 | do 63 | { 64 | ticks=ticks2; 65 | pend=pend2; 66 | count=count2; 67 | ticks2 = SysTick->VAL; 68 | pend2 = !!(SCB->ICSR & SCB_ICSR_PENDSTSET_Msk) ; 69 | count2 = _ulTickCount ; 70 | } while ((pend != pend2) || (count != count2) || (ticks < ticks2)); 71 | 72 | return ((count+pend) * 1000) + (((SysTick->LOAD - ticks)*(1048576/(VARIANT_MCK/1000000)))>>20) ; 73 | // this is an optimization to turn a runtime division into two compile-time divisions and 74 | // a runtime multiplication and shift, saving a few cycles 75 | } 76 | 77 | void delay( uint32_t ms ) 78 | { 79 | if ( ms == 0 ) 80 | { 81 | return ; 82 | } 83 | 84 | uint32_t start = _ulTickCount ; 85 | 86 | do 87 | { 88 | yield(); 89 | } while ( _ulTickCount - start < ms ) ; 90 | } 91 | 92 | #include "Reset.h" // for tickReset() 93 | 94 | void SysTick_DefaultHandler(void) 95 | { 96 | // Increment tick count each ms 97 | WritePin_dir(PORT_A,13,1); 98 | _ulTickCount++; 99 | frame_buffer_refresh(); 100 | buttons_tick(); 101 | tickBuzzer(); 102 | tickDrivers(); 103 | SensorTick(); 104 | WiFiTick(); 105 | tickReset(); 106 | 107 | WritePin_dir(PORT_A,13,0); 108 | } 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | -------------------------------------------------------------------------------- /Code/HWTest/delay.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2015 Arduino LLC. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _DELAY_ 20 | #define _DELAY_ 21 | 22 | #include 23 | #include "variant.h" 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | /** 30 | * \brief Returns the number of milliseconds since the Arduino board began running the current program. 31 | * 32 | * This number will overflow (go back to zero), after approximately 50 days. 33 | * 34 | * \return Number of milliseconds since the program started (uint32_t) 35 | */ 36 | extern uint32_t millis( void ) ; 37 | 38 | /** 39 | * \brief Returns the number of microseconds since the Arduino board began running the current program. 40 | * 41 | * This number will overflow (go back to zero), after approximately 70 minutes. On 16 MHz Arduino boards 42 | * (e.g. Duemilanove and Nano), this function has a resolution of four microseconds (i.e. the value returned is 43 | * always a multiple of four). On 8 MHz Arduino boards (e.g. the LilyPad), this function has a resolution 44 | * of eight microseconds. 45 | * 46 | * \note There are 1,000 microseconds in a millisecond and 1,000,000 microseconds in a second. 47 | */ 48 | extern uint32_t micros( void ) ; 49 | 50 | /** 51 | * \brief Pauses the program for the amount of time (in miliseconds) specified as parameter. 52 | * (There are 1000 milliseconds in a second.) 53 | * 54 | * \param dwMs the number of milliseconds to pause (uint32_t) 55 | */ 56 | extern void delay( uint32_t dwMs ) ; 57 | 58 | /** 59 | * \brief Pauses the program for the amount of time (in microseconds) specified as parameter. 60 | * 61 | * \param dwUs the number of microseconds to pause (uint32_t) 62 | */ 63 | #if defined(__ICCARM__) 64 | static __inline__ void delayMicroseconds( uint32_t ); 65 | #else 66 | static __inline__ void delayMicroseconds( uint32_t ) __attribute__((always_inline, unused)) ; 67 | #endif 68 | static __inline__ void delayMicroseconds( uint32_t usec ) 69 | { 70 | if ( usec == 0 ) 71 | { 72 | return ; 73 | } 74 | 75 | /* 76 | * The following loop: 77 | * 78 | * for (; ul; ul--) { 79 | * __asm__ volatile(""); 80 | * } 81 | * 82 | * produce the following assembly code: 83 | * 84 | * loop: 85 | * subs r3, #1 // 1 Core cycle 86 | * bne.n loop // 1 Core cycle + 1 if branch is taken 87 | */ 88 | 89 | // VARIANT_MCK / 1000000 == cycles needed to delay 1uS 90 | // 3 == cycles used in a loop 91 | uint32_t n = usec * (VARIANT_MCK / 1000000) / 3; 92 | #if defined(__ICCARM__) 93 | // n/=3; 94 | n--; 95 | __asm volatile( "MOV R0, %0\n\t" ::"r"(n)); 96 | __asm volatile //("mov r0, (n) \n" 97 | ("loop: subs r0, #1 \n" 98 | " bhi loop \n"); 99 | #else 100 | #ifndef _Windows 101 | __asm__ __volatile__( 102 | "1: \n" 103 | " sub %0, #1 \n" // substract 1 from %0 (n) 104 | " bne 1b \n" // if result is not 0 jump to 1 105 | : "+r" (n) // '%0' is n variable with RW constraints 106 | : // no input 107 | : // no clobber 108 | ); 109 | #endif 110 | #endif 111 | // https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html 112 | // https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#Volatile 113 | } 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | #endif /* _DELAY_ */ 120 | -------------------------------------------------------------------------------- /Code/HWTest/hwTest.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Code/HWTest/hwTest.cpp -------------------------------------------------------------------------------- /Code/HWTest/hwTest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * SmartPID Controller hardware diagnostic tool 3 | * 4 | * Copyright (C) 2016 Arzaman 5 | */ 6 | 7 | #ifndef HWTEST_H_ 8 | #define HWTEST_H_ 9 | 10 | /* Initialize the diagnostic task 11 | * This function is called at the start of firmware execution. 12 | * Parameters: none 13 | * Returns: none 14 | */ 15 | void hwTestSetup(); 16 | 17 | /* Process the diagnostic task 18 | * This function is called repeatedly (with no specified periodicity) during 19 | * firmware execution; its task is display a graphical user interface and accept 20 | * user input to perform diagnostic tests on hardware components. 21 | * Parameters: none 22 | * Returns: none 23 | */ 24 | void hwTestLoop(void); 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /Code/HWTest/pin_cfg.h: -------------------------------------------------------------------------------- 1 | #ifndef __PIN_CFG_H 2 | #define __PIN_CFG_H 3 | 4 | //#define DSwire1 A,9,IN 5 | //#define DSwire2 A,8,IN 6 | #define DSwire1 PORT_A,9 7 | #define DSwire2 PORT_A,8 8 | 9 | #define NTC_probe1 PORT_B,8 10 | #define NTC_probe2 PORT_B,9 11 | #define ADC_REF PORT_A,3 12 | 13 | 14 | //#define DSwire1_pin PORT_A,9 15 | 16 | 17 | #endif 18 | -------------------------------------------------------------------------------- /Code/HWTest/run_mode.h: -------------------------------------------------------------------------------- 1 | #ifndef _RUN_MODE_H_ 2 | #define _RUN_MODE_H_ 3 | 4 | enum e_trig_direct{ 5 | TRD_HEAT, 6 | TRD_COOL 7 | }; 8 | 9 | enum e_trig_timer{ 10 | TRG_STOP, 11 | TRG_WAIT_TEMP_HOLD, 12 | TRG_TEMP_HOLD_Mess, 13 | TRG_TEMP_HOLD, 14 | TRG_TIME_COMPLETE_Mess, 15 | TRG_TIME_COMPLETE, 16 | TRG_TEMP_PRESET_Mess, 17 | TRG_TO_HEATER, 18 | TRG_TO_COOLING 19 | }; 20 | 21 | struct sDT{ 22 | uint8_t state; 23 | uint8_t direct; 24 | float themp_prev; 25 | float themp_min; 26 | float themp_max; 27 | }; 28 | 29 | 30 | struct sProcStat{ 31 | uint8_t contr_pos; 32 | uint8_t contr_mode; 33 | uint8_t mult_contr; 34 | uint8_t enable; 35 | }; 36 | 37 | void RunBgTasks(void); 38 | void StopProcess(void); 39 | 40 | extern struct sProcStat mProcStat; 41 | extern struct sDT DTh1,DTh2; 42 | extern uint32_t down_timer1,down_timer2; 43 | //extern uint8_t temp_trig1, temp_trig2; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /Code/HWTest/storage_var.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "ABM_Cfg.h" 3 | #include "storage_var.h" 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include "delay.h" 9 | #include 10 | #include 11 | #include 12 | 13 | struct s_stv _stv; 14 | 15 | uint8_t ee_indx_stv,ee_pages_stv; 16 | 17 | uint8_t eeprom_page_buf[EEPROM_PAGE_SIZE]; 18 | 19 | #define MARK_CORR_EE 0xA1B77822 20 | 21 | void messInitEEprom(void); 22 | void messInitFuseBit(void); 23 | void messReboot(void); 24 | 25 | static void trigger_wdt_reset() 26 | { 27 | #ifndef _WE 28 | struct wdt_conf config_wdt; 29 | 30 | 31 | wdt_get_config_defaults(&config_wdt); 32 | 33 | /* Set the Watchdog configuration settings */ 34 | config_wdt.always_on = false; 35 | config_wdt.clock_source = GCLK_GENERATOR_0; 36 | config_wdt.timeout_period = WDT_PERIOD_2048CLK; 37 | 38 | /* Initialize and enable the Watchdog with the user settings */ 39 | wdt_set_config(&config_wdt); 40 | #endif 41 | } 42 | 43 | void configure_eeprom(void) 44 | { 45 | #ifndef _WE 46 | /* Setup EEPROM emulator service */ 47 | //! [init_eeprom_service] 48 | enum status_code error_code = eeprom_emulator_init(); 49 | //! [init_eeprom_service] 50 | struct nvm_fusebits m_fusebits; 51 | 52 | nvm_get_fuses(&m_fusebits); 53 | if((m_fusebits.bootloader_size != NVM_BOOTLOADER_SIZE_64) || (m_fusebits.eeprom_size != NVM_EEPROM_EMULATOR_SIZE_16384)) 54 | { 55 | m_fusebits.bootloader_size = NVM_BOOTLOADER_SIZE_64; 56 | m_fusebits.eeprom_size = NVM_EEPROM_EMULATOR_SIZE_16384; 57 | nvm_set_fuses(&m_fusebits); 58 | messInitFuseBit(); 59 | delay(2000); 60 | messReboot(); 61 | delay(1000); 62 | trigger_wdt_reset(); 63 | while(1){}; 64 | } 65 | 66 | //! [check_init_ok] 67 | if (error_code == STATUS_ERR_NO_MEMORY) { 68 | while (true) { 69 | /* No EEPROM section has been set in the device's fuses */ 70 | } 71 | } 72 | //! [check_init_ok] 73 | //! [check_re-init] 74 | else if (error_code != STATUS_OK) { 75 | /* Erase the emulated EEPROM memory (assume it is unformatted or 76 | * irrecoverably corrupt) */ 77 | eeprom_emulator_erase_memory(); 78 | eeprom_emulator_init(); 79 | } 80 | //! [check_re-init] 81 | #endif 82 | } 83 | 84 | #if (SAMD || SAMR21) 85 | void SYSCTRL_Handler(void) 86 | { 87 | if (SYSCTRL->INTFLAG.reg & SYSCTRL_INTFLAG_BOD33DET) { 88 | SYSCTRL->INTFLAG.reg |= SYSCTRL_INTFLAG_BOD33DET; 89 | eeprom_emulator_commit_page_buffer(); 90 | } 91 | } 92 | #endif 93 | static void configure_bod(void) 94 | { 95 | #if (SAMD || SAMR21) 96 | struct bod_config config_bod33; 97 | bod_get_config_defaults(&config_bod33); 98 | config_bod33.action = BOD_ACTION_INTERRUPT; 99 | /* BOD33 threshold level is about 3.2V */ 100 | config_bod33.level = 48; 101 | bod_set_config(BOD_BOD33, &config_bod33); 102 | bod_enable(BOD_BOD33); 103 | 104 | SYSCTRL->INTENSET.reg |= SYSCTRL_INTENCLR_BOD33DET; 105 | system_interrupt_enable(SYSTEM_INTERRUPT_MODULE_SYSCTRL); 106 | #endif 107 | 108 | } 109 | //****************************************************************************** 110 | void StoreVarToEEprom(void) 111 | { 112 | uint8_t *p=(uint8_t*)&_stv; 113 | uint8_t eeprom_temp_buf[EEPROM_PAGE_SIZE]; 114 | 115 | for(uint8_t i=ee_indx_stv;isizeof(_stv)? sizeof(_stv)%EEPROM_PAGE_SIZE : EEPROM_PAGE_SIZE; 118 | memset(eeprom_page_buf,0,EEPROM_PAGE_SIZE); 119 | memcpy(eeprom_page_buf,&p[i*(EEPROM_PAGE_SIZE)],nbytes); 120 | eeprom_emulator_read_page(i,eeprom_temp_buf); 121 | // check for modification 122 | if(memcmp(eeprom_temp_buf,eeprom_page_buf,nbytes)!=0) 123 | { 124 | memset(eeprom_page_buf,0,EEPROM_PAGE_SIZE); 125 | memcpy(eeprom_page_buf,&p[i*(EEPROM_PAGE_SIZE)],nbytes); 126 | eeprom_emulator_write_page(i, eeprom_page_buf); 127 | eeprom_emulator_commit_page_buffer(); 128 | } 129 | } 130 | } 131 | //****************************************************************************** 132 | void StvResetWiFiNwk(void) 133 | { 134 | _stv.mConLogP.SSID[0]='\0'; 135 | _stv.mConLogP.pwd[0]='\0'; 136 | StoreVarToEEprom(); 137 | } 138 | //****************************************************************************** 139 | void RestoreVarFromEEprom(void) 140 | { 141 | uint8_t *p=(uint8_t*)&_stv; 142 | for(uint8_t i=ee_indx_stv;isizeof(_stv)? sizeof(_stv)%EEPROM_PAGE_SIZE : EEPROM_PAGE_SIZE; 146 | memcpy(&p[i*(EEPROM_PAGE_SIZE)],eeprom_page_buf,nbytes); 147 | } 148 | } 149 | //****************************************************************************** 150 | void CalculateIndexVar(void) 151 | { 152 | ee_indx_stv=0; 153 | ee_pages_stv=(sizeof(_stv)+(EEPROM_PAGE_SIZE-1))/EEPROM_PAGE_SIZE; 154 | 155 | } 156 | //****************************************************************************** 157 | void SheckForInitStorVar(void) 158 | { 159 | //set_fuse_bit 160 | //configure_nvm(); 161 | configure_eeprom(); 162 | configure_bod(); 163 | 164 | CalculateIndexVar(); 165 | 166 | RestoreVarFromEEprom(); 167 | if(_stv.stor_var_control==MARK_CORR_EE) return; 168 | //store defaul values 169 | messInitEEprom(); 170 | delay(2000); 171 | _stv.HW_var.contr_mode=HEATING; 172 | _stv.HW_var.cool_mode=MODE_ON_OFF; 173 | _stv.HW_var.heat_mode=MODE_PID; 174 | _stv.HW_var.mult_contr=SINGLE; 175 | _stv.HW_var.out1_cool=OUT_REL1; 176 | _stv.HW_var.out1_heat=OUT_SSR; 177 | _stv.HW_var.out2_cool=OUT_OFF; 178 | _stv.HW_var.out2_heat=OUT_OFF; 179 | _stv.HW_var.probe1_mode=PROBE_DS18B20; 180 | _stv.HW_var.probe2_mode=PROBE_OFF; 181 | 182 | _stv.ProcPar.TPoint1=55; 183 | _stv.ProcPar.TPoint2=40; 184 | _stv.ProcPar.timer1_preset=5*60; 185 | _stv.ProcPar.timer2_preset=5*60; 186 | _stv.ProcPar.hysteresis1=2; 187 | _stv.ProcPar.hysteresis2=2.5; 188 | 189 | _stv.ProcPar.resetDT1=5; 190 | _stv.ProcPar.resetDT2=7; 191 | 192 | _stv.ProcPar.PID1_Kp=10; 193 | _stv.ProcPar.PID1_Ki=0.2; 194 | _stv.ProcPar.PID1_Kd=0; 195 | _stv.ProcPar.PID2_Kp=10.1; 196 | _stv.ProcPar.PID2_Ki=0.3; 197 | _stv.ProcPar.PID2_Kd=0.1; 198 | 199 | _stv.ProcPar.s_time=1500; 200 | _stv.ProcPar.pwm_period=3500; 201 | 202 | _stv.UnitPar.probe1_calibr=0; 203 | _stv.UnitPar.probe2_calibr=0; 204 | _stv.UnitPar.temper_unit=0; 205 | 206 | _stv.mConLogP.LogMode=0; 207 | _stv.mConLogP.SampleTime=15; 208 | _stv.mConLogP.ConnectMode=WiFi::MODE_OFF; 209 | _stv.mConLogP.SSID[0]='\0'; 210 | _stv.mConLogP.pwd[0]='\0'; 211 | _stv.mConLogP.localServerPort = 80; 212 | _stv.mConLogP.serverIP = THINGSPEAK_IPADDRESS; 213 | _stv.mConLogP.channelID=0; 214 | _stv.mConLogP.userKey[0]='\0'; 215 | _stv.mConLogP.baud = WiFi::BAUD_RATE_DEFAULT; 216 | 217 | _stv.stor_var_control=MARK_CORR_EE; 218 | 219 | StoreVarToEEprom(); 220 | 221 | } 222 | //****************************************************************************** 223 | -------------------------------------------------------------------------------- /Code/HWTest/storage_var.h: -------------------------------------------------------------------------------- 1 | #ifndef _STORAGE_VAR 2 | #define _STORAGE_VAR 3 | 4 | #include 5 | #include 6 | 7 | #include "WiFi.h" 8 | 9 | #define THINGSPEAK_KEY_LEN 16 10 | 11 | struct s_stv{ 12 | 13 | struct sHW_var{ 14 | uint8_t contr_mode; 15 | uint8_t heat_mode; 16 | uint8_t cool_mode; 17 | uint8_t mult_contr; 18 | uint8_t out1_heat; 19 | uint8_t out1_cool; 20 | uint8_t out2_heat; 21 | uint8_t out2_cool; 22 | uint8_t probe1_mode; 23 | uint8_t probe2_mode; 24 | }HW_var; 25 | 26 | struct sUParam{ 27 | float probe1_calibr; 28 | float probe2_calibr; 29 | uint8_t temper_unit; 30 | }UnitPar; 31 | 32 | struct sPParam{ 33 | float TPoint1; 34 | float TPoint2; 35 | uint32_t timer1_preset; 36 | uint32_t timer2_preset; 37 | float PID1_Kp; 38 | float PID1_Ki; 39 | float PID1_Kd; 40 | float PID2_Kp; 41 | float PID2_Ki; 42 | float PID2_Kd; 43 | uint16_t s_time; 44 | uint16_t pwm_period; 45 | float hysteresis1; 46 | float hysteresis2; 47 | float resetDT1; 48 | float resetDT2; 49 | }ProcPar; 50 | 51 | struct sConLogP{ 52 | uint8_t LogMode; 53 | uint8_t SampleTime; 54 | uint8_t ConnectMode; 55 | char SSID[WiFi::SSID_MAX_LEN + 1]; /* null-terminated string */ 56 | char pwd[WiFi::PWD_MAX_LEN + 1]; /* null-terminated string */ 57 | uint16_t localServerPort; 58 | IPAddress serverIP; 59 | uint32_t channelID; 60 | char userKey[THINGSPEAK_KEY_LEN + 1]; /* null-terminated string */ 61 | uint32_t baud; 62 | }mConLogP; 63 | 64 | uint32_t stor_var_control; 65 | }; 66 | 67 | extern struct s_stv _stv; 68 | void configure_eeprom(void); 69 | void StoreVarToEEprom(void); 70 | 71 | /* Reset Wi-Fi network information stored in non-volatile memory 72 | * Wi-Fi network information consists in SSID and password for connecting to an 73 | * access point. 74 | */ 75 | void StvResetWiFiNwk(void); 76 | 77 | void RestoreVarFromEEprom(void); 78 | 79 | #endif 80 | -------------------------------------------------------------------------------- /Code/HWTest/u8g_port.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | #define OLED_NEG 4 | #undef OLED_NEG 5 | 6 | #define WIDTH 128 7 | #define HEIGHT 64 8 | #define PAGE_HEIGHT 64 9 | 10 | //u8g_t u8g; 11 | 12 | uint8_t oled_buffer[(WIDTH/8)*HEIGHT]; 13 | 14 | //****************************************************************************** 15 | uint8_t u8g_com_FB_fn(u8g_t *u8g, uint8_t msg, uint8_t arg_val, void *arg_ptr) 16 | { 17 | switch(msg) 18 | { 19 | case U8G_COM_MSG_INIT: 20 | break; 21 | case U8G_COM_MSG_STOP: 22 | break; 23 | 24 | 25 | case U8G_COM_MSG_CHIP_SELECT: 26 | /* arg_val contains the chip number, which should be enabled */ 27 | break; 28 | 29 | 30 | case U8G_COM_MSG_WRITE_BYTE: 31 | break; 32 | case U8G_COM_MSG_WRITE_SEQ: 33 | break; 34 | } 35 | return 1; 36 | } 37 | //****************************************************************************** 38 | uint8_t r_u8g_dev_FB_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 39 | { 40 | switch(msg) 41 | { 42 | case U8G_DEV_MSG_INIT: 43 | // u8g_InitCom(u8g, dev, U8G_SPI_CLK_CYCLE_300NS); 44 | // u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_adafruit2_init_seq); 45 | break; 46 | case U8G_DEV_MSG_STOP: 47 | break; 48 | case U8G_DEV_MSG_PAGE_NEXT: 49 | { 50 | // u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 51 | // u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd1306_128x64_data_start); 52 | // u8g_WriteByte(u8g, dev, 0x0b0 | pb->p.page); /* select current page (SSD1306) */ 53 | // u8g_SetAddress(u8g, dev, 1); /* data mode */ 54 | // if ( u8g_pb_WriteBuffer(pb, u8g, dev) == 0 ) 55 | // return 0; 56 | // u8g_SetChipSelect(u8g, dev, 0); 57 | } 58 | break; 59 | case U8G_DEV_MSG_SLEEP_ON: 60 | // u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_on); 61 | return 1; 62 | case U8G_DEV_MSG_SLEEP_OFF: 63 | // u8g_WriteEscSeqP(u8g, dev, u8g_dev_ssd13xx_sleep_off); 64 | return 1; 65 | } 66 | // return u8g_dev_pb8v1_base_fn(u8g, dev, msg, arg); 67 | return 1; 68 | } 69 | //****************************************************************************** 70 | void r_u8g_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 71 | { 72 | register uint8_t mask; 73 | uint8_t *ptr = (uint8_t*)b->buf; 74 | 75 | y -= b->p.page_y0; 76 | mask = 1; 77 | y &= 0x07; 78 | mask <<= y; 79 | ptr += x; 80 | if ( color_index ) 81 | { 82 | *ptr |= mask; 83 | } 84 | else 85 | { 86 | mask ^=0xff; 87 | *ptr &= mask; 88 | } 89 | } 90 | //****************************************************************************** 91 | static const uint8_t PXsetBit[] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }, 92 | PXclrBit[] = { 0x7F, 0xBF, 0xDF, 0xEF, 0xF7, 0xFB, 0xFD, 0xFE }; 93 | 94 | void u8g_set_pixel(u8g_pb_t *b, u8g_uint_t x, u8g_uint_t y, uint8_t color_index) 95 | { 96 | 97 | // uint8_t *buffer = (uint8_t*)b->buf; 98 | 99 | // if(buffer) { 100 | // if((x < 0) || (y < 0) || (x >= _width) || (y >= _height)) return; 101 | if(!(b->buf)) return; 102 | /* 103 | int16_t t; 104 | switch(rotation) { 105 | case 1: 106 | t = x; 107 | x = WIDTH - 1 - y; 108 | y = t; 109 | break; 110 | case 2: 111 | x = WIDTH - 1 - x; 112 | y = HEIGHT - 1 - y; 113 | break; 114 | case 3: 115 | t = x; 116 | x = y; 117 | y = HEIGHT - 1 - t; 118 | break; 119 | } 120 | */ 121 | // int b_indx=(x / 8) + y * ((WIDTH + 7) / 8); 122 | // uint8_t *ptr = &((uint8_t*)b->buf)[b_indx]; 123 | // if(color_index/*color*/) *ptr |= PXsetBit[x & 7]; 124 | // else *ptr &= PXclrBit[x & 7]; 125 | int b_indx=(x) + ((y & ~7)<<4); 126 | uint8_t *ptr = &((uint8_t*)b->buf)[b_indx]; 127 | #if defined(OLED_NEG) 128 | if(color_index/*color*/) *ptr &= ~(1<<(y & 7)); 129 | else *ptr |= 1<<(y & 7); 130 | #else 131 | if(color_index/*color*/) *ptr |= 1<<(y & 7); 132 | else *ptr &= ~(1<<(y & 7)); 133 | #endif 134 | } 135 | //****************************************************************************** 136 | void u8g_SetPixel(u8g_pb_t *b, const u8g_dev_arg_pixel_t * const arg_pixel) 137 | { 138 | if ( arg_pixel->y < b->p.page_y0 ) 139 | return; 140 | if ( arg_pixel->y > b->p.page_y1 ) 141 | return; 142 | if ( arg_pixel->x >= b->width ) 143 | return; 144 | u8g_set_pixel(b, arg_pixel->x, arg_pixel->y, arg_pixel->color); 145 | } 146 | //****************************************************************************** 147 | void u8g_FB_Set8Pixel(u8g_pb_t *b, u8g_dev_arg_pixel_t *arg_pixel) 148 | { 149 | register uint8_t pixel = arg_pixel->pixel; 150 | u8g_uint_t dx = 0; 151 | u8g_uint_t dy = 0; 152 | 153 | switch( arg_pixel->dir ) 154 | { 155 | case 0: dx++; break; 156 | case 1: dy++; break; 157 | case 2: dx--; break; 158 | case 3: dy--; break; 159 | } 160 | 161 | do 162 | { 163 | if ( pixel & 128 ) 164 | u8g_SetPixel(b, arg_pixel); 165 | arg_pixel->x += dx; 166 | arg_pixel->y += dy; 167 | pixel <<= 1; 168 | } while( pixel != 0 ); 169 | 170 | } 171 | //****************************************************************************** 172 | void u8g_FB_Clear(u8g_pb_t *b) 173 | { 174 | uint8_t *ptr = (uint8_t *)b->buf; 175 | uint8_t *end_ptr = ptr; 176 | end_ptr += (WIDTH/8)*HEIGHT;//b->width*2; 177 | do 178 | { 179 | #if defined(OLED_NEG) 180 | *ptr++ = 0xff; 181 | #else 182 | *ptr++ = 0; 183 | #endif 184 | } while( ptr != end_ptr ); 185 | } 186 | //****************************************************************************** 187 | uint8_t u8g_dev_FB_fn(u8g_t *u8g, u8g_dev_t *dev, uint8_t msg, void *arg) 188 | { 189 | u8g_pb_t *pb = (u8g_pb_t *)(dev->dev_mem); 190 | switch(msg) 191 | { 192 | case U8G_DEV_MSG_SET_8PIXEL: 193 | if ( u8g_pb_Is8PixelVisible(pb, (u8g_dev_arg_pixel_t *)arg) ) 194 | u8g_FB_Set8Pixel(pb, (u8g_dev_arg_pixel_t *)arg); 195 | break; 196 | case U8G_DEV_MSG_SET_PIXEL: 197 | u8g_SetPixel(pb, (u8g_dev_arg_pixel_t *)arg); 198 | break; 199 | case U8G_DEV_MSG_INIT: 200 | break; 201 | case U8G_DEV_MSG_STOP: 202 | break; 203 | case U8G_DEV_MSG_PAGE_FIRST: 204 | u8g_FB_Clear(pb); 205 | u8g_page_First(&(pb->p)); 206 | break; 207 | case U8G_DEV_MSG_PAGE_NEXT: 208 | // if ( u8g_page_Next(&(pb->p)) == 0 ) 209 | return 0; 210 | // u8g_pb14v1_Clear(pb); 211 | break; 212 | #ifdef U8G_DEV_MSG_IS_BBX_INTERSECTION 213 | case U8G_DEV_MSG_IS_BBX_INTERSECTION: 214 | return u8g_pb_IsIntersection(pb, (u8g_dev_arg_bbx_t *)arg); 215 | #endif 216 | case U8G_DEV_MSG_GET_PAGE_BOX: 217 | u8g_pb_GetPageBox(pb, (u8g_box_t *)arg); 218 | break; 219 | case U8G_DEV_MSG_GET_WIDTH: 220 | *((u8g_uint_t *)arg) = pb->width; 221 | break; 222 | case U8G_DEV_MSG_GET_HEIGHT: 223 | *((u8g_uint_t *)arg) = pb->p.total_height; 224 | break; 225 | case U8G_DEV_MSG_SET_COLOR_ENTRY: 226 | break; 227 | case U8G_DEV_MSG_SET_XY_CB: 228 | break; 229 | case U8G_DEV_MSG_GET_MODE: 230 | return U8G_MODE_BW; 231 | } 232 | return 1; 233 | } 234 | //****************************************************************************** 235 | //U8G_PB_DEV(u8g_dev_null, WIDTH, HEIGHT, PAGE_HEIGHT, u8g_dev_null_fn, u8g_com_null_fn); 236 | //#define U8G_PB_DEV(name, width, height, page_height, dev_fn, com_fn) \ 237 | //uint8_t name##_buf[width] U8G_NOCOMMON ; \ 238 | //u8g_pb_t name##_pb = { {page_height, height, 0, 0, 0}, width, name##_buf}; \ 239 | //u8g_dev_t name = { dev_fn, &name##_pb, com_fn } 240 | 241 | //uint8_t u8g_dev_FB_buf[WIDTH] U8G_NOCOMMON; 242 | u8g_pb_t u8g_dev_FB_pb = { {PAGE_HEIGHT, HEIGHT, 0, 0, 0}, WIDTH, oled_buffer/*u8g_dev_FB_buf*/}; 243 | u8g_dev_t u8g_dev_FB = {u8g_dev_FB_fn, &u8g_dev_FB_pb, u8g_com_FB_fn}; 244 | 245 | U8GLIB mGUI(&u8g_dev_FB, u8g_com_FB_fn); 246 | 247 | //****************************************************************************** 248 | void u8g_setup(void) 249 | { 250 | mGUI.firstPage(); 251 | // u8g_InitComFn(&u8g, &u8g_dev_FB, u8g_com_FB_fn); 252 | //u8g_SetDefaultForegroundColor(&u8g); 253 | // u8g_FirstPage(&u8g); 254 | } 255 | //****************************************************************************** 256 | void FB_Clear(void) 257 | { 258 | for(int i=0;i<((WIDTH/8)*HEIGHT);i++) 259 | { 260 | #if defined(OLED_NEG) 261 | oled_buffer[i]=0xff; 262 | #else 263 | oled_buffer[i]=0; 264 | #endif 265 | } 266 | } 267 | //****************************************************************************** 268 | -------------------------------------------------------------------------------- /Code/HWTest/utlts.cpp: -------------------------------------------------------------------------------- 1 | 2 | #include "utlts.h" 3 | #include 4 | #include "ABM_Buttons.h" 5 | 6 | uint16_t IntToBint(int16_t in) 7 | { 8 | return (30000+in); 9 | } 10 | 11 | int16_t BintToInt(uint16_t in) 12 | { 13 | return ((int)in-(int)30000); 14 | } 15 | 16 | void IncVal(uint8_t *val, uint8_t lim) 17 | { 18 | if(*val>=(lim-1)) *val=0; 19 | else (*val)++; 20 | } 21 | 22 | int IncValLim(int val, int max) 23 | { 24 | if(val>=max) val=max; 25 | else val+=autorepeat_factor; 26 | return val>=max?max:val; 27 | } 28 | 29 | float IncValLim(float val, int max) 30 | { 31 | int tint; 32 | float ret; 33 | if(val>=max) return max; 34 | else{ 35 | tint=(val+((val<0)?-0.05:0.05))*10; 36 | //tint*=autorepeat_factor; 37 | ret=(tint+1*autorepeat_factor)/10.; 38 | return ret>=max?max:ret; 39 | } 40 | } 41 | 42 | void DecVal(uint8_t *val, uint8_t lim) 43 | { 44 | if(*val==0) *val=(lim-1); 45 | else (*val)--; 46 | } 47 | 48 | int DecValLim(int val, int min) 49 | { 50 | if(val<=min) val=min; 51 | else val-=autorepeat_factor; 52 | return val<=min?min:val; 53 | } 54 | 55 | float DecValLim(float val, int min) 56 | { 57 | int tint; 58 | float ret; 59 | if(val<=min) return min; 60 | else{ 61 | tint=(val+((val<0)?-0.05:0.05))*10; 62 | //tint*=autorepeat_factor; 63 | ret=(tint-1*autorepeat_factor)/10.; 64 | return ret<=min?min:ret; 65 | } 66 | } -------------------------------------------------------------------------------- /Code/HWTest/utlts.h: -------------------------------------------------------------------------------- 1 | #ifndef _UTLTS_H_ 2 | #define _UTLTS_H_ 3 | 4 | #include 5 | 6 | void IncVal(uint8_t *val, uint8_t lim); 7 | void DecVal(uint8_t *val, uint8_t lim); 8 | int IncValLim(int val, int max); 9 | float IncValLim(float val, int max); 10 | int DecValLim(int val, int min); 11 | float DecValLim(float val, int min); 12 | uint16_t IntToBint(int16_t in); 13 | int16_t BintToInt(uint16_t in); 14 | 15 | #endif 16 | -------------------------------------------------------------------------------- /Code/HWTest/vsd_GUI.cpp: -------------------------------------------------------------------------------- 1 | #include "ABM_HW_switch.h" 2 | #include "vsd_GUI.h" 3 | #include "wiring_digital.h" 4 | #include 5 | 6 | /* Force inclusion of the _printf_float symbol, in order to support floating 7 | * point specifiers in printf() format strings. */ 8 | asm (".global _printf_float"); 9 | 10 | VSD_GUI vsdGUI(&mGUI); 11 | 12 | extern TDrive DriveOut[]; 13 | 14 | 15 | 16 | const char name_out[5][4]={ 17 | "SSR", 18 | "DC1", 19 | "DC2", 20 | "RL1", 21 | "RL2" 22 | }; 23 | 24 | //****************************************************************************** 25 | uint8_t readDriveSet(uint8_t m_indx) 26 | { 27 | switch(m_indx) 28 | { 29 | case 0: {return (digitalRead(DriveOut[OUT_SSR].pin)); break;} 30 | case 1: {return (digitalRead(DriveOut[OUT_DC1].pin)); break;} 31 | case 2: {return (digitalRead(DriveOut[OUT_DC2].pin)); break;} 32 | case 3: {return (digitalRead(DriveOut[OUT_REL1].pin)); break;} 33 | case 4: {return (digitalRead(DriveOut[OUT_REL2].pin)); break;} 34 | } 35 | return 0; 36 | } 37 | //****************************************************************************** 38 | void draw_LabelBox(char *str,uint8_t x,uint8_t y, uint8_t w,uint8_t h, uint8_t neg) 39 | { 40 | uint8_t w_str,offs; 41 | // mGUI.setFont(u8g_font_5x8); 42 | // mGUI.setFont(u8g_font_5x7); 43 | // mGUI.setFont(u8g_font_chikita); 44 | mGUI.setFont(u8g_font_04b_03); 45 | mGUI.setFontRefHeightText(); 46 | mGUI.setFontPosTop(); 47 | w_str=mGUI.getStrWidth(str); 48 | offs=((w/2-w_str/2)<0)?0:(w/2-w_str/2); 49 | if(neg==0) 50 | { 51 | mGUI.setDefaultForegroundColor(); 52 | mGUI.drawFrame(x, y, w, h); 53 | // mGUI.drawStr((x+offs, y+2 , str); 54 | // mGUI.setDefaultBackgroundColor(); 55 | } 56 | else 57 | { 58 | mGUI.setDefaultForegroundColor(); 59 | mGUI.drawBox(x, y, w, h); 60 | mGUI.setDefaultBackgroundColor(); 61 | } 62 | mGUI.drawStr(x+offs, y+1 , str); 63 | mGUI.setDefaultForegroundColor(); 64 | } 65 | //****************************************************************************** 66 | void DrawOutputs(void) 67 | { 68 | uint8_t x=1,y=9; 69 | for(int i=0;i<5;i++) 70 | { 71 | draw_LabelBox((char*)name_out[i],x,y,18,9,readDriveSet(i)/*i&1*/); 72 | y+=8; 73 | } 74 | } 75 | //****************************************************************************** 76 | void DrawOutputs(uint16_t nX, uint16_t nY) 77 | { 78 | uint8_t x=nX,y=nY; 79 | for(int i=0;i<5;i++) 80 | { 81 | draw_LabelBox((char*)name_out[i],x,y,18,9,readDriveSet(i)/*i&1*/); 82 | y+=8; 83 | } 84 | } 85 | //****************************************************************************** 86 | void VSD_GUI::DrawListBox(vsdListBOX *lbox) 87 | { 88 | 89 | } 90 | //****************************************************************************** 91 | void VSD_GUI::DrawGroupBoxCentr(vsdStringGroup *str_gr, uint16_t x, uint16_t y) 92 | { 93 | uint16_t w,h; 94 | if(str_gr->count==0) return; 95 | w=MaxSizeStrings(str_gr); 96 | h=gui->getFontLineSpacing(); 97 | for(int i=0;icount;i++) 98 | { 99 | DrawTextCenterFrame(x,y+(h+1)*i,str_gr->strs[i], 100 | i==str_gr->curr_indx?lsDOTED:lsNONE, 101 | (uint16_t)w+2); 102 | } 103 | 104 | } 105 | //****************************************************************************** 106 | void VSD_GUI::DrawGroupBoxCentr(vsdStrCbGroup *str_cb, uint16_t x, uint16_t y, 107 | uint8_t line_offset, uint8_t line_count) 108 | { 109 | uint16_t w,h; 110 | if(str_cb->count==0) return; 111 | if ((line_count == 0) || (line_count > (str_cb->count - line_offset))) 112 | line_count = str_cb->count - line_offset; 113 | w=MaxSizeStrings(&str_cb); 114 | h=gui->getFontLineSpacing(); 115 | for(int i=0;iStrCb[i+line_offset].strName, 118 | i+line_offset==str_cb->curr_indx?lsSOLID/*lsDOTED*/:lsNONE, 119 | (uint16_t)w+2); 120 | } 121 | 122 | } 123 | //****************************************************************************** 124 | uint8_t VSD_GUI::MaxSizeStrings(char **str, uint8_t cnt) 125 | { 126 | uint8_t rsize=0,t; 127 | // char *p=str; 128 | for(uint8_t i=0;irsize) rsize=t; 132 | } 133 | return rsize; 134 | } 135 | //****************************************************************************** 136 | uint8_t VSD_GUI::MaxSizeStrings(vsdStrCbGroup **StrCb) 137 | { 138 | uint8_t rsize=0,t; 139 | // char *p=str; 140 | for(uint8_t i=0;i<(*StrCb)->count;i++) 141 | { 142 | t=mGUI.getStrWidth(((*StrCb)->StrCb[i].strName)); 143 | if(t>rsize) rsize=t; 144 | } 145 | return rsize; 146 | } 147 | //****************************************************************************** 148 | uint8_t VSD_GUI::MaxSizeStrings(vsdStringGroup *str_gr) 149 | { 150 | return MaxSizeStrings(str_gr->strs, /*str_gr->len_str,*/ str_gr->count); 151 | } 152 | //****************************************************************************** 153 | void VSD_GUI::DrawTextCenter(uint16_t x, uint16_t y, const char *s) 154 | { 155 | uint16_t cx,cy; 156 | gui->setFontPosBottom(); 157 | cy=y-(gui->getFontLineSpacing()/2); 158 | cx=x-(gui->getStrWidth(s)/2); 159 | gui->setPrintPos(cx,cy); 160 | gui->print(s); 161 | } 162 | //****************************************************************************** 163 | void VSD_GUI::DrawTextCenterOvr(uint16_t x, uint16_t y, const char *s, uint8_t neg) 164 | { 165 | uint16_t cx,cy,w,h; 166 | cy=y-((h=gui->getFontLineSpacing())/2); 167 | cx=x-((w=gui->getStrWidth(s))/2); 168 | 169 | if(neg) gui->setDefaultForegroundColor(); else gui->setDefaultBackgroundColor(); 170 | gui->drawBox(cx, cy-h, w, h); 171 | if(neg) gui->setDefaultBackgroundColor(); else gui->setDefaultForegroundColor(); 172 | DrawTextCenter(x, y, s); 173 | gui->setDefaultForegroundColor(); 174 | } 175 | //****************************************************************************** 176 | void VSD_GUI::DrawTextCenterFrame(uint16_t x, uint16_t y, const char *s) 177 | { 178 | uint16_t cx,cy,w,h; 179 | cy=y-((h=gui->getFontLineSpacing())/2); 180 | cx=x-((w=gui->getStrWidth(s))/2); 181 | 182 | gui->drawFrame(cx-2, cy-h-2, w+3, h+2); 183 | DrawTextCenter(x, y, s); 184 | } 185 | //****************************************************************************** 186 | void VSD_GUI::DrawLineVTop(uint16_t x, uint16_t y, uint16_t l) 187 | { 188 | for(int i=0;igetFontLineSpacing())/2); 210 | cx=x-((w=gui->getStrWidth(s))/2); 211 | SetBlinkPixelCount(0); 212 | SetBlinkPixelStyle(style); 213 | //gui->drawFrame(cx-2, cy-h-1, w+3, h+1); 214 | 215 | cx=cx-2; cy=cy-h-1; w=w+3; h=h/*+1*/; 216 | DrawLineHRight(cx,cy,w); 217 | DrawLineVBot(cx+w,cy,h); 218 | DrawLineHLeft(cx+w,cy+h,w); 219 | DrawLineVTop(cx,cy+h,h); 220 | 221 | DrawTextCenter(x, y, s); 222 | } 223 | //****************************************************************************** 224 | void VSD_GUI::DrawTextCenterFrame_cl(uint16_t x, uint16_t y, const char *s, enum line_style style, int width) 225 | { 226 | uint16_t cx,cy,w,h; 227 | cy=y-((h=gui->getFontLineSpacing())/2); 228 | if(width == 0){ 229 | cx=x-((w=gui->getStrWidth(s))/2); 230 | } 231 | else{ 232 | cx=x-((w=width)/2); 233 | } 234 | 235 | SetBlinkPixelCount(0); 236 | SetBlinkPixelStyle(style); 237 | 238 | // cx=cx-2; cy=cy-h-1; w=w+3; h=h/*+1*/; 239 | cx=cx-2; cy=cy-h-2; w=w+3; h=h+1; 240 | 241 | gui->setDefaultBackgroundColor(); 242 | gui->drawBox(cx, cy, w, h); 243 | gui->setDefaultForegroundColor(); 244 | 245 | for(int i=0;i<3;i++) 246 | { 247 | DrawLineHRight(cx,cy,w); 248 | DrawLineVBot(cx+w,cy,h); 249 | DrawLineHLeft(cx+w,cy+h,w); 250 | DrawLineVTop(cx,cy+h,h); 251 | SetBlinkPixelStyle(lsCLR); 252 | w+=2; h+=2; cx--; cy--; 253 | } 254 | 255 | gui->setDefaultForegroundColor(); 256 | DrawTextCenter(x, y, s); 257 | } 258 | //****************************************************************************** 259 | void VSD_GUI::DrawTextCenterFrame(uint16_t x, uint16_t y, const char *s, enum line_style style, uint16_t width) 260 | { 261 | uint16_t cx,cy,w=width,h; 262 | cy=y-((h=gui->getFontLineSpacing())/2); 263 | // cx=x-((w=gui->getStrWidth(s))/2); 264 | cx=x-(w/2); 265 | SetBlinkPixelCount(0); 266 | SetBlinkPixelStyle(style); 267 | //gui->drawFrame(cx-2, cy-h-1, w+3, h+1); 268 | 269 | // cx=cx-2; cy=cy-h-1; w=w+3; h=h/*+1*/; 270 | cx=cx-2; cy=cy-h-2; w=w+3; h=h+2; 271 | 272 | DrawLineHRight(cx,cy,w); 273 | DrawLineVBot(cx+w,cy,h); 274 | DrawLineHLeft(cx+w,cy+h,w); 275 | DrawLineVTop(cx,cy+h,h); 276 | 277 | DrawTextCenter(x, y, s); 278 | } 279 | //****************************************************************************** 280 | void VSD_GUI::DrawPixelBlink(uint16_t x, uint16_t y) 281 | { 282 | switch(blink_pixel_style) 283 | { 284 | case lsNONE:{} 285 | break; 286 | case lsCLR:{ 287 | gui->setDefaultBackgroundColor(); 288 | gui->drawPixel(x,y); 289 | }break; 290 | case lsSOLID:{ 291 | gui->setDefaultForegroundColor(); 292 | gui->drawPixel(x,y); 293 | }break; 294 | case lsDOTED:{ 295 | if(blink_pixel_count&1) gui->setDefaultForegroundColor(); else gui->setDefaultBackgroundColor(); 296 | gui->drawPixel(x,y); 297 | }break; 298 | case lsDOTED_12:{ 299 | if((blink_pixel_count%3)<1) gui->setDefaultForegroundColor(); else gui->setDefaultBackgroundColor(); 300 | gui->drawPixel(x,y); 301 | }break; 302 | case lsDOTED_13:{ 303 | if((blink_pixel_count%4)<1) gui->setDefaultForegroundColor(); else gui->setDefaultBackgroundColor(); 304 | gui->drawPixel(x,y); 305 | }break; 306 | case lsDOTED_14:{ 307 | if((blink_pixel_count%5)<1) gui->setDefaultForegroundColor(); else gui->setDefaultBackgroundColor(); 308 | gui->drawPixel(x,y); 309 | }break; 310 | case lsDASHED_21:{ 311 | if((blink_pixel_count%3)<2) gui->setDefaultForegroundColor(); else gui->setDefaultBackgroundColor(); 312 | gui->drawPixel(x,y); 313 | }break; 314 | case lsDASHED_31:{ 315 | if((blink_pixel_count%4)<3) gui->setDefaultForegroundColor(); else gui->setDefaultBackgroundColor(); 316 | gui->drawPixel(x,y); 317 | }break; 318 | case lsDASHED_22:{ 319 | if((blink_pixel_count%4)<2) gui->setDefaultForegroundColor(); else gui->setDefaultBackgroundColor(); 320 | gui->drawPixel(x,y); 321 | }break; 322 | case lsDASHED_32:{ 323 | if((blink_pixel_count%5)<3) gui->setDefaultForegroundColor(); else gui->setDefaultBackgroundColor(); 324 | gui->drawPixel(x,y); 325 | }break; 326 | 327 | } 328 | gui->setDefaultForegroundColor(); 329 | blink_pixel_count++; 330 | } 331 | //****************************************************************************** 332 | int VSD_GUI::printf(const char *str, ...) 333 | { 334 | va_list args; 335 | int size; 336 | 337 | va_start( args, str ); 338 | size=vsnprintf((char*)print_buf, 128, str, args); 339 | va_end (args); 340 | 341 | gui->print((const char*)&print_buf[0]); 342 | return size; 343 | } 344 | //****************************************************************************** 345 | int VSD_GUI::printf_n(const char *str, ...) 346 | { 347 | va_list args; 348 | int size,x,y,w,h; 349 | 350 | va_start( args, str ); 351 | size=vsnprintf((char*)print_buf, 128, str, args); 352 | va_end (args); 353 | 354 | x=gui->getPrintCol(); 355 | y=gui->getPrintRow(); 356 | h=gui->getFontLineSpacing(); 357 | w=gui->getStrWidth((const char*)&print_buf[0]); 358 | gui->setDefaultForegroundColor(); 359 | y+=gui->getU8g()->font_calc_vref(gui->getU8g()); 360 | 361 | gui->drawBox(x-1, y-h+1, w+1, h); 362 | // gui->drawBox(x-1, y-h+1, w+1, h); 363 | gui->setDefaultBackgroundColor(); 364 | gui->print((const char*)&print_buf[0]); 365 | gui->setDefaultForegroundColor(); 366 | return size; 367 | } 368 | //****************************************************************************** 369 | int VSD_GUI::printf_p(char *str, ...) 370 | { 371 | va_list args; 372 | int size,x,y,w,h; 373 | 374 | va_start( args, str ); 375 | size=vsnprintf((char*)print_buf, 128, str, args); 376 | va_end (args); 377 | 378 | x=gui->getPrintCol(); 379 | y=gui->getPrintRow(); 380 | h=gui->getFontLineSpacing(); 381 | w=gui->getStrWidth((const char*)&print_buf[0]); 382 | gui->setDefaultBackgroundColor(); 383 | y+=gui->getU8g()->font_calc_vref(gui->getU8g()); 384 | 385 | gui->drawBox(x-1, y-h+1, w+1, h); 386 | // gui->drawBox(x-1, y-h+1, w+1, h); 387 | gui->setDefaultForegroundColor(); 388 | gui->print((const char*)&print_buf[0]); 389 | gui->setDefaultForegroundColor(); 390 | return size; 391 | } 392 | //****************************************************************************** 393 | int VSD_GUI::printf_aright(const char *str, ...) 394 | { 395 | va_list args; 396 | int size,x,y,w,h; 397 | 398 | va_start( args, str ); 399 | size=vsnprintf((char*)print_buf, 128, str, args); 400 | va_end (args); 401 | 402 | x=gui->getPrintCol(); 403 | y=gui->getPrintRow(); 404 | w=gui->getStrWidth((const char*)&print_buf[0]); 405 | gui->setPrintPos(x-w+1,y); 406 | gui->print((const char*)&print_buf[0]); 407 | return size; 408 | } 409 | //****************************************************************************** 410 | int VSD_GUI::printf_center(const char *str, ...) 411 | { 412 | va_list args; 413 | int size,x,y,w,h; 414 | 415 | va_start( args, str ); 416 | size=vsnprintf((char*)print_buf, 128, str, args); 417 | va_end (args); 418 | 419 | x=gui->getPrintCol(); 420 | y=gui->getPrintRow(); 421 | w=gui->getStrWidth((const char*)&print_buf[0]); 422 | gui->setPrintPos(x-(w/2),y); 423 | gui->print((const char*)&print_buf[0]); 424 | return size; 425 | } 426 | //****************************************************************************** 427 | int VSD_GUI::printf_center_n(const char *str, ...) 428 | { 429 | va_list args; 430 | int size, x, y, w, h; 431 | 432 | va_start(args, str); 433 | size = vsnprintf((char*)print_buf, sizeof(print_buf), str, args); 434 | va_end(args); 435 | x = gui->getPrintCol(); 436 | y = gui->getPrintRow(); 437 | h = gui->getFontLineSpacing(); 438 | w = gui->getStrWidth((const char*)&print_buf[0]); 439 | x -= w / 2; 440 | gui->setDefaultForegroundColor(); 441 | gui->drawBox(x - 1, 442 | y + gui->getU8g()->font_calc_vref(gui->getU8g()) - h + 1, w + 1, h); 443 | gui->setDefaultBackgroundColor(); 444 | gui->setPrintPos(x, y); 445 | gui->print((const char*)&print_buf[0]); 446 | gui->setDefaultForegroundColor(); 447 | return size; 448 | } 449 | //****************************************************************************** 450 | int VSD_GUI::print_multiline(const char *str, int x_offset, int line_width) 451 | { 452 | uint16_t w, y; 453 | int i, line_count, chars_per_line; 454 | char *rw_str = (char *)str; 455 | char tmp; 456 | 457 | w = getStrWidth(str); 458 | y = gui->getPrintRow(); 459 | line_count = getLineCount(str, line_width); 460 | chars_per_line = line_width * strlen(str) / w; 461 | for (i = 0; i < line_count; i++) { 462 | gui->setPrintPos(x_offset, y + i * gui->getFontLineSpacing()); 463 | if (gui->getPrintRow() + gui->getFontLineSpacing() > gui->getHeight()) { 464 | line_count = i; 465 | break; 466 | } 467 | if (i < line_count - 1) { 468 | tmp = str[chars_per_line * (i + 1)]; 469 | rw_str[chars_per_line * (i + 1)] = '\0'; 470 | } 471 | gui->print(str + i * chars_per_line); 472 | if (i < line_count - 1) 473 | rw_str[chars_per_line * (i + 1)] = tmp; 474 | } 475 | return line_count; 476 | } 477 | //****************************************************************************** 478 | char* VSD_GUI::sb_printf(const char *str, ...) 479 | { 480 | va_list args; 481 | int size,x,y,w,h; 482 | 483 | va_start( args, str ); 484 | size=vsnprintf((char*)print_buf, 128, str, args); 485 | va_end (args); 486 | 487 | return (char*)print_buf; 488 | } 489 | //****************************************************************************** 490 | int VSD_GUI::getStrWidth(const char *str) 491 | { 492 | char buf[2]; 493 | 494 | buf[0] = str[0]; 495 | buf[1] = '\0'; 496 | return (gui->getStrWidth(buf) * strlen(str)); 497 | } 498 | //****************************************************************************** 499 | int VSD_GUI::getLineCount(const char *str, int line_width) 500 | { 501 | int w, line_count; 502 | 503 | w = getStrWidth(str); 504 | line_count = w / line_width; 505 | if (line_width * line_count < w) 506 | line_count++; 507 | return line_count; 508 | } 509 | //****************************************************************************** 510 | void VSD_GUI::DrawTimeHMS(uint32_t seconds) 511 | { 512 | uint8_t h,m,s; 513 | h=seconds/(60*60); 514 | m=(seconds/60)%60; 515 | s=seconds%60; 516 | if(h>0) printf((char*)"%d:%02d:%02d",h,m,s); 517 | else printf((char*)"%d:%02d",m,s); 518 | } 519 | //****************************************************************************** 520 | void VSD_GUI::DrawTimeHMS(uint16_t x, uint16_t y, uint32_t seconds) 521 | { 522 | gui->setPrintPos(x,y); 523 | DrawTimeHMS(seconds); 524 | } 525 | //****************************************************************************** 526 | void VSD_GUI::DrawTimeHMS(uint16_t x, uint16_t y, uint32_t seconds, const u8g_fntpgm_uint8_t *font) 527 | { 528 | gui->setFont(font); 529 | DrawTimeHMS(x,y,seconds); 530 | } 531 | //****************************************************************************** 532 | extern void FB_Clear(void); 533 | void VSD_GUI::ClrDisp(void) 534 | { 535 | FB_Clear(); 536 | } 537 | //****************************************************************************** 538 | extern uint8_t oled_buffer[]; 539 | void VSD_GUI::ClrDisp_dt(void) 540 | { 541 | for(int i=0;i<((128/8)*64);i+=2) 542 | { 543 | oled_buffer[i]&=0xAA; 544 | oled_buffer[i+1]&=0x55; 545 | } 546 | } 547 | //****************************************************************************** 548 | //****************************************************************************** 549 | 550 | -------------------------------------------------------------------------------- /Code/HWTest/vsd_GUI.h: -------------------------------------------------------------------------------- 1 | #ifndef VSD_GUI_H 2 | #define VSD_GUI_H 3 | 4 | #include 5 | 6 | #define sCOUNT(x) ((sizeof(x)/sizeof(x[0]))) 7 | 8 | #define VSD_TYPE_RO 0x80 /* read-only values */ 9 | 10 | void DrawOutputs(void); 11 | void DrawOutputs(uint16_t nX, uint16_t nY); 12 | 13 | typedef struct{ 14 | const char *str; 15 | char **names; 16 | void *val; 17 | int16_t min; 18 | int16_t max; 19 | uint8_t type; 20 | }sValueList; 21 | 22 | enum list_types{ 23 | lUINT8, 24 | lUINT16, 25 | lUINT32, 26 | lFLOAT, 27 | lSTR_LIST, 28 | lTIME_HMS, 29 | lSTR, 30 | lIP_ADDR, 31 | 32 | /* read-only values */ 33 | lUINT8_RO = lUINT8 | VSD_TYPE_RO, 34 | lUINT16_RO, 35 | lUINT32_RO, 36 | lFLOAT_RO, 37 | lSTR_LIST_RO, 38 | lTIME_HMS_RO, 39 | lSTR_RO, 40 | lIP_ADDR_RO, 41 | lSTR_MULTILINE, 42 | lFULL_SCREEN, 43 | }; 44 | 45 | typedef struct { 46 | uint16_t x; 47 | uint16_t y; 48 | uint16_t w; 49 | uint16_t h; 50 | }s_vsdBOX; 51 | 52 | typedef struct{ 53 | s_vsdBOX box; 54 | uint8_t *text; 55 | uint8_t sstr; 56 | uint8_t count; 57 | uint8_t indx; 58 | }vsdListBOX; 59 | 60 | typedef struct{ 61 | char **strs; 62 | uint8_t count; 63 | uint8_t curr_indx; 64 | }vsdStringGroup; 65 | 66 | typedef struct{ 67 | const char *strName; 68 | bool (*cbFunc)(void); 69 | }vsdMenuStrCb; 70 | 71 | typedef struct{ 72 | vsdMenuStrCb *StrCb; 73 | uint8_t count; 74 | uint8_t curr_indx; 75 | }vsdStrCbGroup; 76 | 77 | typedef struct{ 78 | 79 | }sMenu; 80 | 81 | enum line_style{ 82 | lsNONE, 83 | lsCLR, 84 | lsSOLID, 85 | lsDOTED, 86 | lsDOTED_12, 87 | lsDOTED_13, 88 | lsDOTED_14, 89 | lsDASHED_21, 90 | lsDASHED_31, 91 | lsDASHED_22, 92 | lsDASHED_32, 93 | }; 94 | 95 | class VSD_GUI/* : public U8GLIB*/{ 96 | 97 | U8GLIB *gui; 98 | uint16_t blink_pixel_count; 99 | uint8_t blink_set_val; 100 | uint8_t blink_clr_val; 101 | uint8_t blink_pixel_style; 102 | 103 | uint8_t print_buf[128]; 104 | 105 | public: 106 | VSD_GUI(U8GLIB *cgui) { gui=cgui; } 107 | 108 | void SetBlinkPixelCount(uint16_t bl){ blink_pixel_count=bl; } 109 | void SetBlinkPixelStyle(enum line_style style) { blink_pixel_style = style; } 110 | 111 | void DrawListBox(vsdListBOX *lbox); 112 | void DrawGroupBoxCentr(vsdStringGroup *str_gr, uint16_t x, uint16_t y); 113 | void DrawGroupBoxCentr(vsdStrCbGroup *str_gr, uint16_t x, uint16_t y, 114 | uint8_t line_offset = 0, uint8_t line_count = 0); 115 | 116 | uint8_t MaxSizeStrings(char **str, uint8_t cnt); 117 | uint8_t MaxSizeStrings(vsdStrCbGroup **StrCb); 118 | uint8_t MaxSizeStrings(vsdStringGroup *str_gr); 119 | 120 | void DrawTextCenter(uint16_t x, uint16_t y, const char *s); 121 | void DrawTextCenterOvr(uint16_t x, uint16_t y, const char *s, uint8_t neg); 122 | void DrawTextCenterFrame(uint16_t x, uint16_t y, const char *s); 123 | void DrawTextCenterFrame(uint16_t x, uint16_t y, const char *s, enum line_style style); 124 | void DrawTextCenterFrame_cl(uint16_t x, uint16_t y, const char *s, enum line_style style, int width=0); 125 | void DrawTextCenterFrame(uint16_t x, uint16_t y, const char *s, enum line_style style, uint16_t width); 126 | void DrawPixelBlink(uint16_t x, uint16_t y); 127 | 128 | void DrawLineVTop(uint16_t x, uint16_t y, uint16_t l); 129 | void DrawLineVBot(uint16_t x, uint16_t y, uint16_t l); 130 | void DrawLineHLeft(uint16_t x, uint16_t y, uint16_t l); 131 | void DrawLineHRight(uint16_t x, uint16_t y, uint16_t l); 132 | 133 | void DrawTimeHMS(uint32_t seconds); 134 | void DrawTimeHMS(uint16_t x, uint16_t y, uint32_t seconds); 135 | void DrawTimeHMS(uint16_t x, uint16_t y, uint32_t seconds, const u8g_fntpgm_uint8_t *font); 136 | 137 | int printf(const char *str, ...); 138 | int printf_n(const char *str, ...); 139 | int printf_p(char *str, ...); 140 | int printf_aright(const char *str, ...); 141 | int printf_center(const char *str, ...); 142 | 143 | /* Print a formatted string with black characters on a white background, with 144 | * center alignment 145 | * Parameters: printf-style 146 | * Returns: number of printed characters */ 147 | int printf_center_n(const char *str, ...); 148 | 149 | /* Print a string, occupying one or more display lines 150 | * Parameters: 151 | * - str: NULL-terminated string to be printed 152 | * - x_offset: horizontal offset on the display where each line should start, 153 | * expressed in pixels 154 | * - line_width: maximum width to be occupied by each line, expressed in 155 | * pixels 156 | * Returns: number of occupied lines */ 157 | int print_multiline(const char *str, int x_offset, int line_width); 158 | 159 | char* sb_printf(const char *str, ...); 160 | 161 | /* Get the number of pixels on the horizontal direction needed to print a 162 | * string on the display 163 | * This method supports multi-line strings (in which case the returned number 164 | * is the sum of the pixels of each line). 165 | * This method assumes that all characters in the string have equal spacing. 166 | * Parameters: 167 | * - str: NULL-terminated string to be printed 168 | * Returns: number of pixels needed to print the string */ 169 | int getStrWidth(const char *str); 170 | 171 | /* Get the number of display lines needed to print a string on the display 172 | * Parameters: 173 | * - str: NULL-terminated string to be printed 174 | * - line_width: maximum width to be occupied by each line, expressed in 175 | * pixels 176 | * Returns: number of lines needed to print the string */ 177 | int getLineCount(const char *str, int line_width); 178 | 179 | void ClrDisp(void); 180 | void ClrDisp_dt(void); 181 | 182 | void DrawValueList(const char *,sValueList*,uint8_t count, 183 | void (*check_cb)(int) = NULL); 184 | void DrawValueListVar(sValueList* lst); 185 | 186 | /* Draw a list of items, and return the item selected by the user 187 | * Parameters: 188 | * - title: string to be displayed at the top of the screen 189 | * - itemNames: array of strings corresponding to the list items to be 190 | * displayed 191 | * - itemCount: number of items to be displayed 192 | * Returns: zero-based index of item selected by the user, or a negative value 193 | * if no item was selected (i.e. the user pressed the SS button) 194 | * */ 195 | int DrawSelectionList(const char *title, const char *itemNames[], 196 | unsigned int itemCount); 197 | 198 | /* Draw the string value of a list item, occupying one or more display lines 199 | * Parameters: 200 | * - lst: pointer to list item 201 | * - line_count: if not NULL, pointer where the number of lines corresponding 202 | * to the string length is stored 203 | * Returns: number of lines occupied when drawing the item value, which may be 204 | * lower than the number of lines corresponding to the string length if the 205 | * string didn't fit in the display 206 | * */ 207 | int DrawMultiLine(sValueList *lst, uint8_t *line_count); 208 | 209 | /* Draw a list item in full-screen 210 | * Parameters: 211 | * - lst: pointer to list item 212 | * Returns: none 213 | * */ 214 | void DrawFullScreen(sValueList *lst); 215 | 216 | /* Draw a display-sized frame with a title string superimposed at the top left 217 | * Parameters: 218 | * - title: string to be superimposed on the top left corner of the frame 219 | * Returns: none 220 | * */ 221 | void DrawFrame(const char *title); 222 | 223 | void ChangeValueListVar(sValueList* lst); 224 | int ChangeVar(int val, int min, int max); 225 | int ChangeVar(char **str, uint8_t val, int min, int max); 226 | float ChangeVar(float val, int min, int max); 227 | uint32_t ChangeVarHMS(uint32_t val, int min, int max); 228 | uint32_t ChangeVarHMSw(uint32_t val, int min, int max); 229 | 230 | void DrawListMenu(const char *title, vsdStrCbGroup* lmenu); 231 | 232 | }; 233 | 234 | /* Callback to draw a list item in full-screen 235 | * Parameters: 236 | * - vsdGUI: reference to the VSD_GUI object that handles the GUI 237 | * - lst: pointer to list item whose contents have to be displayed 238 | * - keypress: key press received from the user (can be used to change displayed 239 | * contents depending on key presses, e.g. to scroll large content via the 240 | * UP and DOWN buttons). Note: BUTTON_SS key presses are not passed in this 241 | * argument, because when the calling code detect such key press it stops 242 | * calling this function; in order to be able to intercept all key presses, 243 | * this function should repeatedly call GetKeyPressF(). 244 | * Returns: false if the list item should continue to be displayed, true if the 245 | * GUI should exit from the current screen (e.g. due to user key 246 | * presses) 247 | * */ 248 | typedef bool (*vsdFullScreenCB)(VSD_GUI &vsdGUI, sValueList *lst, 249 | uint8_t keypress); 250 | 251 | extern U8GLIB mGUI; 252 | extern VSD_GUI vsdGUI; 253 | extern void WaitSynchDisplay(void); 254 | 255 | #endif 256 | -------------------------------------------------------------------------------- /Code/HWTest/vsd_Menu.cpp: -------------------------------------------------------------------------------- 1 | #include "ABM_Buttons.h" 2 | #include "ABM_Cfg.h" 3 | #include "run_mode.h" 4 | #include "vsd_GUI.h" 5 | #include "utlts.h" 6 | 7 | extern void WaitSynchDisplay(void); 8 | 9 | void VSD_GUI::DrawListMenu(const char *title, vsdStrCbGroup* lmenu) 10 | { 11 | uint8_t kb; 12 | gui->setFont(u8g_font_6x12r); 13 | while(kb!=BUTTON_SS){ 14 | kb=GetKeyPressF(); 15 | if(kb==BUTTON_UP) 16 | DecVal(&(lmenu->curr_indx), lmenu->count); 17 | else if(kb==BUTTON_DOWN) 18 | IncVal(&(lmenu->curr_indx), lmenu->count); 19 | else if(kb==BUTTON_ENTER) 20 | if ((lmenu->StrCb[lmenu->curr_indx].cbFunc!=NULL) 21 | && lmenu->StrCb[lmenu->curr_indx].cbFunc()) 22 | break; 23 | WaitSynchDisplay(); 24 | ClrDisp(); 25 | DrawGroupBoxCentr(lmenu,64,32); 26 | gui->setPrintPos(1,0); 27 | gui->setFontPosTop(); 28 | gui->print(title); 29 | RunBgTasks(); 30 | } 31 | WaitFreeAllKey(); 32 | } 33 | 34 | void BigMessSetFontParam(void) 35 | { 36 | WaitSynchDisplay(); 37 | mGUI.firstPage(); 38 | mGUI.setFont(u8g_font_10x20r); 39 | mGUI.setFontRefHeightText(); 40 | mGUI.setFontPosTop(); 41 | } 42 | void messInitEEprom(void) 43 | { 44 | BigMessSetFontParam(); 45 | mGUI.setPrintPos(10,20); 46 | mGUI.print("Init EEPROM"); 47 | } 48 | void messInitFuseBit(void) 49 | { 50 | BigMessSetFontParam(); 51 | mGUI.setPrintPos(15,20); 52 | mGUI.print("Init Fuse"); 53 | } 54 | void messReboot(void) 55 | { 56 | BigMessSetFontParam(); 57 | mGUI.setPrintPos(15,20); 58 | mGUI.print("go Reboot"); 59 | } 60 | -------------------------------------------------------------------------------- /Code/HWTest/vsd_macros.h: -------------------------------------------------------------------------------- 1 | #ifndef __VSD_MACROS 2 | #define __VSD_MACROS 3 | /*SAMD*/ 4 | /*macros for fast work GPIO and optimizing memory*/ 5 | /*(VSD)VoblNet vadim8097@gmail.com*/ 6 | 7 | #define PORT_A PORT->Group[0] 8 | #define PORT_B PORT->Group[1] 9 | 10 | #define _write_pin_(port,pin,val)\ 11 | {if(val) port.OUTSET.reg = (uint32_t)(1<< pin);\ 12 | else port.OUTCLR.reg = (uint32_t)(1<< pin);} 13 | 14 | #define WritePin(x,val) _write_pin_(x,val) 15 | #define WritePin_dir(port,pin,val) _write_pin_(port,pin,val) 16 | 17 | #define _read_pin_(port,pin)\ 18 | ((port.IN.reg & (uint32_t)(1<< pin))==0?0:1) 19 | #define ReadPin(x) _read_pin_(x) 20 | 21 | #define _ddr_init_INPU(port,pin)\ 22 | {port.PINCFG[pin].reg=(uint8_t)(PORT_PINCFG_INEN|PORT_PINCFG_PULLEN);\ 23 | port.DIRCLR.reg = (uint32_t)(1<> 1].reg) & PORT_PMUX_PMUXE( 0xF ) ;\ 61 | port.PMUX[pin >> 1].reg = temp|PORT_PMUX_PMUXO( PIO_ANALOG ) ;\ 62 | port.PINCFG[pin].reg |= PORT_PINCFG_PMUXEN ;\ 63 | }\ 64 | else\ 65 | {\ 66 | uint32_t temp ;\ 67 | temp = (port.PMUX[pin >> 1].reg) & PORT_PMUX_PMUXO( 0xF ) ;\ 68 | port.PMUX[pin >> 1].reg = temp|PORT_PMUX_PMUXE( PIO_ANALOG ) ;\ 69 | port.PINCFG[pin].reg |= PORT_PINCFG_PMUXEN ;\ 70 | }\ 71 | }\ 72 | 73 | 74 | #define _llr_init_(port,pin,dd) _ddr_init_##dd(port,pin) 75 | #define _llr_init_n(port,pin,ddn) _llr_init_(port,pin,ddn) 76 | #define InitPin(x,ddn) _llr_init_n(x,ddn) 77 | #define InitPinDef(x) _llr_init_(x) 78 | 79 | /* 80 | #define _write_pin_(port,pin,dd,val)\ 81 | {if(val) PORT->Group[PORT##port].OUTSET.reg = (uint32_t)(1<< pin);\ 82 | else PORT->Group[PORT##port].OUTCLR.reg = (uint32_t)(1<< pin);} 83 | 84 | #define WritePin(x,val) _write_pin_(x,val) 85 | 86 | #define _read_pin_(port,pin,dd)\ 87 | ((PORT->Group[PORT##port].IN.reg & (uint32_t)(1<< pin))==0?0:1) 88 | #define ReadPin(x) _read_pin_(x) 89 | 90 | #define _ddr_init_INPU(port,pin)\ 91 | {PORT->Group[port].PINCFG[pin].reg=(uint8_t)(PORT_PINCFG_INEN|PORT_PINCFG_PULLEN);\ 92 | PORT->Group[port].DIRCLR.reg = (uint32_t)(1<Group[port].OUTSET.reg = (uint32_t)(1<Group[port].PINCFG[pin].reg=(uint8_t)(PORT_PINCFG_INEN|PORT_PINCFG_PULLEN);\ 97 | PORT->Group[port].DIRCLR.reg = (uint32_t)(1<Group[port].OUTCLR.reg = (uint32_t)(1<Group[port].PINCFG[pin].reg=(uint8_t)(PORT_PINCFG_INEN);\ 102 | PORT->Group[port].DIRCLR.reg = (uint32_t)(1<Group[port].PINCFG[pin].reg=(uint8_t)(PORT_PINCFG_INEN);\ 106 | PORT->Group[port].DIRSET.reg = (uint32_t)(1<Group[port].PINCFG[pin].reg&=~(uint8_t)(PORT_PINCFG_INEN);\ 110 | PORT->Group[port].DIRSET.reg = (uint32_t)(1<Group[port].PINCFG[pin].reg&=~(uint8_t)(PORT_PINCFG_INEN);\ 114 | PORT->Group[port].DIRSET.reg = (uint32_t)(1<Group[port].OUTSET.reg = (uint32_t)(1<Group[port].PINCFG[pin].reg&=~(uint8_t)(PORT_PINCFG_INEN);\ 119 | PORT->Group[port].DIRSET.reg = (uint32_t)(1<Group[port].OUTCLR.reg = (uint32_t)(1< 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /Libraries/HWTest_libraries-v2.0-002.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Libraries/HWTest_libraries-v2.0-002.zip -------------------------------------------------------------------------------- /Libraries/README.md: -------------------------------------------------------------------------------- 1 | # Libraries 2 | 3 | this folder contains the libraries used by arduino IDE and should be unzipped inside the local libraries folder 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /Manual/README.md: -------------------------------------------------------------------------------- 1 | # manual 2 | 3 | this folder contains the SmartPID manuals 4 | 5 | Quick start guide 6 | very short introduction and basic operation 7 | 8 | Installation and configuration manual 9 | provide all instruction to: 10 | install and connect smartPID to your ecosystem, 11 | hw configuration, 12 | wifi setup and data logging via thingspeak service, 13 | Arduino IDE connection and programming, 14 | FW upgrade and reset to factory 15 | 16 | Application manual 17 | provide instruction for the application usage and configuration: 18 | Smart home-brewing app and Smart thermostat 19 | 20 | 21 | -------------------------------------------------------------------------------- /Manual/SmartPID SPC1000 USER MANUAL 1.0.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Manual/SmartPID SPC1000 USER MANUAL 1.0.pdf -------------------------------------------------------------------------------- /Manual/SmartPID SPC1000 installation and configuration manual 1.3.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Manual/SmartPID SPC1000 installation and configuration manual 1.3.pdf -------------------------------------------------------------------------------- /Picture/2016-11-25 19_57_43-Greenshot (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/2016-11-25 19_57_43-Greenshot (1).png -------------------------------------------------------------------------------- /Picture/2016-11-25 19_57_43-Greenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/2016-11-25 19_57_43-Greenshot.png -------------------------------------------------------------------------------- /Picture/BANNER-2 (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/BANNER-2 (1).png -------------------------------------------------------------------------------- /Picture/BANNER-2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/BANNER-2.png -------------------------------------------------------------------------------- /Picture/BANNER-3 (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/BANNER-3 (1).png -------------------------------------------------------------------------------- /Picture/BANNER-3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/BANNER-3.png -------------------------------------------------------------------------------- /Picture/BANNER-4 (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/BANNER-4 (1).png -------------------------------------------------------------------------------- /Picture/BANNER-4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/BANNER-4.png -------------------------------------------------------------------------------- /Picture/BANNER-5 (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/BANNER-5 (1).png -------------------------------------------------------------------------------- /Picture/BANNER-5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/BANNER-5.png -------------------------------------------------------------------------------- /Picture/Pro101SmartID2 (1).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/Pro101SmartID2 (1).jpg -------------------------------------------------------------------------------- /Picture/Pro101SmartID2.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/Pro101SmartID2.jpg -------------------------------------------------------------------------------- /Picture/arm+smad21 (1).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/arm+smad21 (1).jpg -------------------------------------------------------------------------------- /Picture/arm+smad21.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/arm+smad21.jpg -------------------------------------------------------------------------------- /Picture/circuit-board.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/circuit-board.png -------------------------------------------------------------------------------- /Picture/header.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/header.jpg -------------------------------------------------------------------------------- /Picture/img-features (1).png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/img-features (1).png -------------------------------------------------------------------------------- /Picture/img-features.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/img-features.png -------------------------------------------------------------------------------- /Picture/multipe smartpid applications.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/multipe smartpid applications.jpg -------------------------------------------------------------------------------- /Picture/smarphone app smarpid (1).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/smarphone app smarpid (1).jpg -------------------------------------------------------------------------------- /Picture/smarphone app smarpid.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/smarphone app smarpid.jpg -------------------------------------------------------------------------------- /Picture/smartPID HW overview (1).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/smartPID HW overview (1).jpg -------------------------------------------------------------------------------- /Picture/smartPID HW overview.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/smartPID HW overview.jpg -------------------------------------------------------------------------------- /Picture/smartPID HW.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/smartPID HW.jpg -------------------------------------------------------------------------------- /Picture/smartPID assembling (1).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/smartPID assembling (1).jpg -------------------------------------------------------------------------------- /Picture/smartPID assembling.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/smartPID assembling.jpg -------------------------------------------------------------------------------- /Picture/smartpid APK install.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/smartpid APK install.png -------------------------------------------------------------------------------- /Picture/specs (1).jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/specs (1).jpg -------------------------------------------------------------------------------- /Picture/specs.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/Picture/specs.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/arzaman/smartPID/ae46786aa2b3a229f6b425821a41fb0e70db5f8b/README.md --------------------------------------------------------------------------------