Commit 3f93924f authored by simon's avatar simon
Browse files

add hat radius

parent 0dab6fcf
Loading
Loading
Loading
Loading
+21 −1
Original line number Diff line number Diff line
@@ -37,6 +37,7 @@ type HID struct {
	hatPanYEvents         map[uint8]chan event
	hatPositionEvents     map[uint8]chan event
	hatAngleEvents        map[uint8]chan event
	hatRadiusEvents       map[uint8]chan event
	hatEdgeEvents         map[uint8]chan event
}

@@ -48,6 +49,10 @@ type when struct {
	time time.Duration
}

type region struct {
	maxX,maxY,minX,minY float32 
}

func (b when) Moment() time.Duration {
	return b.time
}
@@ -81,6 +86,12 @@ type HatAngleEvent struct {
	Angle float32
}

// Hat radius changed event, R {-1...1}
type HatRadiusEvent struct {
	when
	R float32
}

// ParcelOutEvents waits on the HID.OSEvent channel (so is blocking), then puts the required event(s), on any registered channel(s).
func (d HID) ParcelOutEvents() {
	for {
@@ -136,6 +147,14 @@ func (d HID) ParcelOutEvents() {
						c <- HatAngleEvent{when{toDuration(evt.Time)}, float32(math.Atan2(float64(d.HatAxes[evt.Index-1].value), float64(v)))}
					}
				}
				if c, ok := d.hatRadiusEvents[h.number]; ok {
					switch h.axis {
					case 1:
						c <- HatRadiusEvent{when{toDuration(evt.Time)}, float32(math.Sqrt(float64(v)*float64(v)+float64(d.HatAxes[evt.Index+1].value)*float64(d.HatAxes[evt.Index+1].value)))}
					case 2:
						c <- HatRadiusEvent{when{toDuration(evt.Time)}, float32(math.Sqrt(float64(d.HatAxes[evt.Index-1].value)*float64(d.HatAxes[evt.Index-1].value)+float64(v)*float64(v)))}
					}
				}
				if c, ok := d.hatEdgeEvents[h.number]; ok {
					fmt.Println(v,h)
					if (v==1 || v==-1) && h.value != 1 && h.value !=-1 {
@@ -157,7 +176,7 @@ func (d HID) ParcelOutEvents() {
	}
}

// Type of registerable methods and the index they are called witd. (Note: the event type is indicated by the method.)
// Type of registerable methods and the index they are called with. (Note: the event type is indicated by the method.)
type Channel struct {
	Number uint8
	Method func(HID, uint8) chan event
@@ -221,6 +240,7 @@ func (d HID) OnEdge(hat uint8) chan event {
}



// see if Button exists.
func (d HID) ButtonExists(button uint8) (ok bool) {
	for _, v := range d.Buttons {
+1 −1
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ func Connect(index int) (d *HID) {
	if e != nil {
		return nil
	}
	d = &HID{make(chan osEventRecord), make(map[uint8]button), make(map[uint8]hatAxis), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event)}
	d = &HID{make(chan osEventRecord), make(map[uint8]button), make(map[uint8]hatAxis), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event), make(map[uint8]chan event)}
	// start thread to read joystick events to the joystick.state osEvent channel
	go eventPipe(r, d.OSEvents)
	d.populate()
+0 −4
Original line number Diff line number Diff line
@@ -137,7 +137,3 @@ func play(s Sound) {
	}
}
/*  Hal3 Sun 2 Apr 23:41:29 BST 2017 go version go1.6.2 linux/amd64
Sun 2 Apr 23:41:29 BST 2017
*/