Subversion Repositories public

Rev

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

Rev 168 Rev 169
Line 98... Line 98...
98
	restHr = cfg->readNumEntry("restHr", 60);
98
	restHr = cfg->readNumEntry("restHr", 60);
99
	vo2max = cfg->readNumEntry("vo2max", 50);
99
	vo2max = cfg->readNumEntry("vo2max", 50);
100
	weight = cfg->readNumEntry("weight", 70);
100
	weight = cfg->readNumEntry("weight", 70);
101
	sampleTime = cfg->readNumEntry("seconds", 15);
101
	sampleTime = cfg->readNumEntry("seconds", 15);
102
	Serial = cfg->readBoolEntry("Serial", false);
102
	Serial = cfg->readBoolEntry("Serial", false);
-
 
103
	Contour = cfg->readBoolEntry("Contour", false);
103
	Device = cfg->readEntry("Device", "/dev/ttyUSB0");
104
	Device = cfg->readEntry("Device", "/dev/ttyUSB0");
104
	Data = cfg->readEntry("Data", QDir::home().absPath() + "/.sportwatcher");
105
	Data = cfg->readEntry("Data", QDir::home().absPath() + "/.sportwatcher");
105
	HRM = cfg->readEntry("HRM", QDir::home().absPath() + "/polar");
106
	HRM = cfg->readEntry("HRM", QDir::home().absPath() + "/polar");
106
	MAP = cfg->readEntry("MAP", QDir::home().absPath() + "/.sportwatcher/track.wms");
107
	MAP = cfg->readEntry("MAP", QDir::home().absPath() + "/.sportwatcher/track.wms");
107
	Units = cfg->readNumEntry("Units", 0);
108
	Units = cfg->readNumEntry("Units", 0);
Line 2434... Line 2435...
2434
	// This is the point where we draw the curves itself.
2435
	// This is the point where we draw the curves itself.
2435
	// We use different colors to draw the lines.
2436
	// We use different colors to draw the lines.
2436
	x1 = x2 = y1 = y2 = 0;
2437
	x1 = x2 = y1 = y2 = 0;
2437
	int hy1, hy2, hx1, hx2;
2438
	int hy1, hy2, hx1, hx2;
2438
	hy1 = hy2 = hx1 = hx2 = 0;
2439
	hy1 = hy2 = hx1 = hx2 = 0;
2439
	int hEc = 20;
2440
	int hEc = 0;
-
 
2441
	i = 0;
-
 
2442
	AVGHEIGHT *avgHakt, *avgHfirst, *avgHlast, *avgHeight = 0;
-
 
2443
 
-
 
2444
	// To even the surface lines, we store every altitude in the
-
 
2445
	// memory, by building a chain. Then, if the user has set in the
-
 
2446
	// settings (Contour == true), we will even the line by calculating
-
 
2447
	// the average of 10 messure points and setting every value to the
-
 
2448
	// average, who is up or down more than 2 meters from the average.
-
 
2449
	while ((point = ds.getPoint(i)) != 0)
-
 
2450
	{
-
 
2451
	   if (point->alt > 20000.0 || point->alt < -1000.0)
-
 
2452
	   {
-
 
2453
	      i++;
-
 
2454
	      continue;
-
 
2455
	   }
-
 
2456
 
-
 
2457
	   if (!avgHeight)
-
 
2458
	   {
-
 
2459
	      avgHeight = new AVGHEIGHT;
-
 
2460
	      avgHeight->alt = point->alt;
-
 
2461
	      avgHeight->pos = hEc;
-
 
2462
	      avgHeight->prev = 0;
-
 
2463
	      avgHeight->next = 0;
-
 
2464
	      avgHakt = avgHeight;
-
 
2465
	      avgHfirst = avgHeight;
-
 
2466
	   }
-
 
2467
	   else
-
 
2468
	   {
-
 
2469
	      avgHakt = new AVGHEIGHT;
-
 
2470
	      avgHakt->alt = point->alt;
-
 
2471
	      avgHakt->pos = hEc;
-
 
2472
	      avgHakt->next = 0;
-
 
2473
	      avgHakt->prev = avgHeight;
-
 
2474
	      avgHeight->next = avgHakt;
-
 
2475
	      avgHeight = avgHakt;
-
 
2476
	   }
-
 
2477
 
-
 
2478
	   // FIXME: Currently we can not draw below 0 meters, because the
-
 
2479
	   // base line is always 0!
-
 
2480
	   if (avgHakt->alt < 0.0)
-
 
2481
	      avgHakt->alt = 0.0;
-
 
2482
 
-
 
2483
	   hEc++;
-
 
2484
	   i++;
-
 
2485
	}
