Skip to content

Commit f4c5075

Browse files
committed
Initial Commit, Rough Code Dump
0 parents  commit f4c5075

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+37221
-0
lines changed

LICENSE

+340
Large diffs are not rendered by default.

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# ttwatcher
2+
3+
Application to process .ttbin files and download files from TT Sport Watch.
4+
5+
I was having issues with my TT Sport watch and needed a way to process the .ttbin
6+
files that the watch was giving us but were corrupted. A quick search showed the
7+
two projects below had done a lot of the ground work but were written
8+
for Linux. So I set out to make a quick and dirty Windows version so I could
9+
experiment with improving the ttbin parsing / communications.
10+
11+
**DISCLAIMER: I STRONGLY SUGGEST USING THE OFFICIAL APP TO DOWNLOAD YOUR ttbin
12+
files.**
13+
14+
# Heritage
15+
16+
Original inspiration from:
17+
18+
* https://github.com/FluffyKaon/TomTom-ttbin-file-format
19+
* https://github.com/ryanbinns/ttwatch
20+
21+
# Attributions
22+
23+
* Running man Icon made by http://www.freepik.com" is licensed under Creative Commons BY 3.0 CC BY 3.0
24+
* QCustomPlot, an easy to use, modern plotting widget for Qt, Copyright (C) 2011, 2012, 2013, 2014 Emanuel Eichhammer

lib/windows/x64/hid.lib

11.1 KB
Binary file not shown.

lib/windows/x86/hid.lib

27.7 KB
Binary file not shown.

src/Lightmaps.cpp

