Subversion Repositories dashGPS

Rev

Rev 23 | Rev 25 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 23 Rev 24
Line 26... Line 26...
26
 
26
 
27
double speedAvgTime = 0;    // sum of all deltaTime;
27
double speedAvgTime = 0;    // sum of all deltaTime;
28
double speedAvgSum = 0.0;  // sum of deltaTime * speed for each second
28
double speedAvgSum = 0.0;  // sum of deltaTime * speed for each second
29
double lastLocTime = 0.0; // last time there was a location
29
double lastLocTime = 0.0; // last time there was a location
30
 
30
 
-
 
31
uint32_t nextPosTime = 0;
-
 
32
 
31
// convert knots to MPH
33
// convert knots to MPH
32
double const KNOTS_TO_MPH = 1.128;
34
double const KNOTS_TO_MPH = 1.128;
33
int heading = 0;
35
int heading = 0;
34
Location loc;
36
Location loc;
35
 
37
 
Line 76... Line 78...
76
cc_run (struct bmp280_dev *bmp)
78
cc_run (struct bmp280_dev *bmp)
77
 
79
 
78
{
80
{
79
  display1.clearDisplay ();
81
  display1.clearDisplay ();
80
  dial.draw_scale (0, 360, 8, 1, 45);
82
  dial.draw_scale (0, 360, 8, 1, 45);
81
 
-
 
82
  bool stat = updateLocation (&loc, &uc1);
-
 
83
  if (stat && loc.good)
83
  while (1)
84
    {
84
    {
85
 
-
 
86
      heading = loc.heading;
85
      bool stat = updateLocation (&loc, &uc1);
87
      // add in time * speed to give "distance"
86
      if (!stat)
-
 
87
        break;
88
      if (loc.valid == 'A')
88
      if (stat && loc.good)
89
        {
89
        {
-
 
90
 
-
 
91
          heading = loc.heading;
-
 
92
          // add in time * speed to give "distance"
90
          if (lastLocTime != 0)
93
          if (loc.valid == 'A')
91
            {
94
            {
-
 
95
              if (lastLocTime != 0)
-
 
96
                {
92
              double delta = difftime (loc.utc, lastLocTime);
97
                  double delta = difftime (loc.utc, lastLocTime);
-
 
98
                  // believe the speed .
-
 
99
                  if (delta > 0 && delta < 2)
-
 
100
                    {
93
              // if the difference is > 1 second do the calculations.
101
                      speedAvgSum += loc.speed * delta;
-
 
102
                      speedAvgTime += delta;
-
 
103
                      lastLocTime = loc.utc;
-
 
104
                    }
-
 
105
                  else
-
 
106
                     lastLocTime = loc.utc;
-
 
107
                }
94
              if (delta > 0)
108
              else
95
                {
109
                {
96
                  speedAvgSum += loc.speed * delta;
-
 
97
                  speedAvgTime += delta;
-
 
98
                  speedAvg = (speedAvgSum / speedAvgTime) * KNOTS_TO_MPH;
-
 
99
                  lastLocTime = loc.utc;
110
                  lastLocTime = loc.utc;
100
                }
111
                }
101
            }
112
            }
-
 
113
        }
102
          else
114
      else
103
            {
115
        {
104
            lastLocTime = loc.utc;
116
        memset (loc.time, '-', 6);
105
            }
-
 
106
        }
117
        }
107
    }
118
    }
108
  if (loc.valid == 'V')
-
 
109
    memset (loc.time, '-', 6);
-
 
110
 
-
 
111
  // process button press
119
  // process button press
112
  uint8_t const buttonLimit = 3;
120
  uint8_t const buttonLimit = 3;
113
  uint8_t newPush = HAL_GPIO_ReadPin ( encoder_push_GPIO_Port,
121
  uint8_t newPush = HAL_GPIO_ReadPin ( encoder_push_GPIO_Port,
114
  encoder_push_Pin);
122
  encoder_push_Pin);
115
  if (newPush == buttonState)
123
  if (newPush == buttonState)
Line 128... Line 136...
128
          speedAvgSum = 0.0;
136
          speedAvgSum = 0.0;
129
          speedAvgTime = 0.0;
137
          speedAvgTime = 0.0;
130
        }
138
        }
131
    }
139
    }
132
 
140
 
133
  // print out the GMT time at the top of the screen
141
  // update the display once per second
134
  display1.gotoxy (0, 0);
142
  if (HAL_GetTick() > nextPosTime )
135
  display1.printString (small_font, &loc.time[0], 2, WHITE);
-
 
-
 
