I2C hang recover function added
Dependencies: UniGraphic mbed vt100
In this version, check_i2c_pins function was added in edge_mgr.cpp.
プログラムの起動時、I2Cモジュールを初期化する前に、I2Cに使用するピンの電位を確認し
もし一方でも Low に張り付いていた場合、SCL を GPIO 出力に設定して
所定回数 (I2C_UNLOCK_TRIAL_CYCLE) 反転させることにより、疑似リセットクロックを生成します。
その後は、通常の起動手順に復帰し、以降はこれまでと同様の動作をします。
edge_sensor/edge_temp.cpp@0:d895cd1cd897, 2018-04-03 (annotated)
- Committer:
- Rhyme
- Date:
- Tue Apr 03 08:30:29 2018 +0000
- Revision:
- 0:d895cd1cd897
Initial I2C Pin force reset function added
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Rhyme | 0:d895cd1cd897 | 1 | #include "mbed.h" |
Rhyme | 0:d895cd1cd897 | 2 | #include "LM75B.h" |
Rhyme | 0:d895cd1cd897 | 3 | #include "edge_reset_mgr.h" |
Rhyme | 0:d895cd1cd897 | 4 | #include "edge_sensor.h" |
Rhyme | 0:d895cd1cd897 | 5 | #include "edge_temp.h" |
Rhyme | 0:d895cd1cd897 | 6 | #include "edge_chart.h" |
Rhyme | 0:d895cd1cd897 | 7 | |
Rhyme | 0:d895cd1cd897 | 8 | float *current_temp = 0 ; |
Rhyme | 0:d895cd1cd897 | 9 | |
Rhyme | 0:d895cd1cd897 | 10 | edge_temp::edge_temp(LM75B *temp1, SMTC502AT *temp2, SMTC502AT *temp3, LM75B *temp4) |
Rhyme | 0:d895cd1cd897 | 11 | { |
Rhyme | 0:d895cd1cd897 | 12 | _temp1 = temp1 ; |
Rhyme | 0:d895cd1cd897 | 13 | _temp2 = temp2 ; |
Rhyme | 0:d895cd1cd897 | 14 | _temp3 = temp3 ; |
Rhyme | 0:d895cd1cd897 | 15 | _temp4 = temp4 ; |
Rhyme | 0:d895cd1cd897 | 16 | _ftemp[0] = _ftemp[1] = _ftemp[2] = _ftemp[3] = 0.0 ; |
Rhyme | 0:d895cd1cd897 | 17 | _interval = 30 ; |
Rhyme | 0:d895cd1cd897 | 18 | current_temp = &_ftemp[1] ; /* use before for current temp */ |
Rhyme | 0:d895cd1cd897 | 19 | } |
Rhyme | 0:d895cd1cd897 | 20 | |
Rhyme | 0:d895cd1cd897 | 21 | edge_temp::~edge_temp(void) |
Rhyme | 0:d895cd1cd897 | 22 | { |
Rhyme | 0:d895cd1cd897 | 23 | if (_temp1) { |
Rhyme | 0:d895cd1cd897 | 24 | delete _temp1 ; |
Rhyme | 0:d895cd1cd897 | 25 | } |
Rhyme | 0:d895cd1cd897 | 26 | if (_temp2) { |
Rhyme | 0:d895cd1cd897 | 27 | delete _temp2 ; |
Rhyme | 0:d895cd1cd897 | 28 | } |
Rhyme | 0:d895cd1cd897 | 29 | if (_temp3) { |
Rhyme | 0:d895cd1cd897 | 30 | delete _temp3 ; |
Rhyme | 0:d895cd1cd897 | 31 | } |
Rhyme | 0:d895cd1cd897 | 32 | if (_temp4) { |
Rhyme | 0:d895cd1cd897 | 33 | delete _temp4 ; |
Rhyme | 0:d895cd1cd897 | 34 | } |
Rhyme | 0:d895cd1cd897 | 35 | } |
Rhyme | 0:d895cd1cd897 | 36 | |
Rhyme | 0:d895cd1cd897 | 37 | void edge_temp::reset(void) |
Rhyme | 0:d895cd1cd897 | 38 | { |
Rhyme | 0:d895cd1cd897 | 39 | } |
Rhyme | 0:d895cd1cd897 | 40 | |
Rhyme | 0:d895cd1cd897 | 41 | void edge_temp::prepare(void) |
Rhyme | 0:d895cd1cd897 | 42 | { |
Rhyme | 0:d895cd1cd897 | 43 | } |
Rhyme | 0:d895cd1cd897 | 44 | |
Rhyme | 0:d895cd1cd897 | 45 | int edge_temp::sample(void) |
Rhyme | 0:d895cd1cd897 | 46 | { |
Rhyme | 0:d895cd1cd897 | 47 | int result ; |
Rhyme | 0:d895cd1cd897 | 48 | if (_temp1) { |
Rhyme | 0:d895cd1cd897 | 49 | result = _temp1->getTemp(&_ftemp[0]) ; |
Rhyme | 0:d895cd1cd897 | 50 | } |
Rhyme | 0:d895cd1cd897 | 51 | if (_temp2) { |
Rhyme | 0:d895cd1cd897 | 52 | _ftemp[1] = _temp2->getTemp() ; |
Rhyme | 0:d895cd1cd897 | 53 | } |
Rhyme | 0:d895cd1cd897 | 54 | if (_temp3) { |
Rhyme | 0:d895cd1cd897 | 55 | _ftemp[2] = _temp3->getTemp() ; |
Rhyme | 0:d895cd1cd897 | 56 | } |
Rhyme | 0:d895cd1cd897 | 57 | if (_temp4) { |
Rhyme | 0:d895cd1cd897 | 58 | _temp4->getTemp(&_ftemp[3]) ; |
Rhyme | 0:d895cd1cd897 | 59 | } |
Rhyme | 0:d895cd1cd897 | 60 | _sampled_time = edge_time ; |
Rhyme | 0:d895cd1cd897 | 61 | return( result ) ; |
Rhyme | 0:d895cd1cd897 | 62 | } |
Rhyme | 0:d895cd1cd897 | 63 | |
Rhyme | 0:d895cd1cd897 | 64 | int edge_temp::deliver(void) |
Rhyme | 0:d895cd1cd897 | 65 | { |
Rhyme | 0:d895cd1cd897 | 66 | int result ; |
Rhyme | 0:d895cd1cd897 | 67 | char timestr[16] ; |
Rhyme | 0:d895cd1cd897 | 68 | |
Rhyme | 0:d895cd1cd897 | 69 | print_time() ; |
Rhyme | 0:d895cd1cd897 | 70 | printf(" temp: ") ; |
Rhyme | 0:d895cd1cd897 | 71 | if (_temp1) { |
Rhyme | 0:d895cd1cd897 | 72 | printf("LM75B1 = %.2f ", _ftemp[0]) ; |
Rhyme | 0:d895cd1cd897 | 73 | } |
Rhyme | 0:d895cd1cd897 | 74 | if (_temp2) { |
Rhyme | 0:d895cd1cd897 | 75 | printf("before = %.2f ", _ftemp[1]) ; |
Rhyme | 0:d895cd1cd897 | 76 | } |
Rhyme | 0:d895cd1cd897 | 77 | if (_temp3) { |
Rhyme | 0:d895cd1cd897 | 78 | printf("after = %.2f ", _ftemp[2]) ; |
Rhyme | 0:d895cd1cd897 | 79 | } |
Rhyme | 0:d895cd1cd897 | 80 | if (_temp4) { |
Rhyme | 0:d895cd1cd897 | 81 | printf("LM75B2 = %.2f ", _ftemp[3]) ; |
Rhyme | 0:d895cd1cd897 | 82 | } |
Rhyme | 0:d895cd1cd897 | 83 | printf("\n") ; |
Rhyme | 0:d895cd1cd897 | 84 | time2seq(_sampled_time, timestr) ; |
Rhyme | 0:d895cd1cd897 | 85 | sprintf(_str_buf, |
Rhyme | 0:d895cd1cd897 | 86 | "{\"DEVICE\":\"TEMP04\",\"VAL_1\":\"%.1f\",\"VAL_2\":\"%.1f\",\"VAL_3\":\"%.1f\",\"T\":\"%s\",\"E\":\"%d\"}", |
Rhyme | 0:d895cd1cd897 | 87 | _ftemp[0], _ftemp[1], _ftemp[2], timestr, _error_count) ; |
Rhyme | 0:d895cd1cd897 | 88 | result = afero->setAttribute(1, _str_buf) ; |
Rhyme | 0:d895cd1cd897 | 89 | return( result == afSUCCESS ) ; |
Rhyme | 0:d895cd1cd897 | 90 | } |
Rhyme | 0:d895cd1cd897 | 91 | |
Rhyme | 0:d895cd1cd897 | 92 | int temp_v2y(float value, edge_chart_type *p) |
Rhyme | 0:d895cd1cd897 | 93 | { |
Rhyme | 0:d895cd1cd897 | 94 | int y ; |
Rhyme | 0:d895cd1cd897 | 95 | if (value < p->min) { |
Rhyme | 0:d895cd1cd897 | 96 | value = p->min ; |
Rhyme | 0:d895cd1cd897 | 97 | } else if (value > p->max) { |
Rhyme | 0:d895cd1cd897 | 98 | value = p->max ; |
Rhyme | 0:d895cd1cd897 | 99 | } |
Rhyme | 0:d895cd1cd897 | 100 | y = p->top + p->height - 1 |
Rhyme | 0:d895cd1cd897 | 101 | - (int)((p->height - 2) * (value - p->min) /(p->max - p->min)) ; |
Rhyme | 0:d895cd1cd897 | 102 | return( y ) ; |
Rhyme | 0:d895cd1cd897 | 103 | } |
Rhyme | 0:d895cd1cd897 | 104 | |
Rhyme | 0:d895cd1cd897 | 105 | void edge_temp::show(void) |
Rhyme | 0:d895cd1cd897 | 106 | { |
Rhyme | 0:d895cd1cd897 | 107 | edge_chart_type *p = &edge_chart[ _id ] ; |
Rhyme | 0:d895cd1cd897 | 108 | int x, temp, before, after ; |
Rhyme | 0:d895cd1cd897 | 109 | reset_watch_dog() ; |
Rhyme | 0:d895cd1cd897 | 110 | if (display) { |
Rhyme | 0:d895cd1cd897 | 111 | switch(display_mode) { |
Rhyme | 0:d895cd1cd897 | 112 | case DISPLAY_MODE_SUMMARY: |
Rhyme | 0:d895cd1cd897 | 113 | display->BusEnable(true) ; |
Rhyme | 0:d895cd1cd897 | 114 | display->set_font((unsigned char*) Arial12x12); |
Rhyme | 0:d895cd1cd897 | 115 | display->set_font_zoom(2, 2) ; |
Rhyme | 0:d895cd1cd897 | 116 | display->foreground(White) ; |
Rhyme | 0:d895cd1cd897 | 117 | display->locate(EDGE_SUMMARY_X, EDGE_SUMMARY_TIME_Y) ; |
Rhyme | 0:d895cd1cd897 | 118 | displayTime(_sampled_time) ; |
Rhyme | 0:d895cd1cd897 | 119 | display->locate(EDGE_SUMMARY_X, EDGE_SUMMARY_TEMP_Y) ; |
Rhyme | 0:d895cd1cd897 | 120 | display->printf("Temp : %.2f %.2f %.2f",_ftemp[0], _ftemp[1], _ftemp[2]) ; |
Rhyme | 0:d895cd1cd897 | 121 | display->BusEnable(false) ; |
Rhyme | 0:d895cd1cd897 | 122 | reset_watch_dog() ; |
Rhyme | 0:d895cd1cd897 | 123 | break ; |
Rhyme | 0:d895cd1cd897 | 124 | case DISPLAY_MODE_CHART: |
Rhyme | 0:d895cd1cd897 | 125 | x = p->left + p->index + 1; |
Rhyme | 0:d895cd1cd897 | 126 | temp = temp_v2y(_ftemp[0], p) ; |
Rhyme | 0:d895cd1cd897 | 127 | before = temp_v2y(_ftemp[1], p) ; |
Rhyme | 0:d895cd1cd897 | 128 | after = temp_v2y(_ftemp[2], p) ; |
Rhyme | 0:d895cd1cd897 | 129 | display->BusEnable(true) ; |
Rhyme | 0:d895cd1cd897 | 130 | if (p->index == 0) { |
Rhyme | 0:d895cd1cd897 | 131 | draw_chart_frame(p) ; |
Rhyme | 0:d895cd1cd897 | 132 | } |
Rhyme | 0:d895cd1cd897 | 133 | display->pixel(x, temp, White) ; |
Rhyme | 0:d895cd1cd897 | 134 | display->pixel(x, before, Red) ; |
Rhyme | 0:d895cd1cd897 | 135 | display->pixel(x, after, Blue) ; |
Rhyme | 0:d895cd1cd897 | 136 | display->BusEnable(false) ; |
Rhyme | 0:d895cd1cd897 | 137 | p->index = (p->index + 1) % (p->width - 2) ; |
Rhyme | 0:d895cd1cd897 | 138 | break ; |
Rhyme | 0:d895cd1cd897 | 139 | } |
Rhyme | 0:d895cd1cd897 | 140 | } |
Rhyme | 0:d895cd1cd897 | 141 | reset_watch_dog() ; |
Rhyme | 0:d895cd1cd897 | 142 | } |
Rhyme | 0:d895cd1cd897 | 143 |