def del_dir(self, path: str, secure: bool = True) -> None:
        """
        Delete a directory on EV3's file system

        Attributes:
        path: absolute or relative path (from "/home/root/lms2012/sys/")
        secure: flag, if the directory may be not empty
        """
        if secure:
            self.del_file(path)
        else:
            if path.endswith("/"):
                path = path[:-1]
            parent_path = path.rsplit("/", 1)[0] + "/"
            folder = path.rsplit("/", 1)[1]
            ops = b''.join([
                ev3.opFile, ev3.GET_FOLDERS,
                ev3.LCS(parent_path),
                ev3.GVX(0)
            ])
            reply = self.send_direct_cmd(ops, global_mem=1)
            num = struct.unpack('B', reply[5:])[0]
            found = False
            for i in range(num):
                ops = b''.join([
                    ev3.opFile,
                    ev3.GET_SUBFOLDER_NAME,
                    ev3.LCS(parent_path),
                    ev3.LCX(i + 1),  # ITEM
                    ev3.LCX(64),  # LENGTH
                    ev3.GVX(0)  # NAME
                ])
                reply = self.send_direct_cmd(ops, global_mem=64)
                subdir = struct.unpack('64s', reply[5:])[0]
                subdir = subdir.split(b'\x00')[0]
                subdir = subdir.decode("utf8")
                if subdir == folder:
                    found = True
                    ops = b''.join([
                        ev3.opFile,
                        ev3.DEL_SUBFOLDER,
                        ev3.LCS(parent_path),  # NAME
                        ev3.LCX(i + 1)  # ITEM
                    ])
                    self.send_direct_cmd(ops)
                    break
            if not found:
                raise ev3.DirCmdError("Folder " + path + " doesn't exist")
Beispiel #2
0
def playsound() -> None:
    global myEV3
    ops = b''.join([
        ev3.opSound,
        ev3.PLAY,
        ev3.LCX(100),  # VOLUME
        ev3.LCS('./ui/DownloadSucces')  # NAME
    ])
    myEV3.send_direct_cmd(ops)
def rename(name : str) -> None:
    global myEV3
#    myEV3.verbosity = 1
    ops = b''.join([
        ev3.opCom_Set,
        ev3.SET_BRICKNAME,
        ev3.LCS(name)
    ])
    myEV3.send_direct_cmd(ops)
    def copy_file(self, path_source: str, path_dest: str) -> None:
        """
        Copies a file in the EV3's file system from
        its old location to a new one
        (no error if the file doesn't exist)

        Attributes:
        path_source: absolute or relative path (from "/home/root/lms2012/sys/")
                     of the existing file
        path_dest: absolute or relative path of the new file
        """
        ops = b''.join([
            ev3.opFile,
            ev3.MOVE,
            ev3.LCS(path_source),  # SOURCE
            ev3.LCS(path_dest)  # DESTINATION
        ])
        self.send_direct_cmd(ops, global_mem=1)
Beispiel #5
0
#!/usr/bin/env python3

import ev3, time

my_ev3 = ev3.EV3(protocol=ev3.USB, host='00:16:53:49:CA:06')
my_ev3.verbosity = 1

ops = b''.join([
    ev3.opSound,
    ev3.PLAY,
    ev3.LCX(100),                  # VOLUME
    ev3.LCS('./ui/DownloadSucces') # NAME
])
my_ev3.send_direct_cmd(ops)

ops = b''.join([
    ev3.opSound,
    ev3.REPEAT,
    ev3.LCX(50),                  # VOLUME
    ev3.LCS('./ui/DownloadSucces') # NAME
])
my_ev3.send_direct_cmd(ops)
time.sleep(3)
ops = b''.join([
    ev3.opSound,
    ev3.BREAK
])
my_ev3.send_direct_cmd(ops)

