func Elevator_set_button_lamp(button Button, floor int, value bool) { val := 0 if value { val = 1 } C.elev_set_button_lamp(C.elev_button_type_t(button), C.int(floor), C.int(val)) }
// ButtonLightOff turns it off func ButtonLightOff(floor Floor, dir Direction) { if floor == 0 && dir == DirectionDown { dir = DirectionUp } else if floor == NumFloors-1 && dir == DirectionUp { dir = DirectionDown } mutex.Lock() C.elev_set_button_lamp(C.elev_button_type_t(dir), C.int(floor), 0) mutex.Unlock() }
// FloorButtonListener should be spawned as a goroutine func FloorButtonListener(ch chan<- ButtonEvent) { var floorButtonState [3][NumFloors]bool for { for direction := DirectionUp; direction <= DirectionNone; direction++ { for floor := Floor(0); floor < NumFloors; floor++ { mutex.Lock() newState := C.elev_get_button_signal(C.elev_button_type_t(direction), C.int(floor)) != 0 mutex.Unlock() if newState != floorButtonState[direction][floor] { floorButtonState[direction][floor] = newState // Only dispatch an event if it's pressed if newState { log.Debug("Button type ", direction, " floor ", floor, " pressed") ch <- ButtonEvent{Dir: direction, Floor: floor} } else { log.Bullshit("Button type ", direction, " floor ", floor, " released") } } } } } }
func Elev_set_button_lamp(button Elev_button_type_t, floor int, value int) { C.elev_set_button_lamp(C.elev_button_type_t(button), C.int(floor), C.int(value)) }
func Elev_get_button_signal(button Elev_button_type_t, floor int) int { return int(C.elev_get_button_signal(C.elev_button_type_t(button), C.int(floor))) }
func ButtonPushed(button Button_type, floor int) int { return int(C.elev_get_button_signal(C.elev_button_type_t(button), C.int(floor))) }
func Elevator_is_button_pushed(button Button, floor int) bool { return (C.elev_get_button_signal(C.elev_button_type_t(button), C.int(floor)) != 0) }
func LiftDriver_GetButtonSignal(button types.ButtonType, floor int) bool { return int(C.elev_get_button_signal(C.elev_button_type_t(C.int(button)), C.int(floor))) != 0 }
func liftDriver_SetButtonLamp(button int, floor int, onOrOff bool) { C.elev_set_button_lamp(C.elev_button_type_t(button), C.int(floor), C.int(onOrOff)) }
func LiftDriver_SetButtonLamp(button types.ButtonType, floor int, onOrOff int) { C.elev_set_button_lamp(C.elev_button_type_t(C.int(button)), C.int(floor), C.int(onOrOff)) }
func ElevGetButtonSignal(buttonType int, floor int) int { return int(C.elev_get_button_signal(C.elev_button_type_t(C.int(buttonType)), C.int(floor))) }
func SetButtonLamp(button ButtonType, floor, value int) { C.elev_set_button_lamp(C.elev_button_type_t(button), C.int(floor), C.int(value)) }
func GetButtonSignal(button ButtonType, floor int) int { return int(C.elev_get_button_signal(C.elev_button_type_t(button), C.int(floor))) }
func Elev_get_button_signal(button int, floor int) bool { return int(C.elev_get_button_signal(C.elev_button_type_t(button), C.int(floor))) != 0 }