Release candidate version. The pointer in GAS Pressure display is changed to a triangle.

Dependencies:   UniGraphic mbed vt100

Please note, at 2-Mar-2018 the current version of mbed-lib has a defect in Ticker.
https://os.mbed.com/forum/bugs-suggestions/topic/29287/

So, mbed lib version 157 is intentionally being used.
Please do not update mbed library until the problem in the above URL is fixed.

In this version, format of GAS Pressure Display has been changed.
/media/uploads/Rhyme/low.jpg

/media/uploads/Rhyme/good.jpg

/media/uploads/Rhyme/high.jpg

moto

Committer:
Rhyme
Date:
Fri Mar 02 07:56:09 2018 +0000
Revision:
0:774324cbc5a6
Release candidate version. GAS Pressure pointer is now a triangle.; Some source file clean-up was done.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Rhyme 0:774324cbc5a6 1 #include "mbed.h"
Rhyme 0:774324cbc5a6 2 #include "afLib.h"
Rhyme 0:774324cbc5a6 3 #include "edge_reset_mgr.h"
Rhyme 0:774324cbc5a6 4 #include "edge_sensor.h"
Rhyme 0:774324cbc5a6 5 #include "edge_accel.h"
Rhyme 0:774324cbc5a6 6 #include "MMA8451Q.h"
Rhyme 0:774324cbc5a6 7
Rhyme 0:774324cbc5a6 8 edge_accel::edge_accel(MMA8451Q *accel) : edge_sensor()
Rhyme 0:774324cbc5a6 9 {
Rhyme 0:774324cbc5a6 10 _accel = accel ;
Rhyme 0:774324cbc5a6 11 _sample_count = 0 ;
Rhyme 0:774324cbc5a6 12 _accumulation = 0 ;
Rhyme 0:774324cbc5a6 13 _prev_x = 0 ;
Rhyme 0:774324cbc5a6 14 _prev_y = 0 ;
Rhyme 0:774324cbc5a6 15 _prev_z = 0 ;
Rhyme 0:774324cbc5a6 16
Rhyme 0:774324cbc5a6 17 _interval = 30 ;
Rhyme 0:774324cbc5a6 18 }
Rhyme 0:774324cbc5a6 19
Rhyme 0:774324cbc5a6 20 edge_accel::~edge_accel(void)
Rhyme 0:774324cbc5a6 21 {
Rhyme 0:774324cbc5a6 22 delete _accel ;
Rhyme 0:774324cbc5a6 23 }
Rhyme 0:774324cbc5a6 24
Rhyme 0:774324cbc5a6 25 void edge_accel::reset(void)
Rhyme 0:774324cbc5a6 26 {
Rhyme 0:774324cbc5a6 27 clear_value() ;
Rhyme 0:774324cbc5a6 28 edge_sensor::reset() ;
Rhyme 0:774324cbc5a6 29 }
Rhyme 0:774324cbc5a6 30
Rhyme 0:774324cbc5a6 31 #if 0
Rhyme 0:774324cbc5a6 32 void edge_accel::prepare(void)
Rhyme 0:774324cbc5a6 33 {
Rhyme 0:774324cbc5a6 34 // printf("accel prepare\n") ;
Rhyme 0:774324cbc5a6 35 }
Rhyme 0:774324cbc5a6 36 #endif
Rhyme 0:774324cbc5a6 37
Rhyme 0:774324cbc5a6 38 int edge_accel::sample(void)
Rhyme 0:774324cbc5a6 39 {
Rhyme 0:774324cbc5a6 40 int result ;
Rhyme 0:774324cbc5a6 41 float theValue = 0.0 ;
Rhyme 0:774324cbc5a6 42 if (_sample_count > 1) { /* if sample is 1 or less, no data */
Rhyme 0:774324cbc5a6 43 _num_sampled = _sample_count - 1 ;
Rhyme 0:774324cbc5a6 44 theValue = (float)_accumulation / (float)(_num_sampled) ;
Rhyme 0:774324cbc5a6 45 result = 0 ; /* success */
Rhyme 0:774324cbc5a6 46 } else {
Rhyme 0:774324cbc5a6 47 result = 1 ; /* fail! */
Rhyme 0:774324cbc5a6 48 }
Rhyme 0:774324cbc5a6 49 _value = theValue / 4096.0 ;
Rhyme 0:774324cbc5a6 50 _sampled_time = edge_time ;
Rhyme 0:774324cbc5a6 51 _sample_count = 0 ;
Rhyme 0:774324cbc5a6 52 _accumulation = 0 ;
Rhyme 0:774324cbc5a6 53 return( result ) ;
Rhyme 0:774324cbc5a6 54 }
Rhyme 0:774324cbc5a6 55
Rhyme 0:774324cbc5a6 56 int edge_accel::deliver(void)
Rhyme 0:774324cbc5a6 57 {
Rhyme 0:774324cbc5a6 58 int result ;
Rhyme 0:774324cbc5a6 59 char timestr[16] ;
Rhyme 0:774324cbc5a6 60
Rhyme 0:774324cbc5a6 61 print_time(_sampled_time) ;
Rhyme 0:774324cbc5a6 62 // _value = get_value() ;
Rhyme 0:774324cbc5a6 63 printf(" accel: %.3f [%d samples]\n", _value, _num_sampled) ;
Rhyme 0:774324cbc5a6 64 time2seq(_sampled_time, timestr) ;
Rhyme 0:774324cbc5a6 65 sprintf(_str_buf,
Rhyme 0:774324cbc5a6 66 "{\"DEVICE\":\"ACCEL\",\"PN\":\"MMA8451Q\",\"VAL_X\":\"%.3f\",\"VAL_Y\":\"0\",\"VAL_Z\":\"0\",\"UNIT\":\"g\",\"T\":\"%s\",\"E\":\"%d\"}",
Rhyme 0:774324cbc5a6 67 _value, timestr, _error_count) ;
Rhyme 0:774324cbc5a6 68 result = afero->setAttribute(1, _str_buf) ;
Rhyme 0:774324cbc5a6 69
Rhyme 0:774324cbc5a6 70 return( result == afSUCCESS ) ;
Rhyme 0:774324cbc5a6 71 }
Rhyme 0:774324cbc5a6 72
Rhyme 0:774324cbc5a6 73 int accel_v2y(float value, edge_chart_type *p)
Rhyme 0:774324cbc5a6 74 {
Rhyme 0:774324cbc5a6 75 int y ;
Rhyme 0:774324cbc5a6 76 if (value < p->min) {
Rhyme 0:774324cbc5a6 77 value = p->min ;
Rhyme 0:774324cbc5a6 78 } else if (value > p->max) {
Rhyme 0:774324cbc5a6 79 value = p->max ;
Rhyme 0:774324cbc5a6 80 }
Rhyme 0:774324cbc5a6 81 y = p->top + p->height/2 - 1
Rhyme 0:774324cbc5a6 82 - (int)((p->height - 2) * value /(p->max - p->min)) ;
Rhyme 0:774324cbc5a6 83 return( y ) ;
Rhyme 0:774324cbc5a6 84 }
Rhyme 0:774324cbc5a6 85
Rhyme 0:774324cbc5a6 86 void edge_accel::show(void)
Rhyme 0:774324cbc5a6 87 {
Rhyme 0:774324cbc5a6 88 int x, y ;
Rhyme 0:774324cbc5a6 89 edge_chart_type *p = &edge_chart[0] ; /* edge_chart for accel */
Rhyme 0:774324cbc5a6 90 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 91 if (display) {
Rhyme 0:774324cbc5a6 92 switch(display_mode) {
Rhyme 0:774324cbc5a6 93 case DISPLAY_MODE_SUMMARY:
Rhyme 0:774324cbc5a6 94 display->BusEnable(true) ;
Rhyme 0:774324cbc5a6 95 display->set_font((unsigned char*) Arial12x12);
Rhyme 0:774324cbc5a6 96 display->set_font_zoom(2, 2) ;
Rhyme 0:774324cbc5a6 97 display->foreground(White) ;
Rhyme 0:774324cbc5a6 98 display->locate(EDGE_SUMMARY_X, EDGE_SUMMARY_TIME_Y) ;
Rhyme 0:774324cbc5a6 99 displayTime(_sampled_time) ;
Rhyme 0:774324cbc5a6 100 // display->locate(10, 5) ;
Rhyme 0:774324cbc5a6 101 // display->printf(timestr) ;
Rhyme 0:774324cbc5a6 102 display->locate(EDGE_SUMMARY_X, EDGE_SUMMARY_ACCEL_Y) ;
Rhyme 0:774324cbc5a6 103 display->printf("Accel: %.3f [%4d]", _value, _num_sampled) ;
Rhyme 0:774324cbc5a6 104 display->BusEnable(false) ;
Rhyme 0:774324cbc5a6 105 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 106 break ;
Rhyme 0:774324cbc5a6 107 case DISPLAY_MODE_CHART:
Rhyme 0:774324cbc5a6 108 x = p->left + p->index + 1;
Rhyme 0:774324cbc5a6 109 y = accel_v2y(_value, p) ;
Rhyme 0:774324cbc5a6 110 display->BusEnable(true) ;
Rhyme 0:774324cbc5a6 111 if (p->index == 0) {
Rhyme 0:774324cbc5a6 112 draw_chart_frame(p) ;
Rhyme 0:774324cbc5a6 113 }
Rhyme 0:774324cbc5a6 114 display->pixel(x, y, White) ;
Rhyme 0:774324cbc5a6 115 display->BusEnable(false) ;
Rhyme 0:774324cbc5a6 116 p->index = (p->index + 1) % (p->width - 2) ;
Rhyme 0:774324cbc5a6 117 break ;
Rhyme 0:774324cbc5a6 118 default:
Rhyme 0:774324cbc5a6 119 break ;
Rhyme 0:774324cbc5a6 120 }
Rhyme 0:774324cbc5a6 121 }
Rhyme 0:774324cbc5a6 122 clear_value() ;
Rhyme 0:774324cbc5a6 123 reset_watch_dog() ;
Rhyme 0:774324cbc5a6 124 }
Rhyme 0:774324cbc5a6 125
Rhyme 0:774324cbc5a6 126 int edge_accel::accum(void)
Rhyme 0:774324cbc5a6 127 {
Rhyme 0:774324cbc5a6 128 int result ;
Rhyme 0:774324cbc5a6 129 int16_t value[3] ;
Rhyme 0:774324cbc5a6 130
Rhyme 0:774324cbc5a6 131 if (_enable) {
Rhyme 0:774324cbc5a6 132 result = _accel->getAllRawData(value) ;
Rhyme 0:774324cbc5a6 133
Rhyme 0:774324cbc5a6 134 if (result == 0) { /* success */
Rhyme 0:774324cbc5a6 135 if (_sample_count != 0) { /* first data does not have prev_data */
Rhyme 0:774324cbc5a6 136 _accumulation +=
Rhyme 0:774324cbc5a6 137 abs(_prev_x - value[0])
Rhyme 0:774324cbc5a6 138 + abs(_prev_y - value[1])
Rhyme 0:774324cbc5a6 139 + abs(_prev_z - value[2]) ;
Rhyme 0:774324cbc5a6 140 }
Rhyme 0:774324cbc5a6 141
Rhyme 0:774324cbc5a6 142 _sample_count++ ;
Rhyme 0:774324cbc5a6 143
Rhyme 0:774324cbc5a6 144 _prev_x = value[0] ;
Rhyme 0:774324cbc5a6 145 _prev_y = value[1] ;
Rhyme 0:774324cbc5a6 146 _prev_z = value[2] ;
Rhyme 0:774324cbc5a6 147 }
Rhyme 0:774324cbc5a6 148 }
Rhyme 0:774324cbc5a6 149
Rhyme 0:774324cbc5a6 150 return( result ) ;
Rhyme 0:774324cbc5a6 151 }
Rhyme 0:774324cbc5a6 152
Rhyme 0:774324cbc5a6 153 void edge_accel::clear_value(void)
Rhyme 0:774324cbc5a6 154 {
Rhyme 0:774324cbc5a6 155 _sample_count = 0 ;
Rhyme 0:774324cbc5a6 156 _accumulation = 0 ;
Rhyme 0:774324cbc5a6 157 _prev_x = 0 ;
Rhyme 0:774324cbc5a6 158 _prev_y = 0 ;
Rhyme 0:774324cbc5a6 159 _prev_z = 0 ;
Rhyme 0:774324cbc5a6 160 }
Rhyme 0:774324cbc5a6 161
Rhyme 0:774324cbc5a6 162
Rhyme 0:774324cbc5a6 163