ops = b''.join([
    ev3.opSound,
Beispiel #6
0
    def sound(self,
              path: str,
              duration: float = None,
              repeat: bool = False) -> task.Task:
        """
        returns a Task object, that plays a sound file

        Attributes:
        path: name of the sound file (without extension ".rsf")

        Keyword Attributes:
        duration: duration of the sound file (in sec.)
        repeat: flag, if repeatedly playing
        """
        if repeat:
            ops = b''.join([
                ev3.opSound,
                ev3.REPEAT,
                ev3.LCX(self._volume),  # VOLUME
                ev3.LCS(path)  # NAME
            ])
        else:
            ops = b''.join([
                ev3.opSound,
                ev3.PLAY,
                ev3.LCX(self._volume),  # VOLUME
                ev3.LCS(path)  # NAME
            ])
        # pylint: disable=redefined-variable-type
        if not repeat and not duration:
            return task.Task(self.send_direct_cmd, args=(ops, ))
        elif not repeat and duration:
            t_inner = task.Task(self.send_direct_cmd,
                                args=(ops, ),
                                duration=duration,
                                action_stop=self.stop)
            return task.Task(t_inner.start, join=True)
        elif repeat and not duration:
            t_inner = task.Task(self.send_direct_cmd,
                                args=(ops, ),
                                action_stop=self.stop,
                                action_cont=self.send_direct_cmd,
                                args_cont=(ops, ),
                                duration=999999999)
            return task.Task(t_inner.start, join=True)
        elif repeat and duration:

            class _Task(task.Task):
                # pylint: disable=protected-access
                def _final(self, **kwargs):
                    super()._final(**kwargs)
                    if self._root._time_action:
                        self._root._time_rest = self._root._time_action - time.time(
                        )
                        self._root._time_action -= self._root._time_rest

                # pylint: enable=protected-access
                def _cont2(self, **kwargs):
                    self._time_action += self._time_rest
                    super()._cont2(**kwargs)

            t_inner = task.concat(
                _Task(self.send_direct_cmd,
                      args=(ops, ),
                      duration=duration,
                      action_stop=self.stop,
                      action_cont=self.send_direct_cmd,
                      args_cont=(ops, )), _Task(self.stop))
            # pylint: enable=redefined-variable-type
            return task.Task(t_inner.start, join=True)
Beispiel #7
0
import ev3, time

my_ev3 = ev3.EV3(protocol=ev3.WIFI, host='00:16:53:5E:89:BD')
my_ev3.verbosity = 1

ops = b''.join([
    ev3.opUI_Draw,
    ev3.TOPLINE,
    ev3.LCX(0),  # ENABLE
    ev3.opUI_Draw,
    ev3.BMPFILE,
    ev3.LCX(1),  # COLOR
    ev3.LCX(0),  # X0
    ev3.LCX(0),  # Y0
    ev3.LCS("../apps/Motor Control/MotorCtlAD.rgf"),  # NAME
    ev3.opUI_Draw,
    ev3.UPDATE
])
my_ev3.send_direct_cmd(ops)
time.sleep(5)
ops = b''.join([
    ev3.opUI_Draw,
    ev3.TOPLINE,
    ev3.LCX(1),  # ENABLE
    ev3.opUI_Draw,
    ev3.FILLWINDOW,
    ev3.LCX(0),  # COLOR
    ev3.LCX(0),  # Y0
    ev3.LCX(0),  # Y1
    ev3.opUI_Draw,
Beispiel #8
0
#!/usr/bin/env python3

import ev3

my_ev3 = ev3.EV3(protocol=ev3.USB, host='00:16:53:49:CA:06')
my_ev3.verbosity = 1

ops = b''.join([
    ev3.opFile,
    ev3.LOAD_IMAGE,
    ev3.LCX(1),  # SLOT
    ev3.LCS('../apps/Motor Control/Motor Control.rbf'),  # NAME
    ev3.LVX(0),  # SIZE
    ev3.LVX(4),  # IP*
    ev3.opProgram_Start,
    ev3.LCX(1),  # SLOT
    ev3.LVX(0),  # SIZE
    ev3.LVX(4),  # IP*
    ev3.LCX(0)  # DEBUG
])
my_ev3.send_direct_cmd(ops, local_mem=8)
Beispiel #9
0
#!/usr/bin/env python3

import ev3

my_ev3 = ev3.EV3(protocol=ev3.USB, host='00:16:53:49:CA:06')
my_ev3.verbosity = 1
ops = b''.join([
    ev3.opCom_Set,
    ev3.SET_BRICKNAME,
    ev3.LCS("myEV3")
])
my_ev3.send_direct_cmd(ops)
Beispiel #10
0
#!/usr/bin/env python3

import ev3

my_ev3 = ev3.EV3(protocol=ev3.WIFI, host='00:16:53:5E:89:BD')
my_ev3.verbosity = 1

ops = b''.join([ev3.opCom_Set, ev3.SET_BRICKNAME, ev3.LCS("EV3_SD")])
my_ev3.send_direct_cmd(ops)