143
    {
136
  display1.printString (small_font, ":", 1, WHITE);
144
      nextPosTime += 1000;
137
  display1.printString (small_font, &loc.time[2], 2, WHITE);
-
 
138
 
145
 
139
  display1.printString (small_font, ":", 1, WHITE);
146
      // slow down the output of ata
-
 
147
      if (speedAvgTime > 0)
140
  display1.printString (small_font, &loc.time[4], 2, WHITE);
148
        speedAvg = (speedAvgSum / speedAvgTime) * KNOTS_TO_MPH;
141
 
149
 
-
 
150
      // print out the GMT time at the top of the screen
142
  int dial_ang = heading + 180;
151
      display1.gotoxy (0, 0);
-
 
152
      display1.printString (small_font, &loc.time[0], 2, WHITE);
143
  dial.draw_needle (dial_ang);
153
      display1.printString (small_font, ":", 1, WHITE);
-
 
154
      display1.printString (small_font, &loc.time[2], 2, WHITE);
144
 
155
 
145
  display1.gotoxy (70, 25);
-
 
146
  if (loc.valid == 'A')
-
 
147
    {
-
 
148
      display1.fontDigits (large_font, 3, -1, heading);
156
      display1.printString (small_font, ":", 1, WHITE);
149
    }
-
 
150
  else
-
 
151
    display1.printString (large_font, "GPS?", 4, WHITE);
157
      display1.printString (small_font, &loc.time[4], 2, WHITE);
152
 
158
 
153
  if (loc.valid == 'A')
159
      int dial_ang = heading + 180;
154
    speedMPH = loc.speed * KNOTS_TO_MPH;
160
      dial.draw_needle (dial_ang);
155
  else
-
 
156
    speedMPH = 0.0;
-
 
157
 
-
 
158
  display1.gotoxy (0, 8);
-
 
159
  display1.printString (small_font, "Speed", 5, WHITE);
-
 
160
  display1.gotoxy (0, 16);
-
 
161
  display1.fontDigits (large_font, 4, 1, speedMPH * 10);
-
 
162
 
-
 
163
  display1.gotoxy (0, 32);
-
 
164
  display1.printString (small_font, "Average", 7, WHITE);
-
 
165
  display1.gotoxy (0, 40);
-
 
166
  display1.fontDigits (large_font, 4, 1, speedAvg * 10);
-
 
167
 
161
 
168
  struct bmp280_uncomp_data ucomp_data;
162
      display1.gotoxy (70, 25);
-
 
163
      if (loc.valid == 'A')
-
 
164
        {
-
 
165
          display1.fontDigits (large_font, 3, -1, heading);
-
 
166
        }
-
 
167
      else
-
 
168
        display1.printString (large_font, "GPS?", 4, WHITE);
169
 
169
 
170
  if (HAL_GetTick () - lastTick > 100)
170
      if (loc.valid == 'A')
-
 
171
        speedMPH = loc.speed * KNOTS_TO_MPH;
171
    {
172
      else
-
 
173
        speedMPH = 0.0;
-
 
174
 
172
      lastTick = HAL_GetTick ();
175
      display1.gotoxy (0, 8);
-
 
176
      display1.printString (small_font, "Speed", 5, WHITE);
-
 
177
      display1.gotoxy (0, 16);
-
 
178
      display1.fontDigits (large_font, 4, 1, speedMPH * 10);
-
 
179
 
-
 
180
      display1.gotoxy (0, 32);
-
 
181
      display1.printString (small_font, "Average", 7, WHITE);
-
 
182
      display1.gotoxy (0, 40);
173
      /* Reading the raw data from sensor */
183
      display1.fontDigits (large_font, 4, 1, speedAvg * 10);
-
 
184
 
174
      rslt = bmp280_get_uncomp_data (&ucomp_data, bmp);
185
      struct bmp280_uncomp_data ucomp_data;
175
 
186
 
176
      if (rslt == BMP280_OK)
187
      if (HAL_GetTick () - lastTick > 100)
177
        {
188
        {
-
 
189
          lastTick = HAL_GetTick ();
178
          /* Getting the 32 bit compensated temperature */
190
          /* Reading the raw data from sensor */
179
          rslt = bmp280_get_comp_temp_32bit (&temp32, ucomp_data.uncomp_temp,
191
          rslt = bmp280_get_uncomp_data (&ucomp_data, bmp);
180
                                             bmp);
-
 
181
 
192
 
-
 
193
          if (rslt == BMP280_OK)
-
 
194
            {
-
 
195
              /* Getting the 32 bit compensated temperature */
-
 
196
              rslt = bmp280_get_comp_temp_32bit (&temp32,
-
 
197
                                                 ucomp_data.uncomp_temp, bmp);
-
 
198
 
182
          rslt = bmp280_get_comp_pres_32bit (&pres32, ucomp_data.uncomp_press,
199
              rslt = bmp280_get_comp_pres_32bit (&pres32,
183
                                             bmp);
200
                                                 ucomp_data.uncomp_press, bmp);
184
 
201
 
185
#if defined USB_DEVICE
202
#if defined USB_DEVICE
186
/*
203
/*
187
          *  $--XDR,a,x.x,a,c--c, ..... *hh<CR><LF> \\
204
          *  $--XDR,a,x.x,a,c--c, ..... *hh<CR><LF> \\
188
 
205
 
Line 217... Line 234...
217
           cnt+= small_sprintf(buffer+cnt,"*%02X\n",sum);
234
           cnt+= small_sprintf(buffer+cnt,"*%02X\n",sum);
218
 
235
 
219
           CDC_Transmit_FS(reinterpret_cast<uint8_t*>(&buffer[0]),cnt);
236
           CDC_Transmit_FS(reinterpret_cast<uint8_t*>(&buffer[0]),cnt);
220
#endif
237
#endif
221
 
238
 
-
 
239
            }
222
        }
240
        }
223
    }
-
 
224
  display1.gotoxy (0, 56);
241
      display1.gotoxy (0, 56);
225
  display1.printString (small_font, "T", 2, WHITE);
242
      display1.printString (small_font, "T", 2, WHITE);
226
  display1.fontDigits (small_font, 4, 1, temp32 / 10, WHITE);
243
      display1.fontDigits (small_font, 4, 1, temp32 / 10, WHITE);
227
  display1.printString (small_font, " P", 2, WHITE);
244
      display1.printString (small_font, " P", 2, WHITE);
228
  display1.fontDigits (small_font, 5, 0, pres32 / 100, WHITE);
245
      display1.fontDigits (small_font, 5, 0, pres32 / 100, WHITE);
229
  display1.printString (small_font, " ", 1, WHITE);
246
      display1.printString (small_font, " ", 1, WHITE);
230
 
-
 
231
  display1.display ();
-
 
232
 
247
 
-
 
248
      display1.display ();
-
 
249
    }
233
}
250
}