Subversion Repositories dashGPS

Rev

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

Rev 22 Rev 23
Line 20... Line 20...
20
  int const DISPLAY_RAMWIDTH = 132;
20
  int const DISPLAY_RAMWIDTH = 132;
21
 
21
 
22
}
22
}
23
 
23
 
24
float speedMPH = 0.0;
24
float speedMPH = 0.0;
25
float speedAVG = 0.0;
25
float speedAvg = 0.0;
26
int speedTimer  = 0;
-
 
27
float speedDist = 0.0;
-
 
28
 
26
 
-
 
27
double speedAvgTime = 0;    // sum of all deltaTime;
-
 
28
double speedAvgSum = 0.0;  // sum of deltaTime * speed for each second
-
 
29
double lastLocTime = 0.0; // last time there was a location
29
 
30
 
-
 
31
// convert knots to MPH
-
 
32
double const KNOTS_TO_MPH = 1.128;
30
int heading = 0;
33
int heading = 0;
31
Location loc;
34
Location loc;
32
 
35
 
33
uint32_t lastTick = 0;
36
uint32_t lastTick = 0;
34
int32_t temp32 = 0;
37
int32_t temp32 = 0;
Line 71... Line 74...
71
char fontBuf[] = "01234567";
74
char fontBuf[] = "01234567";
72
extern "C" void
75
extern "C" void
73
cc_run (struct bmp280_dev *bmp)
76
cc_run (struct bmp280_dev *bmp)
74
 
77
 
75
{
78
{
76
 
-
 
77
  display1.clearDisplay ();
79
  display1.clearDisplay ();
78
  dial.draw_scale (0, 360, 8, 1, 45);
80
  dial.draw_scale (0, 360, 8, 1, 45);
79
 
81
 
80
  bool stat = updateLocation (&loc, &uc1);
82
  bool stat = updateLocation (&loc, &uc1);
81
  if (stat && loc.good)
83
  if (stat && loc.good)
82
    {
84
    {
83
      heading = loc.heading;
-
 
84
 
85
 
-
 
86
      heading = loc.heading;
-
 
87
      // add in time * speed to give "distance"
85
      loc.good = false;
88
      if (loc.valid == 'A')
-
 
89
        {
-
 
90
          if (lastLocTime != 0)
-
 
91
            {
-
 
92
              double delta = difftime (loc.utc, lastLocTime);
-
 
93
              // if the difference is > 1 second do the calculations.
-
 
94
              if (delta > 0)
-
 
95
                {
-
 
96
                  speedAvgSum += loc.speed * delta;
-
 
97
                  speedAvgTime += delta;
-
 
98
                  speedAvg = (speedAvgSum / speedAvgTime) * KNOTS_TO_MPH;
-
 
99
                  lastLocTime = loc.utc;
-
 
100
                }
-
 
101
            }
-
 
102
          else
-
 
103
            {
-
 
104
            lastLocTime = loc.utc;
-
 
105
            }
-
 
106
        }
86
    }
107
    }
87
  if (loc.valid == 'V')
108
  if (loc.valid == 'V')
88
    memset (loc.time, '-', 6);
109
    memset (loc.time, '-', 6);
89
 
110
 
-
 
111
  // process button press
-
 
112
  uint8_t const buttonLimit = 3;
-
 
113
  uint8_t newPush = HAL_GPIO_ReadPin ( encoder_push_GPIO_Port,
-
 
114
  encoder_push_Pin);
-
 
115
  if (newPush == buttonState)
-
 
116
    buttonCount = 0;
-
 
117
  else if (buttonCount < buttonLimit)
-
 
118
    buttonCount++;
-
 
119
 
-
 
120
  if (buttonCount == buttonLimit)
-
 
121
    {
-
 
122
      buttonState = newPush;
-
 
123
      buttonCount = 0;
90
 
124
 
-
 
125
      // if the button is held down , we set the average speed
-
 
126
      if (buttonState == GPIO_PIN_RESET)
-
 
127
        {
-
 
128
          speedAvgSum = 0.0;
-
 
129
          speedAvgTime = 0.0;
-
 
130
        }
-
 
131
    }
91
 
132
 
92
  // print out the GMT time at the top of the screen
133
  // print out the GMT time at the top of the screen
93
  display1.gotoxy (0, 0);
134
  display1.gotoxy (0, 0);
94
  display1.printString (small_font, &loc.time[0], 2, WHITE);
135
  display1.printString (small_font, &loc.time[0], 2, WHITE);
95
  display1.printString (small_font, ":", 1, WHITE);
136
  display1.printString (small_font, ":", 1, WHITE);
96
  display1.printString (small_font, &loc.time[2], 2, WHITE);
137
  display1.printString (small_font, &loc.time[2], 2, WHITE);
97
 
138
 
98
  display1.printString (small_font, ":", 1, WHITE);
139
  display1.printString (small_font, ":", 1, WHITE);
99
  display1.printString (small_font, &loc.time[4], 2, WHITE);
140
  display1.printString (small_font, &loc.time[4], 2, WHITE);
-
 
141
 
100
  int dial_ang = heading + 180;
142
  int dial_ang = heading + 180;
101
  dial.draw_needle (dial_ang);
143
  dial.draw_needle (dial_ang);
102
 
144
 
103
  display1.gotoxy (70, 25);
145
  display1.gotoxy (70, 25);
104
  if (loc.valid == 'A')
146
  if (loc.valid == 'A')
Line 107... Line 149...
107
    }
149
    }
