def text_node(self, root):
        node = Node("text", root)
        node.set_attribute("@callback", "rgb_text")
        node.set_display_name("Text")
        node.set_type("string")

        node.set_config("$writable", "write")
        node.set_value_callback = self.set_text
        return node
 def set_analog_node(root, name="Set Analog"):
     slug = name.replace(" ", "_").lower()
     node = Node(slug, root)
     node.set_display_name(name)
     node.set_config("$is", "set_analog")
     node.set_parameters([
         {
             "name": "Value",
             "type": "number"
         }
     ])
     node.set_invokable("write")
     return node
    def get_default_nodes(self):
        self.do_restore = False
        super_root = self.get_root_node()

        add_module = Node("add_module", super_root)
        add_module.set_display_name("Add Module")
        add_module.set_profile("add_module")
        add_module.set_parameters([
            {
                "name": "Name",
                "type": "string"
            },
            {
                "name": "Type",
                "type": self.module_enum()
            },
            {
                "name": "Address",
                "type": self.address_enum()
            }
        ])
        add_module.set_columns([
            {
                "name": "Success",
                "type": "string"
            }
        ])
        add_module.set_invokable("config")

        poll_speed = Node("poll_speed", super_root)
        poll_speed.set_display_name("Poll Speed")
        poll_speed.set_type("number")
        poll_speed.set_value(0.1)
        poll_speed.set_config("$writable", "config")

        super_root.add_child(add_module)
        super_root.add_child(poll_speed)

        return super_root
 def humid_node(self, root):
     node = Node("humid", root)
     node.set_display_name("Humidity")
     node.set_type("number")
     node.set_attribute("@unit", "%")
     return node
 def temp_node(self, root):
     node = Node("temp", root)
     node.set_display_name("Temperature")
     node.set_type("number")
     node.set_attribute("@unit", "C")
     return node
 def color_node(self, root):
     node = Node("color", root)
     node.set_attribute("@callback", "rgb_color")
     node.set_display_name("Color")
     node.set_type("dynamic")
     node.set_config("$editor", "color")
     node.set_config("$writable", "write")
     node.set_value_callback = self.set_color
     return node
 def remove_module_node(root):
     node = Node("remove_module", root)
     node.set_display_name("Remove Module")
     node.set_config("$is", "remove_module")
     node.set_invokable("config")
     return node
    def add_module(self, parameters):
        if "Name" not in parameters.params:
            return [["Invalid name."]]
        node = Node(str(parameters.params["Name"]), self.super_root)
        node.set_attribute("@callback", "module")
        module_type = parameters.params["Type"]
        address = parameters.params["Address"]
        address_type = self.addresses[address][0]
        node.set_attribute("@module", module_type)
        node.set_attribute("@address", address)
        node.set_attribute("@type", address_type)
        node.set_value_callback = self.set_value
        node.set_config("$writable", "write")
        if module_type == "LED":
            if address_type == "pwm":
                grovepi.pinMode(self.addresses[address][1], "OUTPUT")
                node.set_type("number")
                node.set_attribute("@mode", "output")
                node.set_attribute("@unit", "%")
            elif address_type == "digital":
                grovepi.pinMode(self.addresses[address][1], "OUTPUT")
                node.set_type("bool")
                node.set_attribute("@mode", "output")
            else:
                return [["Requires pwm or digital"]]
        elif module_type == "RGB LCD":
            node.add_child(self.color_node(node))
            node.add_child(self.text_node(node))
        elif module_type == "Light Sensor":
            if address_type == "analog":
                node.set_type("number")
                node.set_attribute("@unit", "%")
                node.set_attribute("@mode", "input")
            else:
                return [["Requires analog"]]
        elif module_type == "Rotary Angle Sensor":
            if address_type == "analog":
                grovepi.pinMode(self.addresses[address][1], "INPUT")
                node.set_type("number")
                node.set_attribute("@unit", "%")
                node.set_attribute("@mode", "input")
            else:
                return [["Requires analog"]]
        elif module_type == "Ultrasonic Ranger":
            if address_type == "digital" or address_type == "pwm":
                grovepi.pinMode(self.addresses[address][1], "INPUT")
                node.set_type("number")
                node.set_attribute("@unit", "cm")
                node.set_attribute("@mode", "input")
            else:
                return [["Requires digital or pwm"]]
        elif module_type == "Buzzer":
            if address_type == "digital" or address_type == "pwm":
                grovepi.pinMode(self.addresses[address][1], "OUTPUT")
                node.set_type("number")
                node.set_attribute("@mode", "output")
            else:
                return [["Requires digital or pwm"]]
        elif module_type == "Sound Sensor":
            if address_type == "analog":
                grovepi.pinMode(self.addresses[address][1], "INPUT")
                node.set_type("number")
                node.set_attribute("@unit", "%")
                node.set_attribute("@mode", "input")
            else:
                return [["Requires analog"]]
        elif module_type == "Button":
            if address_type == "digital" or address_type == "pwm":
                grovepi.pinMode(self.addresses[address][1], "INPUT")
                node.set_type("bool")
                node.set_attribute("@mode", "input")
            else:
                return [["Requires digital or pwm"]]
        elif module_type == "Relay":
            if address_type == "digital" or address_type == "pwm":
                grovepi.pinMode(self.addresses[address][1], "OUTPUT")
                node.set_type("bool")
                node.set_attribute("@mode", "output")
            else:
                return [["Requires digital or pwm"]]
        elif module_type == "Temp and Humid":
            if address_type == "digital" or address_type == "pwm":
                grovepi.pinMode(self.addresses[address][1], "INPUT")
                node.add_child(self.temp_node(node))
                node.add_child(self.humid_node(node))
                node.set_attribute("@mode", "input")
            else:
                return [["Requires digital or pwm"]]

        node.add_child(self.remove_module_node(node))

        self.super_root.add_child(node)

        return [
            [
                "Success!"
            ]
        ]
