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