Ejemplo n.º 1
0
func (rs *ReaderSuite) TestReadGesture(c *C) {
	header := &EventHeader{}

	gopack.Unpack(rs.blankValue[:4], header)

	log.Printf("T %+v", header)

	c.Assert(header.Id, Equals, uint8(0x91))

	dataHeader := &DataHeader{}

	gopack.Unpack(rs.blankValue[4:8], dataHeader)
	log.Printf("T %+v", dataHeader)

	c.Assert(dataHeader.DataMask, Equals, uint16(0x1f))

	c.Assert(dataHeader.DataMask&1, Equals, uint16(1))
	c.Assert(dataHeader.DataMask&2, Equals, uint16(2))
	c.Assert(dataHeader.DataMask&4, Equals, uint16(4))
	c.Assert(dataHeader.DataMask&8, Equals, uint16(8))
	c.Assert(dataHeader.DataMask&16, Equals, uint16(16))

	log.Printf("len %d", len(rs.blankValue))

}
Ejemplo n.º 2
0
func (r *Reader) buildGestureEvent(buf []byte, n int) {

	g := NewGestureData()

	gopack.Unpack(buf[:4], g.Event)
	gopack.Unpack(buf[4:8], g.DataHeader)

	// var for offset
	offset := 8

	// is this a duplicate event
	if int(g.Event.Seq) == r.currentSeq {
		return
	}

	r.currentSeq = int(g.Event.Seq)

	// grab the DSPIfo
	if g.DataHeader.DataMask&DSPIfoFlag == DSPIfoFlag {
		offset += 2
	}

	// grab the GestureInfo
	if g.DataHeader.DataMask&GestureInfoFlag == GestureInfoFlag {

		gopack.Unpack(buf[offset:offset+4], g.Gesture)
		g.Gesture.GestureVal = g.Gesture.GestureVal & uint32(0xff)
		offset += 4
	}

	// grab the TouchInfo
	if g.DataHeader.DataMask&TouchInfoFlag == TouchInfoFlag {
		gopack.Unpack(buf[offset:offset+4], g.Touch)
		offset += 4
	}

	// grab the AirWheelInfo
	if g.DataHeader.DataMask&AirWheelInfoFlag == AirWheelInfoFlag {
		gopack.Unpack(buf[offset:offset+2], g.AirWheel)
		offset += 2
	}

	// grab the CoordinateInfo
	if g.DataHeader.DataMask&CoordinateInfoFlag == CoordinateInfoFlag {
		gopack.Unpack(buf[offset:offset+6], g.Coordinates)
		offset += 6
	}

	r.log.Debugf("Gesture: %s, Airwheel: %d, Touch: %s", g.Gesture.Name(), g.AirWheel.AirWheelVal, g.Touch.Name())

	// XXX: TODO: If we haven't read anything else... just ignore it for now as it's some other kind of message
	if offset > 8 {
		go r.onGesture(g)
	}
}
Ejemplo n.º 3
0
func (rs *ReaderSuite) TestReadGestureTwo(c *C) {
	header := &EventHeader{}

	gopack.Unpack(rs.gestureVal[:4], header)

	log.Printf("header %+v", header)

	c.Assert(header.Id, Equals, uint8(0x91))

	dataHeader := &DataHeader{}

	gopack.Unpack(rs.gestureVal[4:8], dataHeader)
	log.Printf("dataHeader %+v", dataHeader)

	c.Assert(dataHeader.DataMask, Equals, uint16(0x11f))

	c.Assert(dataHeader.DataMask&1, Equals, uint16(1))

	// var for offset
	offset := 8

	// grab the DSPIfo
	if dataHeader.DataMask&DSPIfoFlag == DSPIfoFlag {
		offset += 2
	}

	// grab the GestureInfo
	if dataHeader.DataMask&GestureInfoFlag == GestureInfoFlag {

		gestureInfo := &GestureInfo{}

		gopack.Unpack(rs.gestureVal[offset:offset+4], gestureInfo)

		log.Printf("gesture %d", gestureInfo.GestureVal&0xff)

		offset += 4

	}

	// SKIP 4 bytes

	// grab the TouchInfo
	if dataHeader.DataMask&TouchInfoFlag == TouchInfoFlag {

		touchInfo := &TouchInfo{}

		gopack.Unpack(rs.gestureVal[offset:offset+4], touchInfo)

		log.Printf("touchInfo %v", touchInfo)

		offset += 4
	}

	// grab the AirWheelInfo
	if dataHeader.DataMask&AirWheelInfoFlag == AirWheelInfoFlag {

		airWheelInfo := &AirWheelInfo{}

		gopack.Unpack(rs.gestureVal[offset:offset+2], airWheelInfo)

		log.Printf("airWheelInfo %v", airWheelInfo)

		offset += 2
	}

	// grab the CoordinateInfo
	if dataHeader.DataMask&CoordinateInfoFlag == CoordinateInfoFlag {

		coordinateInfo := &CoordinateInfo{}

		gopack.Unpack(rs.gestureVal[offset:offset+6], coordinateInfo)

		log.Printf("coordinateInfo %v", coordinateInfo)

		offset += 6
	}

	c.Assert(dataHeader.DataMask&2, Equals, uint16(2))
	c.Assert(dataHeader.DataMask&4, Equals, uint16(4))
	c.Assert(dataHeader.DataMask&8, Equals, uint16(8))
	c.Assert(dataHeader.DataMask&16, Equals, uint16(16))
}