Exemple #9
0
 def create_rng(self, data):
     name = data[1]["Name"]
     if self.responder.get_super_root().get("/%s" % name) is None:
         rng = Node(name, self.responder.get_super_root())
         rng.set_config("$is", "rng")
         rng.set_type("number")
         rng.set_value(0)
         self.responder.get_super_root().add_child(rng)
         delete = Node("delete", rng)
         delete.set_config("$is", "delete_rng")
         delete.set_invokable("config")
         rng.add_child(delete)
         self.rngs[name] = rng
         return [
             [
                 True
             ]
         ]
     return [
         [
             False
         ]
     ]
Exemple #10
0
    def get_default_nodes(self, super_root):
        create_rng = Node("create_rng", super_root)
        create_rng.set_display_name("Create RNG")
        create_rng.set_config("$is", "create_rng")
        create_rng.set_invokable("config")
        create_rng.set_parameters([
            {
                "name": "Name",
                "type": "string"
            }
        ])
        create_rng.set_columns([
            {
                "name": "Success",
                "type": "bool"
            }
        ])

        set_speed = Node("set_speed", super_root)
        set_speed.set_display_name("Set Speed")
        set_speed.set_config("$is", "set_speed")
        set_speed.set_invokable("config")
        set_speed.set_parameters([
            {
                "name": "Speed",
                "type": "number"
            }
        ])
        set_speed.set_columns([
            {
                "name": "Success",
                "type": "bool"
            }
        ])

        super_root.add_child(create_rng)
        super_root.add_child(set_speed)

        return super_root
Exemple #11
0
 def create_rng(self, data):
     name = data[1]["Name"]
     if self.responder.get_super_root().get("/%s" % name) is None:
         rng = Node(name, self.responder.get_super_root())
         rng.set_config("$is", "rng")
         rng.set_type("number")
         rng.set_value(0)
         self.responder.get_super_root().add_child(rng)
         delete = Node("delete", rng)
         delete.set_config("$is", "delete_rng")
         delete.set_invokable("config")
         rng.add_child(delete)
         self.rngs[name] = rng
         return [[True]]
     return [[False]]
Exemple #12
0
    def get_default_nodes(self, super_root):
        create_rng = Node("create_rng", super_root)
        create_rng.set_display_name("Create RNG")
        create_rng.set_config("$is", "create_rng")
        create_rng.set_invokable("config")
        create_rng.set_parameters([{"name": "Name", "type": "string"}])
        create_rng.set_columns([{"name": "Success", "type": "bool"}])

        set_speed = Node("set_speed", super_root)
        set_speed.set_display_name("Set Speed")
        set_speed.set_config("$is", "set_speed")
        set_speed.set_invokable("config")
        set_speed.set_parameters([{"name": "Speed", "type": "number"}])
        set_speed.set_columns([{"name": "Success", "type": "bool"}])

        super_root.add_child(create_rng)
        super_root.add_child(set_speed)

        return super_root