19 from eric7 import Globals, Preferences |
20 from eric7 import Globals, Preferences |
20 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
21 from eric7.EricWidgets import EricFileDialog, EricMessageBox |
21 from eric7.EricWidgets.EricApplication import ericApp |
22 from eric7.EricWidgets.EricApplication import ericApp |
22 from eric7.SystemUtilities import FileSystemUtilities |
23 from eric7.SystemUtilities import FileSystemUtilities |
23 |
24 |
|
25 from ..MicroPythonWidget import HAS_QTCHART |
24 from . import FirmwareGithubUrls |
26 from . import FirmwareGithubUrls |
25 from .DeviceBase import BaseDevice |
27 from .DeviceBase import BaseDevice |
26 from ..MicroPythonWidget import HAS_QTCHART |
|
27 |
28 |
28 |
29 |
29 class MicrobitDevice(BaseDevice): |
30 class MicrobitDevice(BaseDevice): |
30 """ |
31 """ |
31 Class implementing the device for BBC micro:bit and Calliope mini boards. |
32 Class implementing the device for BBC micro:bit and Calliope mini boards. |
630 self.tr("DAPLink Firmware"), |
631 self.tr("DAPLink Firmware"), |
631 Preferences.getMicroPython("CalliopeDAPLinkUrl"), |
632 Preferences.getMicroPython("CalliopeDAPLinkUrl"), |
632 ), |
633 ), |
633 ] |
634 ] |
634 |
635 |
|
636 ################################################################## |
|
637 ## Methods below implement the file system commands |
|
638 ################################################################## |
|
639 |
|
640 def ls(self, dirname=""): |
|
641 """ |
|
642 Public method to get a directory listing of the connected device. |
|
643 |
|
644 @param dirname name of the directory to be listed |
|
645 @type str |
|
646 @return tuple containg the directory listing |
|
647 @rtype tuple of str |
|
648 @exception OSError raised to indicate an issue with the device |
|
649 """ |
|
650 # BBC micro:bit does not support directories |
|
651 commands = [ |
|
652 "import os as __os_", |
|
653 "print(__os_.listdir())", |
|
654 "del __os_", |
|
655 ] |
|
656 out, err = self._interface.execute(commands) |
|
657 if err: |
|
658 raise OSError(self._shortError(err)) |
|
659 return ast.literal_eval(out.decode("utf-8")) |
|
660 |
|
661 def lls(self, dirname="", fullstat=False, showHidden=False): |
|
662 """ |
|
663 Public method to get a long directory listing of the connected device |
|
664 including meta data. |
|
665 |
|
666 @param dirname name of the directory to be listed |
|
667 @type str |
|
668 @param fullstat flag indicating to return the full stat() tuple |
|
669 @type bool |
|
670 @param showHidden flag indicating to show hidden files as well |
|
671 @type bool |
|
672 @return list containing the directory listing with tuple entries of |
|
673 the name and and a tuple of mode, size and time (if fullstat is |
|
674 false) or the complete stat() tuple. 'None' is returned in case the |
|
675 directory doesn't exist. |
|
676 @rtype tuple of (str, tuple) |
|
677 @exception OSError raised to indicate an issue with the device |
|
678 """ |
|
679 # BBC micro:bit does not support directories |
|
680 commands = [ |
|
681 "import os as __os_", |
|
682 "\n".join( |
|
683 [ |
|
684 "def is_visible(filename, showHidden):", |
|
685 " return showHidden or " |
|
686 "(filename[0] != '.' and filename[-1] != '~')", |
|
687 ] |
|
688 ), |
|
689 "\n".join( |
|
690 [ |
|
691 "def stat(filename):", |
|
692 " size = __os_.size(filename)", |
|
693 " return (0, 0, 0, 0, 0, 0, size, 0, 0, 0)", |
|
694 ] |
|
695 ), |
|
696 "\n".join( |
|
697 [ |
|
698 "def listdir_stat(showHidden):", |
|
699 " files = __os_.listdir()", |
|
700 " return list((f, stat(f)) for f in files if" |
|
701 " is_visible(f,showHidden))", |
|
702 ] |
|
703 ), |
|
704 "print(listdir_stat({0}))".format(showHidden), |
|
705 "del __os_, stat, listdir_stat, is_visible", |
|
706 ] |
|
707 out, err = self._interface.execute(commands) |
|
708 if err: |
|
709 raise OSError(self._shortError(err)) |
|
710 fileslist = ast.literal_eval(out.decode("utf-8")) |
|
711 if fileslist is None: |
|
712 return None |
|
713 else: |
|
714 if fullstat: |
|
715 return fileslist |
|
716 else: |
|
717 return [(f, (s[0], s[6], s[8])) for f, s in fileslist] |
|
718 |
|
719 def pwd(self): |
|
720 """ |
|
721 Public method to get the current directory of the connected device. |
|
722 |
|
723 @return current directory |
|
724 @rtype str |
|
725 """ |
|
726 # BBC micro:bit does not support directories |
|
727 return "" |
|
728 |
|
729 ################################################################## |
|
730 ## time related methods below |
|
731 ################################################################## |
|
732 |
|
733 def _getSetTimeCode(self): |
|
734 """ |
|
735 Protected method to get the device code to set the time. |
|
736 |
|
737 Note: This method must be implemented in the various device specific |
|
738 subclasses. |
|
739 |
|
740 @return code to be executed on the connected device to set the time |
|
741 @rtype str |
|
742 """ |
|
743 # rtc_time[0] - year 4 digit |
|
744 # rtc_time[1] - month 1..12 |
|
745 # rtc_time[2] - day 1..31 |
|
746 # rtc_time[3] - weekday 1..7 1=Monday |
|
747 # rtc_time[4] - hour 0..23 |
|
748 # rtc_time[5] - minute 0..59 |
|
749 # rtc_time[6] - second 0..59 |
|
750 # rtc_time[7] - yearday 1..366 |
|
751 # rtc_time[8] - isdst 0, 1, or -1 |
|
752 return "" |
|
753 |
635 |
754 |
636 def createDevice(microPythonWidget, deviceType, vid, pid, boardName, serialNumber): |
755 def createDevice(microPythonWidget, deviceType, vid, pid, boardName, serialNumber): |
637 """ |
756 """ |
638 Function to instantiate a MicroPython device object. |
757 Function to instantiate a MicroPython device object. |
639 |
758 |