+281
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,281 @@
1+
#include "Lightmaps.h"
2+
3+
LightMaps::LightMaps(QWidget *parent) : QWidget(parent), pressed(false), snapped(false), dragging(false)
4+
{
5+
m_Map = new SlippyMap(this);
6+
connect(m_Map, SIGNAL(updated(QRect)), SLOT(updateMap(QRect)));
7+
connect(m_Map, SIGNAL(updated(QRect)), this, SIGNAL(updated()));
8+
}
9+
10+
void LightMaps::setCenter(qreal lat, qreal lng)
11+
{
12+
if ( m_Map->latitude == lat && m_Map->longitude == lng ) return;
13+
14+
m_Map->latitude = lat;
15+
m_Map->longitude = lng;
16+
m_Map->locationSet = true;
17+
m_Map->cancelDownloads();
18+
m_Map->invalidate();
19+
20+
emit latitudeChanged(lat);
21+
emit longitudeChanged(lng);
22+
}
23+
24+
void LightMaps::setCenter(int zoom, qreal lat, qreal lng)
25+
{
26+
if ( m_Map->latitude == lat && m_Map->longitude == lng && m_Map->zoom == zoom ) return;
27+
28+
if ( zoom < 0 ) zoom = 0;
29+
if ( zoom > 18 ) zoom = 18;
30+
31+
32+
m_Map->latitude = lat;
33+
m_Map->longitude = lng;
34+
m_Map->zoom = zoom;
35+
m_Map->locationSet = true;
36+
m_Map->cancelDownloads();
37+
m_Map->invalidate();
38+
39+
emit latitudeChanged(lat);
40+
emit longitudeChanged(lng);
41+
emit zoomChanged(zoom);
42+
}
43+
44+
void LightMaps::setLatitude( qreal lat)
45+
{
46+
if ( m_Map->latitude == lat ) return;
47+
48+
m_Map->latitude = lat;
49+
m_Map->locationSet = true;
50+
m_Map->cancelDownloads();
51+
m_Map->invalidate();
52+
53+
emit latitudeChanged(lat);
54+
}
55+
56+
void LightMaps::setLongitude( qreal lng )
57+
{
58+
if ( m_Map->longitude == lng ) return;
59+
60+
m_Map->longitude = lng;
61+
m_Map->locationSet = true;
62+
m_Map->cancelDownloads();
63+
m_Map->invalidate();
64+
emit longitudeChanged(lng);
65+
}
66+
67+
qreal LightMaps::latitude() const
68+
{
69+
return m_Map->latitude;
70+
}
71+
72+
qreal LightMaps::longitude() const
73+
{
74+
return m_Map->longitude;
75+
}
76+
77+
void LightMaps::updateMap(const QRect &r)
78+
{
79+
update(r);
80+
}
81+
void LightMaps::resizeEvent(QResizeEvent *)
82+
{
83+
m_Map->width = width();
84+
m_Map->height = height();
85+
m_Map->invalidate();
86+
}
87+
88+
void LightMaps::paintEvent(QPaintEvent *event)
89+
{
90+
QPainter p;
91+
p.begin(this);
92+
m_Map->render(&p, event->rect());
93+
94+
QPen pen;
95+
pen.setColor(Qt::red);
96+
pen.setWidth(3);
97+
p.setPen(pen);
98+
99+
// Draw graphics over the top.
100+
foreach ( const QRectF& line, m_Lines )
101+
{
102+
double latitude1 = line.top();
103+
double longitude1 = line.left();
104+
double latitude2 = line.bottom();
105+
double longitude2 = line.right();
106+
107+
QPoint p1,p2;
108+
109+
bool p1Visible = geoToScreen(latitude1, longitude1, p1);
110+
bool p2Visible = geoToScreen(latitude2, longitude2, p2);
111+
112+
if ( !p1Visible && !p2Visible )
113+
{
114+
// just skip it.
115+
continue;
116+
}
117+
118+
p.drawLine(p1,p2);
119+
120+
}
121+
122+
QPen pen_blue;
123+
pen_blue.setColor(Qt::blue);
124+
pen_blue.setWidth(3);
125+
p.setPen(pen_blue);
126+
127+
foreach ( const QPointF& pf, m_Circles )
128+
{
129+
QPoint p1;
130+
bool centerVisible = geoToScreen( pf.y(), pf.x(), p1);
131+
132+
if ( !centerVisible )
133+
{
134+
continue;
135+
}
136+
137+
138+
139+
p.drawEllipse(p1, 6,6);
140+
141+
}
142+
143+
144+
p.setPen(Qt::black);
145+
146+
p.drawText(rect(), Qt::AlignBottom | Qt::TextWordWrap,
147+
"Map data CCbySA 2009 OpenStreetMap.org contributors");
148+
p.end();
149+
150+
}
151+
152+
void LightMaps::timerEvent(QTimerEvent *)
153+
{
154+
update();
155+
}
156+
157+
void LightMaps::mousePressEvent(QMouseEvent *event)
158+
{
159+
if (event->buttons() != Qt::LeftButton)
160+
return;
161+
pressed = snapped = true;
162+
pressPos = dragPos = event->pos();
163+
}
164+
165+
void LightMaps::mouseMoveEvent(QMouseEvent *event)
166+
{
167+
if (!event->buttons())
168+
return;
169+
170+
if (!pressed || !snapped)
171+
{
172+
QPoint delta = event->pos() - pressPos;
173+
pressPos = event->pos();
174+
m_Map->pan(delta);
175+
emit dragBegin();
176+
dragging = true;
177+
return;
178+
}
179+
else
180+
{
181+
const int threshold = 10;
182+
QPoint delta = event->pos() - pressPos;
183+
if (snapped)
184+
{
185+
snapped &= delta.x() < threshold;
186+
snapped &= delta.y() < threshold;
187+
snapped &= delta.x() > -threshold;
188+
snapped &= delta.y() > -threshold;
189+
}
190+
}
191+
192+
}
193+
194+
void LightMaps::mouseReleaseEvent(QMouseEvent *)
195+
{
196+
if ( dragging ) {
197+
emit dragEnd();
198+
dragging = false;
199+
}
200+
201+
update();
202+
}
203+
204+
void LightMaps::keyPressEvent(QKeyEvent *event)
205+
{
206+
207+
if (event->key() == Qt::Key_Left)
208+
m_Map->pan(QPoint(20, 0));
209+
if (event->key() == Qt::Key_Right)
210+
m_Map->pan(QPoint(-20, 0));
211+
if (event->key() == Qt::Key_Up)
212+
m_Map->pan(QPoint(0, 20));
213+
if (event->key() == Qt::Key_Down)
214+
m_Map->pan(QPoint(0, -20));
215+
216+
}
217+
218+
void LightMaps::wheelEvent(QWheelEvent *event)
219+
{
220+
if ( event->delta() < 0 )
221+
{
222+
setZoom( zoom() - 1 );
223+
}
224+
else
225+
{
226+
setZoom( zoom() + 1 );
227+
}
228+
229+
}
230+
231+
void LightMaps::setZoom(int zoom)
232+
{
233+
if ( zoom < 0 ) return;
234+
if ( zoom > 18 ) return;
235+
236+
237+
if ( m_Map->zoom == zoom ) return;
238+
m_Map->zoom = zoom;
239+
m_Map->cancelDownloads();
240+
m_Map->invalidate();
241+
emit zoomChanged(zoom);
242+
}
243+
244+
int LightMaps::zoom() const
245+
{
246+
return m_Map->zoom;
247+
}
248+
249+
bool LightMaps::geoToScreen(qreal latitude, qreal longitude, QPoint &p) const
250+
{
251+
return m_Map->geoToScreen(latitude, longitude, p);
252+
}
253+
254+
QRectF LightMaps::geoBounds()
255+
{
256+
return m_Map->geoBounds();
257+
}
258+
259+
void LightMaps::clearLines()
260+
{
261+
m_Lines.clear();
262+
}
263+
264+
void LightMaps::addLine(qreal latitude1, qreal longitude1, qreal latitude2, qreal longitude2)
265+
{
266+
QRectF line( QPointF(longitude1, latitude1),QPointF(longitude2, latitude2) );
267+
m_Lines.append(line);
268+
}
269+
270+
void LightMaps::clearCircles()
271+
{
272+
m_Circles.clear();
273+
}
274+
275+
void LightMaps::addCircle(qreal latitude, qreal longitude)
276+
{
277+
m_Circles.append( QPointF( longitude, latitude ));
278+
}
279+
280+
281+

