<commit_before>package main

import (
	def "definitions"
	hw "hardware"
	"fsm"
	"network"
	"time"
)


func EventHandler(){
	//Check for all events in loop
	//Make convinient variables
	//Fix lights
	
	//Convenient channels
	var BtnChan = make(chan def.BtnPress, 10)
	var IncomingMessageChan =make(chan def.Message, 10)
	var FloorChan = make(chan int)
	var DeadElevatorChan = make(chan int)

	//Convenient variables/structs


	//Threads
	go eventBtnPressed(BtnChan)
	go eventIncommingMessage(IncommingMessageChan)
	go eventCabAtFloor(FloorChan)

	for{
		select{
			case btnPress:= <- BtnChan:
				//Do something :P
			case msg := <- IncommingMessageChan:
				//Do something
			case currFloor := <- FloorChan:
				//Handle floor
			case deadElevator := <- DeadElevatorChan:
				//Handle dead elevator
		}
	}
}

func eventBtnPressed(ch chan def.BtnPress){
	//Check for a button beeing pressed
	lastBtnPressed := def.BtnPress{
		Button: -1,
		Floor: -1,
	} 
	btnPressed := def.BtnPress{
		Button: -2,
		Floor: -2,
	}
	for{
		for floor := 0; floor < def.NumFloors; floor++ {
			for btn := 0; btn < def.NumButtons; btn++ {
				if hw.ReadBtn(floor, btn){
					btnPressed{btn,floor}
					if lastBtnPressed != btnPressed{
						ch <- btnPressed
					}
					lastBtnPressed = btnPressed
				}
			}
		}
		time.Millisecond(1)
	}
}

func eventCabAtFloor(ch chan int){
	//initialize with invalid values
	var floorReached = -2
	var prevFloor = -3
	for{
		if hw.GetFloor != -1{
			if prevFloor != floorReached{
				floorReached = hw.GetFloor
				ch <-floorReached
			}
		}
		time.Millisecond(1)
	}
}

func eventIncommingMessage(ch chan def.Message){

}

func eventExternRequestTimeout(ch chan ...){

}

func eventDeadElevator(ch chan int){

}<commit_msg>Worked on eventhandler<commit_after>package main

import (
	def "definitions"
	hw "hardware"
	"fsm"
	"network"
	"time"
)


func EventHandler(){
	//Check for all events in loop
	//Make convinient variables
	//Fix lights
	
	//Convenient channels
	var BtnChan = make(chan def.BtnPress, 10)
	var IncomingMessageChan =make(chan def.Message, 10)
	var FloorChan = make(chan int)
	var DeadElevatorChan = make(chan int)
	var incomingUdpMsgChan =(make chan network.udpMessage)

	//Convenient variables/structs

	//Threads
	go eventBtnPressed(BtnChan)
	go eventIncommingMessage(IncommingMessageChan)
	go eventCabAtFloor(FloorChan)
	go network.forwardIncoming(IncomingMessageChan, incomingUdpMsgChan)

	for{
		select{
			case btnPress:= <- BtnChan:
				//Do something :P
				//Check if there is an order here already
				//
			case currFloor := <- FloorChan:
				//Handle floor
			case deadElevator := <- DeadElevatorChan:
				//Handle dead elevator
				//Check the whole queue for the dead lifts requests
				//Send them out as new requests
				//how to stop multiple elevators doing this?
			case incomingMsg := <- IncomingMessageChan:
				//Handle message
				//AlivePing
				if incomingMsg.Category == 1{

				}
				//NewRequest
				if incomingMsg.Category == 2{

				}
				//CompleteRequest
				if incomingMsg.Category == 3{

				}
				//Cost
				if incomingMsg.Category == 4 {
					
				}
		}
	}
}

func eventBtnPressed(ch chan def.BtnPress){
	//Check for a button beeing pressed
	lastBtnPressed := def.BtnPress{
		Button: -1,
		Floor: -1,
	} 
	btnPressed := def.BtnPress{
		Button: -2,
		Floor: -2,
	}
	for{
		for floor := 0; floor < def.NumFloors; floor++ {
			for btn := 0; btn < def.NumButtons; btn++ {
				if hw.ReadBtn(floor, btn){
					btnPressed{btn,floor}
					if lastBtnPressed != btnPressed{
						ch <- btnPressed
					}
					lastBtnPressed = btnPressed
				}
			}
		}
		time.Millisecond(1)
	}
}

func eventCabAtFloor(ch chan int){
	//initialize with invalid values
	var floorReached = -2
	var prevFloor = -3
	for{
		if hw.GetFloor != -1{
			if prevFloor != floorReached{
				floorReached = hw.GetFloor
				ch <-floorReached
			}
		}
		time.Millisecond(1)
	}
}
//This is handled by network.forwardIncoming() really
func eventIncommingMessage(ch chan def.Message){
	network.forwardIncoming()
}

func eventExternRequestTimeout(ch chan ...){

}

func eventDeadElevator(ch chan int){

}
{'fraction_non_alphanumeric': 0.11127272727272727, 'fraction_numerical': 0.008242424242424242, 'mean_word_length': 3.0811078140454997, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7421414', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1459, 'n_words': 383}