The hardwareDetector() function can either be instructed to probe directly for the first available matching hardware or it can return a hardware object for more specific hardware lists or searches.
All hardware is referenced with 3 information strings, denoted here as "dev", "devType" and "devInfo". Their contents depend on the type of hardware that was found and also the method of detection.
dev := Will hold either the direct side label or
the remote peripheral name.
You can use this value directly to .wrap()
an object to this peripheral.
devType := Will hold the base device type, for example:
"modem", "computer", "turtle", "drive",
"monitor", "printer" or other peripheral
supplied by other mods.
devInfo := Will hold any available additional information
about this particular peripheral.
modem : "wireless" or "cable"
computer : string containing the ID number, i.e.: "6"
turtle : string containing the ID number, i.e.: "7"
drive : "empty" := no disk in drive
"floppy" := data floppy in drive
"music" := music disc in drive
"unknown" := unknown media in drive
monitor : "normal" or "advanced"
printer : "n/a" or "remote"
Parameters:
You can pass any number of parameters, each holding a peripheral type ("chat", "chatbox", "chatterbox") and you can also add any of the listed devInfo labels; for example:
"monitor:advanced" := would return an advanced monitor if found
"drive:music" := would return the drive that has the music disc
As mentioned, you can either probe directly or use the hardware object.
The test samples found in the test application for hardwareDetector(), will show you how to accomplish both. (
http://pastebin.com/DAYhYyz4 )
The hardware object contains the following methods:
.detect()
This method is called internally every time hardwareDetector() is
called, but you can also call it through the hardware object in
case you need to refresh the hardware list, say after connecting
or disconnecting something. You could also call this method if
your event handler detects a peripheral attach or detach.
.find(...)
When probing directly on hardwareDetector() this method is actually
doing all the work. .find() will search through the entire hardware
list and return the first available hardware that matches your
search parameter(s). This method accepts any number of parameters
and you can also do the devInfo combinations here.
@returns:
dev, devType, devInfo (all strings)
.getAll()
This function simply just returns the entire hardware list as a
table.
The table contains # "records" of the tuple dev, devType, devInfo.
You can thus use this table entry counter as a reference to the
number of devices connected to this computer.
@returns:
table of tuples {dev, devType, devInfo}
Reference sample:
local all = hw.getAll()
"all" would then have this structure:
all = {
[1] = {"right", "modem", "cable"}
[2] = {"left", "modem", "wireless"}
}
and can be referenced:
if (all[1][3] == "wireless") then
blah, blah
end
.getList(...)
This function is a combination of .find() and .getAll(), however
this fill filter out a result list, that only contains hardware
that matches the given parameters. See <parameters> for further
info.
.isRemote(dev)
Tests dev against direct attachments or remote.
@returns
true := if this dev is available remotely through cables.
nil := if this dev is attached on any sides of the computer
This documentation is also found inside the test application in a comment block, between the hardwareDetector() function and the actual test environment.
Sorry for the odd indenting here - I can't seem to get the forum to indent things the way I want it.