108
  else
150
  else
109
    display1.printString (large_font, "GPS?", 4, WHITE);
151
    display1.printString (large_font, "GPS?", 4, WHITE);
110
 
152
 
111
  if (loc.valid == 'A')
153
  if (loc.valid == 'A')
112
    speedMPH = loc.speed / 1.815;
154
    speedMPH = loc.speed * KNOTS_TO_MPH;
-
 
155
  else
-
 
156
    speedMPH = 0.0;
113
 
157
 
114
  display1.gotoxy (0, 8);
158
  display1.gotoxy (0, 8);
115
  display1.printString (small_font, "Speed", 5, WHITE);
159
  display1.printString (small_font, "Speed", 5, WHITE);
116
  display1.gotoxy (0, 16);
160
  display1.gotoxy (0, 16);
117
  display1.fontDigits (large_font, 4, 1, speedMPH * 10);
161
  display1.fontDigits (large_font, 4, 1, speedMPH * 10);
118
 
162
 
119
  display1.gotoxy (0, 32);
163
  display1.gotoxy (0, 32);
120
  display1.printString (small_font, "Average", 7, WHITE);
164
  display1.printString (small_font, "Average", 7, WHITE);
121
  display1.gotoxy (0, 40);
165
  display1.gotoxy (0, 40);
122
  display1.fontDigits (large_font, 4, 1, speedAVG * 10);
166
  display1.fontDigits (large_font, 4, 1, speedAvg * 10);
123
 
-
 
124
 
-
 
125
 
-
 
126
 
167
 
127
  struct bmp280_uncomp_data ucomp_data;
168
  struct bmp280_uncomp_data ucomp_data;
128
 
169
 
129
  if (HAL_GetTick () - lastTick > 100)
170
  if (HAL_GetTick () - lastTick > 100)
130
    {
171
    {
Line 180... Line 221...
180
 
221
 
181
        }
222
        }
182
    }
223
    }
183
  display1.gotoxy (0, 56);
224
  display1.gotoxy (0, 56);
184
  display1.printString (small_font, "T", 2, WHITE);
225
  display1.printString (small_font, "T", 2, WHITE);
185
  display1.fontDigits (small_font, 4, 1, temp32/10, WHITE);
226
  display1.fontDigits (small_font, 4, 1, temp32 / 10, WHITE);
186
  display1.printString (small_font, " P", 2, WHITE);
227
  display1.printString (small_font, " P", 2, WHITE);
187
  display1.fontDigits (small_font, 5, 0, pres32/100, WHITE);
228
  display1.fontDigits (small_font, 5, 0, pres32 / 100, WHITE);
188
  display1.printString (small_font, " ", 1, WHITE);
229
  display1.printString (small_font, " ", 1, WHITE);
189
 
230
 
190
 
-
 
191
  display1.display ();
231
  display1.display ();
192
 
232
 
193
}
233
}