-
 
2486
 
2440
	double avgHeight[20];
2487
	avgHlast = avgHeight;
-
 
2488
	// If wanted, even the lines
2441
	int hEven = -1;
2489
	if (Contour)
-
 
2490
	{
-
 
2491
	double alt[10], avg, step;
-
 
2492
	int a;
2442
 
2493
 
2443
	for (i = 0; i < hEc; i++)
2494
	   for (i = 0; i < (hEc + 10); i += 10)
-
 
2495
	   {
2444
	   avgHeight[i] = 0.0;
2496
	      avg = 0.0;
-
 
2497
 
-
 
2498
	      for (a = 0; a < 10; a++)
-
 
2499
	      {
-
 
2500
		 alt[a] = getAvgAlt(avgHfirst, i + a);
-
 
2501
		 avg += alt[a];
-
 
2502
	      }
-
 
2503
 
-
 
2504
	      if ((i + 10) >= hEc)
-
 
2505
		 avg /= (double)(hEc - i) + 1.0;
-
 
2506
	      else
-
 
2507
		 avg /= 10.0;
2445
 
2508
 
-
 
2509
	      for (a = 0; a < 10; a++)
-
 
2510
	      {
-
 
2511
		 if ((avgHakt = getAvgPtr(avgHfirst, i + a)) != 0)
-
 
2512
		 {
-
 
2513
		    if ((avgHakt->alt - avg) > 2 || (avgHakt->alt - avg) < -2)
-
 
2514
		       avgHakt->alt = avg;
-
 
2515
		 }
-
 
2516
	      }
-
 
2517
	   }
-
 
2518
	}
-
 
2519
 
-
 
2520
	// plot the altitude
2446
	i = 0;
2521
	i = 0;
-
 
2522
	int j = 0;
2447
 
2523
 
2448
	while ((point = ds.getPoint(i)) != 0)
2524
	while ((point = ds.getPoint(i)) != 0)
