local class = require('mc.class')
local stream = require('stream.stream')
local object_defs = require('object_defs')
local DEFAULT_SCAN_INTERVAL <const> = 200
local bus = class()
function bus:ctor(object)
self.name = object.name
self.stream = (stream[object.class_name] or stream.None).new(object, object.name)
local obj_def = object_defs[object.class_name] or {}
self.need_scan = obj_def.need_scan or false
self.scan_interval = obj_def.scan_interval or DEFAULT_SCAN_INTERVAL
end
function bus:set_high_task_cb(high_task_cb)
self.high_task_cb = high_task_cb
end
function bus:notify_high_task(chip)
local high_task_cb = self.high_task_cb
if high_task_cb then
high_task_cb(chip)
end
end
function bus:set_secondary_task_cb(secondary_task_cb)
self.secondary_task_cb = secondary_task_cb
end
function bus:notify_secondary_task(chip)
local secondary_task_cb = self.secondary_task_cb
if secondary_task_cb then
secondary_task_cb(chip)
end
end
function bus:write(input)
self.stream:write(input)
end
function bus:read(input)
return self.stream:read(input)
end
return bus