# Path: myDevices/devices/bus.py
# class Bus():
#     def __init__(self, busName, device, flag=os.O_RDWR):
#         enableBus(busName)
#         self.busName = busName
#         self.device = device
#         self.flag = flag
#         self.fd = 0
#         self.open()
#         
#     def open(self):
#         self.fd = os.open(self.device, self.flag)
#         if self.fd < 0:
#             raise Exception("Cannot open %s" % self.device)
# 
#     def close(self):
#         if self.fd > 0:
#             os.close(self.fd)
#     
#     def readDevice(self, size=1):
#         if self.fd > 0:
#             return os.read(self.fd, size)
#         raise Exception("Device %s not open" % self.device)
#     
#     def readBytes(self, size=1):
#         return bytearray(self.readDevice(size))
#     
#     def readByte(self):
#         return self.readBytes()[0]
# 
#     def writeDevice(self, string):
#         if self.fd > 0:
#             return os.write(self.fd, string)
#         raise Exception("Device %s not open" % self.device)
#     
#     def writeBytes(self, data):
#         return self.writeDevice(bytearray(data))
# 
#     def writeByte(self, value):
#         self.writeBytes([value])
# 
# def loadModule(module):
#     subprocess.call(["sudo", "modprobe", module])


import os
from myDevices.devices.bus import Bus, loadModule
from myDevices.utils.logger import *
#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.


EXTRAS = {
    "TEMP": {"loaded": False, "module": "w1-therm"},
    "2408": {"loaded": False, "module": "w1_ds2408"}
}

FAMILIES = {
    '10' : "DS18S20",
    '22' : "DS1822",
    '28' : "DS18B20",
    '29' : "DS2408",
    '3B' : "DS1825",
    '42' : "DS28EA00"
}

def loadExtraModule(name):
    if EXTRAS[name]["loaded"] == False:

# Path: myDevices/devices/bus.py
# class Bus():
#     def __init__(self, busName, device, flag=os.O_RDWR):
#         enableBus(busName)
#         self.busName = busName
#         self.device = device
#         self.flag = flag
#         self.fd = 0
#         self.open()
#         
#     def open(self):
#         self.fd = os.open(self.device, self.flag)
#         if self.fd < 0:
#             raise Exception("Cannot open %s" % self.device)
# 
#     def close(self):
#         if self.fd > 0:
#             os.close(self.fd)
#     
#     def readDevice(self, size=1):
#         if self.fd > 0:
#             return os.read(self.fd, size)
#         raise Exception("Device %s not open" % self.device)
#     
#     def readBytes(self, size=1):
#         return bytearray(self.readDevice(size))
#     
#     def readByte(self):
#         return self.readBytes()[0]
# 
#     def writeDevice(self, string):
#         if self.fd > 0:
#             return os.write(self.fd, string)
#         raise Exception("Device %s not open" % self.device)
#     
#     def writeBytes(self, data):
#         return self.writeDevice(bytearray(data))
# 
#     def writeByte(self, value):
#         self.writeBytes([value])
# 
# def loadModule(module):
#     subprocess.call(["sudo", "modprobe", module])


# Path: myDevices/devices/onewire.py
import os
from myDevices.devices.bus import Bus, loadModule
from myDevices.utils.logger import *

#
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#       http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.


EXTRAS = {
    "TEMP": {"loaded": False, "module": "w1-therm"},
    "2408": {"loaded": False, "module": "w1_ds2408"}
}

FAMILIES = {
    '10' : "DS18S20",
    '22' : "DS1822",
    '28' : "DS18B20",
    '29' : "DS2408",
    '3B' : "DS1825",
    '42' : "DS28EA00"
}

def loadExtraModule(name):
    if EXTRAS[name]["loaded"] == False:

        loadModule(EXTRAS[name]["module"])