Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: UniGraphic mbed vt100
edge_temp.cpp
00001 #include "mbed.h" 00002 #include "LM75B.h" 00003 #include "edge_reset_mgr.h" 00004 #include "edge_sensor.h" 00005 #include "edge_temp.h" 00006 #include "edge_chart.h" 00007 00008 float *current_temp = 0 ; 00009 00010 edge_temp::edge_temp(LM75B *temp1, SMTC502AT *temp2, SMTC502AT *temp3, LM75B *temp4) 00011 { 00012 _temp1 = temp1 ; 00013 _temp2 = temp2 ; 00014 _temp3 = temp3 ; 00015 _temp4 = temp4 ; 00016 _ftemp[0] = _ftemp[1] = _ftemp[2] = _ftemp[3] = 0.0 ; 00017 _interval = 30 ; 00018 current_temp = &_ftemp[1] ; /* use before for current temp */ 00019 } 00020 00021 edge_temp::~edge_temp(void) 00022 { 00023 if (_temp1) { 00024 delete _temp1 ; 00025 } 00026 if (_temp2) { 00027 delete _temp2 ; 00028 } 00029 if (_temp3) { 00030 delete _temp3 ; 00031 } 00032 if (_temp4) { 00033 delete _temp4 ; 00034 } 00035 } 00036 00037 void edge_temp::reset(void) 00038 { 00039 } 00040 00041 void edge_temp::prepare(void) 00042 { 00043 } 00044 00045 int edge_temp::sample(void) 00046 { 00047 int result ; 00048 if (_temp1) { 00049 result = _temp1->getTemp(&_ftemp[0]) ; 00050 } 00051 if (_temp2) { 00052 _ftemp[1] = _temp2->getTemp() ; 00053 } 00054 if (_temp3) { 00055 _ftemp[2] = _temp3->getTemp() ; 00056 } 00057 if (_temp4) { 00058 _temp4->getTemp(&_ftemp[3]) ; 00059 } 00060 _sampled_time = edge_time ; 00061 return( result ) ; 00062 } 00063 00064 int edge_temp::deliver(void) 00065 { 00066 int result ; 00067 char timestr[16] ; 00068 00069 print_time() ; 00070 printf(" temp: ") ; 00071 if (_temp1) { 00072 printf("LM75B1 = %.2f ", _ftemp[0]) ; 00073 } 00074 if (_temp2) { 00075 printf("before = %.2f ", _ftemp[1]) ; 00076 } 00077 if (_temp3) { 00078 printf("after = %.2f ", _ftemp[2]) ; 00079 } 00080 if (_temp4) { 00081 printf("LM75B2 = %.2f ", _ftemp[3]) ; 00082 } 00083 printf("\n") ; 00084 time2seq(_sampled_time, timestr) ; 00085 sprintf(_str_buf, 00086 "{\"DEVICE\":\"TEMP04\",\"VAL_1\":\"%.1f\",\"VAL_2\":\"%.1f\",\"VAL_3\":\"%.1f\",\"T\":\"%s\",\"E\":\"%d\"}", 00087 _ftemp[0], _ftemp[1], _ftemp[2], timestr, _error_count) ; 00088 result = afero->setAttribute(1, _str_buf) ; 00089 return( result == afSUCCESS ) ; 00090 } 00091 00092 int temp_v2y(float value, edge_chart_type *p) 00093 { 00094 int y ; 00095 if (value < p->min) { 00096 value = p->min ; 00097 } else if (value > p->max) { 00098 value = p->max ; 00099 } 00100 y = p->top + p->height - 1 00101 - (int)((p->height - 2) * value /(p->max - p->min)) ; 00102 return( y ) ; 00103 } 00104 00105 void edge_temp::show(void) 00106 { 00107 edge_chart_type *p = &edge_chart[ _id ] ; 00108 int x, temp, before, after ; 00109 reset_watch_dog() ; 00110 if (display) { 00111 switch(display_mode) { 00112 case DISPLAY_MODE_SUMMARY: 00113 display->BusEnable(true) ; 00114 display->set_font((unsigned char*) Arial12x12); 00115 display->set_font_zoom(2, 2) ; 00116 display->foreground(White) ; 00117 display->locate(EDGE_SUMMARY_X, EDGE_SUMMARY_TIME_Y) ; 00118 displayTime(_sampled_time) ; 00119 display->locate(EDGE_SUMMARY_X, EDGE_SUMMARY_TEMP_Y) ; 00120 display->printf("Temp : %.2f %.2f %.2f",_ftemp[0], _ftemp[1], _ftemp[2]) ; 00121 display->BusEnable(false) ; 00122 reset_watch_dog() ; 00123 break ; 00124 case DISPLAY_MODE_CHART: 00125 x = p->left + p->index + 1; 00126 temp = temp_v2y(_ftemp[0], p) ; 00127 before = temp_v2y(_ftemp[1], p) ; 00128 after = temp_v2y(_ftemp[2], p) ; 00129 display->BusEnable(true) ; 00130 if (p->index == 0) { 00131 draw_chart_frame(p) ; 00132 } 00133 display->pixel(x, temp, White) ; 00134 display->pixel(x, before, Red) ; 00135 display->pixel(x, after, Blue) ; 00136 display->BusEnable(false) ; 00137 p->index = (p->index + 1) % (p->width - 2) ; 00138 break ; 00139 } 00140 } 00141 reset_watch_dog() ; 00142 } 00143
Generated on Fri Jul 15 2022 06:01:06 by
1.7.2