int main(int argc, char **argv) { unsigned short *image565 = screen_init(); struct image *image = image_new(WIDTH, HEIGHT); struct image *font = image_new(BLOCK_X, BLOCK_Y*50); struct Glyph glyph[50]; int i; recognize_init(); event_init(); image_load(font, "data.raw"); memset(glyph, 0, sizeof(glyph)); printf("Press any key to start..."); getc(stdin); printf("Recognizing 1~25 ...\n"); screen_capture(image565); rgb565_to_rgb24(image->buf, image565); threshold(THRESHOLD, image->buf); recognize(image, font, glyph, 0); for (i = 0; i < 25; ++i) { send_touch(glyph[i].x, glyph[i].y); usleep(100); } printf("\n\nPress any key to continue..."); getc(stdin); printf("Recognizing 26~50 ...\n"); screen_capture(image565); rgb565_to_rgb24(image->buf, image565); threshold(THRESHOLD, image->buf); recognize(image, font, glyph, 1); for (i = 24; i < 50; ++i) { send_touch(glyph[i].x, glyph[i].y); usleep(100); } image_destroy(font); event_destroy(); image_destroy(image); screen_destroy(image565); return 0; }
bool TouchExtensionGlobal::postTouchEvent(QTouchEvent *event, QWaylandView *view) { const QList<QTouchEvent::TouchPoint> points = event->touchPoints(); const int pointCount = points.count(); if (!pointCount) return false; wl_client *surfaceClient = view->surface()->client()->client(); uint32_t time = m_compositor->currentTimeMsecs(); const int rescount = m_resources.count(); for (int res = 0; res < rescount; ++res) { Resource *target = m_resources.at(res); if (target->client() != surfaceClient) continue; // We will use no touch_frame type of event, to reduce the number of // events flowing through the wire. Instead, the number of points sent is // included in the touch point events. int sentPointCount = 0; for (int i = 0; i < pointCount; ++i) { if (points.at(i).state() != Qt::TouchPointStationary) ++sentPointCount; } for (int i = 0; i < pointCount; ++i) { const QTouchEvent::TouchPoint &tp(points.at(i)); // Stationary points are never sent. They are cached on client side. if (tp.state() == Qt::TouchPointStationary) continue; uint32_t id = tp.id(); uint32_t state = (tp.state() & 0xFFFF) | (sentPointCount << 16); uint32_t flags = (tp.flags() & 0xFFFF) | (int(event->device()->capabilities()) << 16); int x = toFixed(tp.pos().x()); int y = toFixed(tp.pos().y()); int nx = toFixed(tp.normalizedPos().x()); int ny = toFixed(tp.normalizedPos().y()); int w = toFixed(tp.rect().width()); int h = toFixed(tp.rect().height()); int vx = toFixed(tp.velocity().x()); int vy = toFixed(tp.velocity().y()); uint32_t pressure = uint32_t(tp.pressure() * 255); QByteArray rawData; QVector<QPointF> rawPosList = tp.rawScreenPositions(); int rawPosCount = rawPosList.count(); if (rawPosCount) { rawPosCount = qMin(maxRawPos, rawPosCount); QVector<float>::iterator iter = m_posData.begin(); for (int rpi = 0; rpi < rawPosCount; ++rpi) { const QPointF &rawPos(rawPosList.at(rpi)); // This will stay in screen coordinates for performance // reasons, clients using this data will presumably know // what they are doing. *iter++ = static_cast<float>(rawPos.x()); *iter++ = static_cast<float>(rawPos.y()); } rawData = QByteArray::fromRawData(reinterpret_cast<const char*>(m_posData.constData()), sizeof(float) * rawPosCount * 2); } send_touch(target->handle, time, id, state, x, y, nx, ny, w, h, pressure, vx, vy, flags, rawData); } return true; } return false; }