2449
	{
2525
	{
2450
	   // calculate the y position based on the time
2526
	   // calculate the y position based on the time
2451
	   qt = garmin_dtime(point->time);
2527
	   qt = garmin_dtime(point->time);
Line 2460... Line 2536...
2460
	   if (hx1 == 0)
2536
	   if (hx1 == 0)
2461
	      hx1 = hx2;
2537
	      hx1 = hx2;
2462
 
2538
 
2463
	   if (point->alt < 20000.0 && point->alt > -1000.0)
2539
	   if (point->alt < 20000.0 && point->alt > -1000.0)
2464
	   {
2540
	   {
2465
	   double aH;
-
 
2466
 
-
 
2467
/* Polynominterpolation zum glätten der Höhenlinien (Kurvenglätten)
-
 
2468
   FIXME: following formulas are to be done!
-
 
2469
 
-
 
2470
   For i = 1 To n
-
 
2471
       For j = n To i + 1 Step -1
-
 
2472
           y(j) = (y(j) - y(j-1)) / (x(j) - x(j-i))
-
 
2473
       Next j
-
 
2474
   Next i
-
 
2475
 
-
 
2476
  y_Wert = 0
-
 
2477
   For i = n To 1 Step -1
-
 
2478
       y_Wert = y_Wert * (x_Wert - x(i)) + y(i)
2541
	   double alt = getAvgAlt(avgHfirst, j);
2479
   Next i
-
 
2480
*/
-
 
2481
 
-
 
2482
	      if (Contour)
-
 
2483
	      {
-
 
2484
		 if (hEven == -1)
-
 
2485
		 {
-
 
2486
		    aH = point->alt;
-
 
2487
		    hEven = 0;
-
 
2488
		 }
-
 
2489
 
2542
 
2490
		 if (hEven > (hEc - 1))
-
 
2491
		 {
-
 
2492
		    aH = 0.0;
-
 
2493
 
-
 
2494
		    for (hEven = 0; hEven < hEc; hEven++)
-
 
2495
		       aH += avgHeight[hEven];
-
 
2496
 
-
 
2497
		    aH /= (double)hEc;
-
 
2498
		    hEven = 0;
-
 
2499
		 }
-
 
2500
 
-
 
2501
		 if (point->alt < 0.0)
-
 
2502
		    avgHeight[hEven] = 0.0;
-
 
2503
		 else
-
 
2504
		    avgHeight[hEven] = point->alt;
-
 
2505
 
-
 
2506
		 hEven++;
-
 
2507
	      }
-
 
2508
	      else
2543
	      j++;
2509
	      {
-
 
2510
		 if (point->alt < 0.0)
-
 
2511
		    aH = 0.0;
-
 
2512
		 else
-
 
2513
		    aH = point->alt;
-
 
2514
	      }
-
 
2515
 
2544
 
2516
	      if (meter)
2545
	      if (meter)
2517
		 y2 = (double)rh - (aH - minHeight) * h_tick;
2546
		 y2 = (double)rh - (alt - minHeight) * h_tick;
2518
	      else
2547
	      else
2519
	      {
2548
	      {
2520
		 double hrscale = rh / (maxHeight - minHeight);
2549
		 double hrscale = rh / (maxHeight - minHeight);
2521
		 y2 = (double)rh - (aH - minHeight) * hrscale;
2550
		 y2 = (double)rh - (alt - minHeight) * hrscale;
2522
	      }
2551
	      }
2523
 
2552
 
2524
	      if (y1 == 0)
2553
	      if (y1 == 0)
2525
		 y1 = y2;
2554
		 y1 = y2;
2526
 
2555
 
Line 2553... Line 2582...
2553
	}
2582
	}
2554
 
2583
 
2555
	paint.end();
2584
	paint.end();
2556
	imgProfile->setPixmap(pmProfile);
2585
	imgProfile->setPixmap(pmProfile);
2557
 
2586
 
-
 
2587
	// free the chain of altitudes
-
 
2588
	avgHakt = avgHfirst;
-
 
2589
 
-
 
2590
	while (avgHakt)
-
 
2591
	{
-
 
2592
	   avgHeight = avgHakt->next;
-
 
2593
	   delete avgHakt;
-
 
2594
	   avgHakt = avgHeight;
-
 
2595
	}
-
 
2596
 
2558
//	if (bProfile)
2597
//	if (bProfile)
2559
//	   bitBlt(imgProfile, 0, 0, &pmProfile);
2598
//	   bitBlt(imgProfile, 0, 0, &pmProfile);
2560
}
2599
}
2561
 
2600
 
-
 
2601
double sportwatcherWidget::getAvgAlt(AVGHEIGHT *avgHeight, int pos)
-
 
2602
{
-
 
2603
AVGHEIGHT *akt;
-
 
2604
 
-
 
2605
	akt = avgHeight;
-
 
2606
 
-
 
2607
	while (akt)
-
 
2608
	{
-
 
2609
	   if (akt->pos == pos)
-
 
2610
	      return akt->alt;
-
 
2611
 
-
 
2612
	   akt = akt->next;
-
 
2613
	}
-
 
2614
 
-
 
2615
	return 0.0;
-
 
2616
}
-
 
2617
 
-
 
2618
AVGHEIGHT *sportwatcherWidget::getAvgPtr(AVGHEIGHT *avgHeight, int pos)
-
 
2619
{
-
 
2620
AVGHEIGHT *akt;
-
 
2621
 
-
 
2622
	akt = avgHeight;
-
 
2623
 
-
 
2624
	while (akt)
-
 
2625
	{
-
 
2626
	   if (akt->pos == pos)
-
 
2627
	      return akt;
-
 
2628
 
-
 
2629
	   akt = akt->next;
-
 
2630
	}
-
 
2631
 
-
 
2632
	return 0;
-
 
2633
}
-
 
2634
 
2562
void sportwatcherWidget::resizeEvent(QResizeEvent */* *e */)
2635
void sportwatcherWidget::resizeEvent(QResizeEvent */* *e */)
2563
{
2636
{
2564
	showTrack(zfactor);
2637
	showTrack(zfactor);
2565
	showCurves();
2638
	showCurves();
2566
}
2639
}