aboutsummaryrefslogtreecommitdiff
path: root/smartpen.h
blob: 12ed89845164e95537becdf18d085c92fbb19b0d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
 * scribiu -- read notebooks and voice memos from Livescribe pens
 * Copyright (C) 2015 Javier S. Pedro <javier@javispedro.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef SMARTPEN_H
#define SMARTPEN_H

#include <QtCore/QObject>
#include <QtCore/QDateTime>
#include <QtCore/QVariantMap>
#include <openobex/obex.h>

#define SMARTPEN_DPI_X (677.3333)
#define SMARTPEN_DPI_Y (677.3333)

// TODO: These values are mostly random.
#define SMARTPEN_BLEED_X 333.3
#define SMARTPEN_BLEED_Y 333.3

class Smartpen : public QObject
{
	Q_OBJECT

public:
	explicit Smartpen(QObject *parent = 0);
	~Smartpen();

	typedef QPair<unsigned int, unsigned int> Address;

	bool isConnected() const;

	enum Parameters {
		PenName = 8011
	};

	QByteArray getObject(const QString& name);
	QString getParameter(Parameters parameter);

	QString getPenName();
	QVariantMap getPenInfo();

	struct ChangeReport {
		QString guid;
		QString className;
		QString title;
	};

	QList<ChangeReport> getChangeList(const QDateTime &from = QDateTime());

	QByteArray getLspData(const QString &name, const QDateTime &from = QDateTime());
	QByteArray getPaperReplay(const QDateTime &from = QDateTime());

	static qint64 toPenTime(const QDateTime &dt);
	static QDateTime fromPenTime(qint64 t);

	static QString toPenSerial(quint64 id);
	static quint64 toPenId(const QString &serial);

public slots:
	bool connectToPen(const Address &addr);
	void disconnectFromPen();

signals:
	void error();

private:
	static void obexEventCb(obex_t *handle, obex_object_t *obj,
	                            int mode, int event, int obex_cmd, int obex_rsp);
	void handleObexEvent(obex_object_t *object,
	                     int event, int obex_cmd, int obex_rsp);
	void handleObexRequestDone(obex_object_t *object, int obex_cmd, int obex_rsp);

	static QString toPenSerialSegment(quint32 id, int len);
	static quint32 fromPenSerialSegment(const QString &s);

	static QByteArray encodeUtf16(const QString &s);
	void addConnHeader(obex_object_t *object) const;

private:
	obex_t * _obex;
	quint32 _connId;
	QByteArray _inBuf;
};

#endif // SMARTPEN_H