src/Lightmaps.h

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#ifndef LIGHTMAPS_H
2+
#define LIGHTMAPS_H
3+
4+
5+
#include <QtCore>
6+
#include <QtGui>
7+
#include <QtNetwork>
8+
#include <QDebug>
9+
#include <QWidget>
10+
#include <QList>
11+
12+
#include "SlippyMap.h"
13+
14+
class LightMaps: public QWidget
15+
{
16+
Q_OBJECT
17+
18+
QList<QRectF> m_Lines;
19+
QList<QPointF> m_Circles;
20+
21+
public:
22+
LightMaps(QWidget *parent = 0);
23+
24+
void setCenter(qreal lat, qreal lng);
25+
void setCenter(int zoom, qreal lat, qreal lng);
26+
27+
void setLatitude( qreal lat);
28+
void setLongitude( qreal lng );
29+
qreal latitude() const;
30+
qreal longitude() const;
31+
void setZoom ( int zoom );
32+
int zoom( ) const;
33+
bool geoToScreen( qreal latitude, qreal longitude, QPoint & p ) const;
34+
QRectF geoBounds();
35+
36+
void clearLines();
37+
void addLine( qreal latitude1, qreal longitude1, qreal latitude2, qreal longitude2);
38+
39+
void clearCircles();
40+
void addCircle( qreal latitude, qreal longitude );
41+
42+
private slots:
43+
void updateMap(const QRect &r);
44+
45+
46+
protected:
47+
48+
void resizeEvent(QResizeEvent *);
49+
void paintEvent(QPaintEvent *event);
50+
void timerEvent(QTimerEvent *);
51+
void mousePressEvent(QMouseEvent *event) ;
52+
void mouseMoveEvent(QMouseEvent *event);
53+
void mouseReleaseEvent(QMouseEvent *);
54+
void keyPressEvent(QKeyEvent *event);
55+
void wheelEvent(QWheelEvent * event);
56+
57+
signals:
58+
void latitudeChanged( double lat );
59+
void longitudeChanged( double lng );
60+
void zoomChanged ( int zoom );
61+
void updated();
62+
void dragEnd();
63+
void dragBegin();
64+
65+
private:
66+
SlippyMap *m_Map;
67+
bool pressed;
68+
bool snapped;
69+
bool dragging;
70+
QPoint pressPos;
71+
QPoint dragPos;
72+
};
73+
74+
#endif // LIGHTMAPS_H

0 commit comments

Comments
 (0)