Gas Pressure Display Updated Power control for Pressure sensor added

Dependencies:   UniGraphic mbed vt100

Committer:
Rhyme
Date:
Fri Feb 16 08:27:50 2018 +0000
Revision:
0:37c8ecde13c2
control PSE530 power via PTC5 (pse530_en)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:37c8ecde13c2 1 #include "mbed.h"
Rhyme 0:37c8ecde13c2 2 #include "LM75B.h"
Rhyme 0:37c8ecde13c2 3 #include "edge_reset_mgr.h"
Rhyme 0:37c8ecde13c2 4 #include "edge_sensor.h"
Rhyme 0:37c8ecde13c2 5 #include "edge_temp.h"
Rhyme 0:37c8ecde13c2 6 #include "edge_chart.h"
Rhyme 0:37c8ecde13c2 7
Rhyme 0:37c8ecde13c2 8 float *current_temp = 0 ;
Rhyme 0:37c8ecde13c2 9
Rhyme 0:37c8ecde13c2 10 edge_temp::edge_temp(LM75B *temp1, SMTC502AT *temp2, SMTC502AT *temp3, LM75B *temp4)
Rhyme 0:37c8ecde13c2 11 {
Rhyme 0:37c8ecde13c2 12 _temp1 = temp1 ;
Rhyme 0:37c8ecde13c2 13 _temp2 = temp2 ;
Rhyme 0:37c8ecde13c2 14 _temp3 = temp3 ;
Rhyme 0:37c8ecde13c2 15 _temp4 = temp4 ;
Rhyme 0:37c8ecde13c2 16 _ftemp[0] = _ftemp[1] = _ftemp[2] = _ftemp[3] = 0.0 ;
Rhyme 0:37c8ecde13c2 17 _interval = 30 ;
Rhyme 0:37c8ecde13c2 18 current_temp = &_ftemp[1] ; /* use before for current temp */
Rhyme 0:37c8ecde13c2 19 }
Rhyme 0:37c8ecde13c2 20
Rhyme 0:37c8ecde13c2 21 edge_temp::~edge_temp(void)
Rhyme 0:37c8ecde13c2 22 {
Rhyme 0:37c8ecde13c2 23 if (_temp1) {
Rhyme 0:37c8ecde13c2 24 delete _temp1 ;
Rhyme 0:37c8ecde13c2 25 }
Rhyme 0:37c8ecde13c2 26 if (_temp2) {
Rhyme 0:37c8ecde13c2 27 delete _temp2 ;
Rhyme 0:37c8ecde13c2 28 }
Rhyme 0:37c8ecde13c2 29 if (_temp3) {
Rhyme 0:37c8ecde13c2 30 delete _temp3 ;
Rhyme 0:37c8ecde13c2 31 }
Rhyme 0:37c8ecde13c2 32 if (_temp4) {
Rhyme 0:37c8ecde13c2 33 delete _temp4 ;
Rhyme 0:37c8ecde13c2 34 }
Rhyme 0:37c8ecde13c2 35 }
Rhyme 0:37c8ecde13c2 36
Rhyme 0:37c8ecde13c2 37 void edge_temp::reset(void)
Rhyme 0:37c8ecde13c2 38 {
Rhyme 0:37c8ecde13c2 39 }
Rhyme 0:37c8ecde13c2 40
Rhyme 0:37c8ecde13c2 41 void edge_temp::prepare(void)
Rhyme 0:37c8ecde13c2 42 {
Rhyme 0:37c8ecde13c2 43 }
Rhyme 0:37c8ecde13c2 44
Rhyme 0:37c8ecde13c2 45 int edge_temp::sample(void)
Rhyme 0:37c8ecde13c2 46 {
Rhyme 0:37c8ecde13c2 47 int result ;
Rhyme 0:37c8ecde13c2 48 if (_temp1) {
Rhyme 0:37c8ecde13c2 49 result = _temp1->getTemp(&_ftemp[0]) ;
Rhyme 0:37c8ecde13c2 50 }
Rhyme 0:37c8ecde13c2 51 if (_temp2) {
Rhyme 0:37c8ecde13c2 52 _ftemp[1] = _temp2->getTemp() ;
Rhyme 0:37c8ecde13c2 53 }
Rhyme 0:37c8ecde13c2 54 if (_temp3) {
Rhyme 0:37c8ecde13c2 55 _ftemp[2] = _temp3->getTemp() ;
Rhyme 0:37c8ecde13c2 56 }
Rhyme 0:37c8ecde13c2 57 if (_temp4) {
Rhyme 0:37c8ecde13c2 58 _temp4->getTemp(&_ftemp[3]) ;
Rhyme 0:37c8ecde13c2 59 }
Rhyme 0:37c8ecde13c2 60 _sampled_time = edge_time ;
Rhyme 0:37c8ecde13c2 61 return( result ) ;
Rhyme 0:37c8ecde13c2 62 }
Rhyme 0:37c8ecde13c2 63
Rhyme 0:37c8ecde13c2 64 int edge_temp::deliver(void)
Rhyme 0:37c8ecde13c2 65 {
Rhyme 0:37c8ecde13c2 66 int result ;
Rhyme 0:37c8ecde13c2 67 char timestr[16] ;
Rhyme 0:37c8ecde13c2 68
Rhyme 0:37c8ecde13c2 69 print_time() ;
Rhyme 0:37c8ecde13c2 70 printf(" temp: ") ;
Rhyme 0:37c8ecde13c2 71 if (_temp1) {
Rhyme 0:37c8ecde13c2 72 printf("LM75B1 = %.2f ", _ftemp[0]) ;
Rhyme 0:37c8ecde13c2 73 }
Rhyme 0:37c8ecde13c2 74 if (_temp2) {
Rhyme 0:37c8ecde13c2 75 printf("before = %.2f ", _ftemp[1]) ;
Rhyme 0:37c8ecde13c2 76 }
Rhyme 0:37c8ecde13c2 77 if (_temp3) {
Rhyme 0:37c8ecde13c2 78 printf("after = %.2f ", _ftemp[2]) ;
Rhyme 0:37c8ecde13c2 79 }
Rhyme 0:37c8ecde13c2 80 if (_temp4) {
Rhyme 0:37c8ecde13c2 81 printf("LM75B2 = %.2f ", _ftemp[3]) ;
Rhyme 0:37c8ecde13c2 82 }
Rhyme 0:37c8ecde13c2 83 printf("\n") ;
Rhyme 0:37c8ecde13c2 84 time2seq(_sampled_time, timestr) ;
Rhyme 0:37c8ecde13c2 85 sprintf(_str_buf,
Rhyme 0:37c8ecde13c2 86 "{\"DEVICE\":\"TEMP04\",\"VAL_1\":\"%.1f\",\"VAL_2\":\"%.1f\",\"VAL_3\":\"%.1f\",\"T\":\"%s\",\"E\":\"%d\"}",
Rhyme 0:37c8ecde13c2 87 _ftemp[0], _ftemp[1], _ftemp[2], timestr, _error_count) ;
Rhyme 0:37c8ecde13c2 88 result = afero->setAttribute(1, _str_buf) ;
Rhyme 0:37c8ecde13c2 89 return( result == afSUCCESS ) ;
Rhyme 0:37c8ecde13c2 90 }
Rhyme 0:37c8ecde13c2 91
Rhyme 0:37c8ecde13c2 92 int temp_v2y(float value, edge_chart_type *p)
Rhyme 0:37c8ecde13c2 93 {
Rhyme 0:37c8ecde13c2 94 int y ;
Rhyme 0:37c8ecde13c2 95 if (value < p->min) {
Rhyme 0:37c8ecde13c2 96 value = p->min ;
Rhyme 0:37c8ecde13c2 97 } else if (value > p->max) {
Rhyme 0:37c8ecde13c2 98 value = p->max ;
Rhyme 0:37c8ecde13c2 99 }
Rhyme 0:37c8ecde13c2 100 y = p->top + p->height - 1
Rhyme 0:37c8ecde13c2 101 - (int)((p->height - 2) * value /(p->max - p->min)) ;
Rhyme 0:37c8ecde13c2 102 return( y ) ;
Rhyme 0:37c8ecde13c2 103 }
Rhyme 0:37c8ecde13c2 104
Rhyme 0:37c8ecde13c2 105 void edge_temp::show(void)
Rhyme 0:37c8ecde13c2 106 {
Rhyme 0:37c8ecde13c2 107 edge_chart_type *p = &edge_chart[ _id ] ;
Rhyme 0:37c8ecde13c2 108 int x, temp, before, after ;
Rhyme 0:37c8ecde13c2 109 reset_watch_dog() ;
Rhyme 0:37c8ecde13c2 110 if (display) {
Rhyme 0:37c8ecde13c2 111 switch(display_mode) {
Rhyme 0:37c8ecde13c2 112 case DISPLAY_MODE_SUMMARY:
Rhyme 0:37c8ecde13c2 113 display->BusEnable(true) ;
Rhyme 0:37c8ecde13c2 114 display->set_font((unsigned char*) Arial12x12);
Rhyme 0:37c8ecde13c2 115 display->set_font_zoom(2, 2) ;
Rhyme 0:37c8ecde13c2 116 display->foreground(White) ;
Rhyme 0:37c8ecde13c2 117 display->locate(EDGE_SUMMARY_X, EDGE_SUMMARY_TIME_Y) ;
Rhyme 0:37c8ecde13c2 118 displayTime(_sampled_time) ;
Rhyme 0:37c8ecde13c2 119 display->locate(EDGE_SUMMARY_X, EDGE_SUMMARY_TEMP_Y) ;
Rhyme 0:37c8ecde13c2 120 display->printf("Temp : %.2f %.2f %.2f",_ftemp[0], _ftemp[1], _ftemp[2]) ;
Rhyme 0:37c8ecde13c2 121 display->BusEnable(false) ;
Rhyme 0:37c8ecde13c2 122 reset_watch_dog() ;
Rhyme 0:37c8ecde13c2 123 break ;
Rhyme 0:37c8ecde13c2 124 case DISPLAY_MODE_CHART:
Rhyme 0:37c8ecde13c2 125 x = p->left + p->index + 1;
Rhyme 0:37c8ecde13c2 126 temp = temp_v2y(_ftemp[0], p) ;
Rhyme 0:37c8ecde13c2 127 before = temp_v2y(_ftemp[1], p) ;
Rhyme 0:37c8ecde13c2 128 after = temp_v2y(_ftemp[2], p) ;
Rhyme 0:37c8ecde13c2 129 display->BusEnable(true) ;
Rhyme 0:37c8ecde13c2 130 if (p->index == 0) {
Rhyme 0:37c8ecde13c2 131 draw_chart_frame(p) ;
Rhyme 0:37c8ecde13c2 132 }
Rhyme 0:37c8ecde13c2 133 display->pixel(x, temp, White) ;
Rhyme 0:37c8ecde13c2 134 display->pixel(x, before, Red) ;
Rhyme 0:37c8ecde13c2 135 display->pixel(x, after, Blue) ;
Rhyme 0:37c8ecde13c2 136 display->BusEnable(false) ;
Rhyme 0:37c8ecde13c2 137 p->index = (p->index + 1) % (p->width - 2) ;
Rhyme 0:37c8ecde13c2 138 break ;
Rhyme 0:37c8ecde13c2 139 }
Rhyme 0:37c8ecde13c2 140 }
Rhyme 0:37c8ecde13c2 141 reset_watch_dog() ;
Rhyme 0:37c8ecde13c2 142 }
Rhyme 0:37c8ecde13c2 143