rts-sim-module/sys/iscs_sys/iscs_bas_fan.go
2023-12-27 18:11:27 +08:00

56 lines
1.4 KiB
Go

package iscs_sys
import (
"joylink.club/ecs"
"joylink.club/ecs/filter"
"joylink.club/rtsssimulation/component"
)
// FanSystem 风机
type FanSystem struct {
query *ecs.Query
}
// NewFanSystem 风机系统
func NewFanSystem() *FanSystem {
return &FanSystem{
query: ecs.NewQuery(filter.Contains(component.UidType, component.MotorType, component.FluidDriverType, component.DeviceExceptionType)),
}
}
func (s *FanSystem) Update(w ecs.World) {
s.query.Each(w, func(entry *ecs.Entry) {
//fanId := component.UidType.Get(entry).Id
fan := component.MotorType.Get(entry)
fluidDriver := component.FluidDriverType.Get(entry)
//fmt.Printf("====>>>fanId = %s , forward = %t , speed = %f , ms = %d\n", fanId, fan.Forward, fan.Speed, fan.Ms)
//一般风机(3000 r/min)
if entry.HasComponent(component.CommonFanTag) {
if fan.Speed > 3000 {
fan.Speed = 3000
}
}
//软启风机(100 r/min)
if entry.HasComponent(component.SoftStartFanTag) {
if fan.Speed > 100 {
fan.Speed = 100
}
}
//双速风机(Low 2000 r/min ; High 7000 r/min)
if entry.HasComponent(component.HighLowSpeedFanTag) {
highMode := component.FanHighLowSpeedModeType.Get(entry).HighMode
if highMode { //高速模式
if fan.Speed > 6000 {
fan.Speed = 6000
}
} else { //低速模式
if fan.Speed > 2000 {
fan.Speed = 2000
}
}
}
//
fluidDriver.On = fan.Speed > 0
fluidDriver.Forward = fan.Forward
})
}