Esempio n. 1
0
    def _card_state_change(self, pin):
        """
        Need to debounce this
        :param pin:
        :return:
        """
        if self._debounce:
            return

        self._debounce = True
        self._debounce_timer = Timer(-1)
        self._debounce_timer.init(period=DEBOUNCE_TIME,
                                  mode=Timer.ONE_SHOT,
                                  callback=self._remove_debounce)

        irq_state = disable_irq()

        if pin.value():  # No card present
            if self._card:  # Card may not be present on boot
                enable_irq(irq_state)
                uos.umount(self._directory)
                irq_state = disable_irq()
                self._deinit_card()
        else:
            try:
                card = self._init_card()
                enable_irq(irq_state)
                uos.mount(card, self._directory)
                irq_state = disable_irq()
            except OSError:  # Mount issue, probably EPERM
                pass

        enable_irq(irq_state)
Esempio n. 2
0
	def record(self, duration = 4):
		if self.sd is not None:
			self.sleep(False)
			WAV_DATA_SIZE = duration * Mic.SAMPLES_PER_SECOND * Mic.BYTES_PER_SAMPLE
			wav_header = self.gen_wav_header(Mic.SAMPLES_PER_SECOND, Mic.BITS_PER_SAMPLE, 1, Mic.SAMPLES_PER_SECOND * duration)
			uos.mount(self.sd, "/")
			f = open('/mic_recording_'+str(random.randint(1,1000))+'.wav','wb')
			f.write(wav_header)
			now = utime.ticks_ms()
			mic_samples = bytearray(Mic.SAMPLE_BLOCK_SIZE)
			sd_samples = bytearray(Mic.SDCARD_SECTOR_SIZE)
			numread = 0
			numwrite = 0
			for _ in range(WAV_DATA_SIZE // Mic.SDCARD_SECTOR_SIZE):
			    try:
			        numread += self.audio.readinto(mic_samples)    
			        self.prune(mic_samples, sd_samples)
			        numwrite += f.write(sd_samples)
			    except KeyboardInterrupt:  
			        break
			elapsedTime = utime.ticks_diff(utime.ticks_ms(),now)
			f.close()
			uos.umount("/")
			self.sleep(True)
			print("Listo, bytes leídos: {}, bytes escritos: {}, \nduración segun ticks: {}, duración segun calculos {}".format(numread,
																					numwrite,
																					elapsedTime,
																					numwrite/8000.0))
		else:
			print("Por favor, añade una sd")
Esempio n. 3
0
def test(bdev, vfs_class):
    print("test", vfs_class)

    # mkfs
    vfs_class.mkfs(bdev)

    # construction
    vfs = vfs_class(bdev)

    # mount
    uos.mount(vfs, "/lfs")

    # import
    with open("/lfs/lfsmod.py", "w") as f:
        f.write('print("hello from lfs")\n')
    import lfsmod

    # import package
    uos.mkdir("/lfs/lfspkg")
    with open("/lfs/lfspkg/__init__.py", "w") as f:
        f.write('print("package")\n')
    import lfspkg

    # chdir and import module from current directory (needs "" in sys.path)
    uos.mkdir("/lfs/subdir")
    uos.chdir("/lfs/subdir")
    uos.rename("/lfs/lfsmod.py", "/lfs/subdir/lfsmod2.py")
    import lfsmod2

    # umount
    uos.umount("/lfs")

    # clear imported modules
    sys.modules.clear()
Esempio n. 4
0
 def timer_exp_func(self, timer):
     self.station.active(False)
     if self.logger is not None:
         with open("/sdcard/SSID.log", "r") as fp:
             self.logger.write_line(fp.read())
     umount("/sdcard")
     start(0)
Esempio n. 5
0
def test(bdev, vfs_class):
    print('test', vfs_class)

    # mkfs
    vfs_class.mkfs(bdev)

    # construction
    vfs = vfs_class(bdev)

    # mount
    uos.mount(vfs, '/lfs')

    # import
    with open('/lfs/lfsmod.py', 'w') as f:
        f.write('print("hello from lfs")\n')
    import lfsmod

    # import package
    uos.mkdir('/lfs/lfspkg')
    with open('/lfs/lfspkg/__init__.py', 'w') as f:
        f.write('print("package")\n')
    import lfspkg

    # umount
    uos.umount('/lfs')

    # clear imported modules
    sys.modules.clear()
Esempio n. 6
0
def _reset(delay):
    import utime
    import machine
    print("restarting...")
    utime.sleep(delay)
    uos.umount('/remote')
    uos.sync()
    machine.reset()
Esempio n. 7
0
def umountsd(mountpoint="/sd"):
    """ Umount command """
    import uos
    try:
        uos.umount(mountpoint)
        print("Sd umounted from '%s'" % mountpoint)
    except:
        print("Cannot umount sd from '%s'" % mountpoint)
Esempio n. 8
0
def get_predict(filename,th,ts,tp):
    ts=ts+th
    tp=tp+ts
    #SD card setup
    #MOSI(IO23) MISO(19) SCK(18)
    spisd=SPI(-1,sck=Pin(18),mosi=Pin(23),miso=Pin(19))
    #CS(5)
    sd=sdcard.SDCard(spisd,Pin(5))
    uos.mount(sd,'/sd')

    #WiFi setup
    WIFI_SSID = 'OPPOA5s'
    WIFI_PASSWORD = '******'
    ap_if = network.WLAN(network.AP_IF)
    wifi = network.WLAN(network.STA_IF)

    ap_if.active(False)

    # connect the device to the WiFi network
    wifi.active(True)
    wifi.connect(WIFI_SSID, WIFI_PASSWORD)
    time.sleep(5)

    #Read data from csv file
    Data=[]
    label=[]
    no_Rows=0
    filename="/sd/{}".format(filename)
    with open(filename,'r') as file:
        for line in file:
            if no_Rows <= ts & no_Rows > 0:
                line=line.rstrip('\n')
                line=line.rstrip('\r')
                Data.append(line.split(','))
                no_Rows+=1
            elif no_Rows == 0:
                line=line.rstrip('\n')
                line=line.rstrip('\r')
                label.append(line.split(','))
                no_Rows+=1
            else:
                no_Rows+=1
    column = label[0]
    #Convert data into json format
    js = {"columns":column, "data":Data}
    jsd = json.dumps(js)
    dfj = json.loads(jsd)
    #url to cloud system
    url = 'https://test-torc.herokuapp.com/torc-extract/?th={}'.format(ts)
    result = urequests.post(url,data=jsd)
    print(result)
    print(result.text)
    #Unmount SD card and deactivate WiFi
    uos.umount('/sd')
    wifi.active(False)
    ap_if.active(True)
    return result.text[-3]
 def cleanup(self):
     self.close_recorder()
     try:
         uos.umount(self._ramdisk_mount_point)
     except OSError as e:
         print(e)
     if self._task:
         kpu.deinit(self._task)
         self._task = None
Esempio n. 10
0
 def umountflash(self):                      # Unmount flash
     if self.flash is None:
         return
     if self.mounted:
         self.flash.synchronise()
     try:
         uos.umount(self.flash.mountpoint)
     except OSError:
         pass                                # Don't care if it wasn't mounted
     self.flash.end()                        # Shut down
     self.mounted = False                    # flag unmounted to prevent spurious syncs
Esempio n. 11
0
def sd_gdt_func(timer):
    print("SD card did not mount correctly")
    # TODO: add LED sigal from board to signify this
    try:
        umount("/sdcard")
    except OSError as e:
        # TODO: add LED signal from board to signify this
        print("Reinsert SD Card in SD Card reader")
        # TODO: remove sleep once LED signal is done
        # sleep gives time to read comment before reseting the board
        sleep(3)
    reset()
Esempio n. 12
0
def test(bdev, vfs_class):
    print("test", vfs_class)

    # mkfs
    vfs_class.mkfs(bdev)

    # construction
    vfs = vfs_class(bdev)

    # mount
    uos.mount(vfs, "/lfs")

    # import
    with open("/lfs/lfsmod.py", "w") as f:
        f.write('print("hello from lfs")\n')
    import lfsmod

    # import package
    uos.mkdir("/lfs/lfspkg")
    with open("/lfs/lfspkg/__init__.py", "w") as f:
        f.write('print("package")\n')
    import lfspkg

    # chdir and import module from current directory (needs "" in sys.path)
    uos.mkdir("/lfs/subdir")
    uos.chdir("/lfs/subdir")
    uos.rename("/lfs/lfsmod.py", "/lfs/subdir/lfsmod2.py")
    import lfsmod2

    # umount
    uos.umount("/lfs")

    # mount read-only
    vfs = vfs_class(bdev)
    uos.mount(vfs, "/lfs", readonly=True)

    # test reading works
    with open("/lfs/subdir/lfsmod2.py") as f:
        print("lfsmod2.py:", f.read())

    # test writing fails
    try:
        open("/lfs/test_write", "w")
    except OSError as er:
        print(repr(er))

    # umount
    uos.umount("/lfs")

    # clear imported modules
    usys.modules.clear()
Esempio n. 13
0
def __main__(args):
    if len(args) < 3:
        print("Usage:")
        print("umount <path>")
        print("umount /ram0")
        return
    path = args[2]
    if path in _vfses:
        vfs, bdev = _vfses[path]
        uos.umount(vfs)
        del _vfses[path]
        gc.collect()
    else:
        uos.umount(args[2])
Esempio n. 14
0
 def umount(self):
   try:
     uos.umount("/sd")
     try:
       self.sd.deinit()
       del self.sd
     except:
       pass
     # let all SD pins be inputs
     for i in bytearray([2,4,12,13,14,15]):
       p = Pin(i,Pin.IN)
       a = p.value()
       del p, a
     return True
   except:
     return False
Esempio n. 15
0
def foo():
    aux = imu.dumpfifo()
    aux = imu.sortfifo(aux)
    print("[debug] ms_intA: {}".format(ticks_ms()))

    if sd is not None:
        uos.mount(sd, '/')
        lista_dir = uos.listdir()
        count = 0
        while ('acc%d.csv' % (count)) in lista_dir:
            count = count + 1
        print(count)
        f = open('acc%d.csv' % (count), 'a')
        f.write("{},{}\n".format(imu.readtostring(aux[0]), rtc.datetime()))
        for i in aux[1:len(aux)]:
            f.write("{}\n".format(imu.readtostring(i)))
        f.close()
        uos.umount("/")
Esempio n. 16
0
async def record_wav_to_sdcard(audio_in, wav):
    sreader = asyncio.StreamReader(audio_in)

    # create header for WAV file and write to SD card
    wav_header = create_wav_header(
        SAMPLE_RATE_IN_HZ,
        WAV_SAMPLE_SIZE_IN_BITS,
        NUM_CHANNELS,
        SAMPLE_RATE_IN_HZ * RECORD_TIME_IN_SECONDS,
    )
    num_bytes_written = wav.write(wav_header)

    # allocate sample array
    # memoryview used to reduce heap allocation
    mic_samples = bytearray(10000)
    mic_samples_mv = memoryview(mic_samples)

    num_sample_bytes_written_to_wav = 0

    # continuously read audio samples from I2S hardware
    # and write them to a WAV file stored on a SD card
    print("Recording size: {} bytes".format(RECORDING_SIZE_IN_BYTES))
    print("==========  START RECORDING ==========")
    while num_sample_bytes_written_to_wav < RECORDING_SIZE_IN_BYTES:
        # read samples from the I2S peripheral
        num_bytes_read_from_mic = await sreader.readinto(mic_samples_mv)

        # write samples to WAV file
        if num_bytes_read_from_mic > 0:
            num_bytes_to_write = min(
                num_bytes_read_from_mic,
                RECORDING_SIZE_IN_BYTES - num_sample_bytes_written_to_wav)
            num_bytes_written = wav.write(mic_samples_mv[:num_bytes_to_write])
            num_sample_bytes_written_to_wav += num_bytes_written

    print("==========  DONE RECORDING ==========")
    # cleanup
    wav.close()
    if uos.uname().machine.find("PYBD") == 0:
        uos.umount("/sd")
    if uos.uname().machine.find("ESP32") == 0:
        uos.umount("/sd")
        sd.deinit()
    audio_in.deinit()
Esempio n. 17
0
def Sampling(th,ts,tp):
    thi = th
    tsi = ts+th
    tpi = tp+ts
    spisd=SPI(-1,sck=Pin(18),mosi=Pin(23),miso=Pin(19))
    sd=sdcard.SDCard(spisd,Pin(5))
    uos.mount(sd,'/sd')
    filename = time.localtime()
    filename = "Sampling_{}-{}-{}_{}-{}-{}.csv".format(filename[3],filename[4],filename[5],filename[2],filename[1],filename[0])
    f = open("/sd/{}".format(filename),"a")
    f.write("time(s),TGS 2600,TGS 2602,TGS 2611,TGS 2620,TGS 813,TGS 816,TGS 821,TGS 822,TGS 826,TGS 832,Temp,Humid\n")
    t = 0
    ti = 0
    data = Sensor_Read(th)
    while t<thi:
        print("Heating_t:{}".format(t))
        S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12 = data[ti]
        f.write("{},{},{},{},{},{},{},{},{},{},{},{},{}\n".format(t,S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12))
        print("{},{},{},{},{},{},{},{},{},{},{},{},{}\n".format(t,S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12))
        ti+=1
        t+=1
    pump("Sampling")
    data = Sensor_Read(ts)
    ti=0
    while t>=thi and t<tsi:
        print("Sampling_t:{}".format(t))
        S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12 = data[ti]
        f.write("{},{},{},{},{},{},{},{},{},{},{},{},{}\n".format(t,S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12))
        print("{},{},{},{},{},{},{},{},{},{},{},{},{}\n".format(t,S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12))
        ti+=1
        t+=1
    pump("Purging")
    data = Sensor_Read(tp)
    ti=0
    while t>=tsi and t<tpi:
        print("Purging_t:{}".format(t))
        S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12 = data[ti]
        f.write("{},{},{},{},{},{},{},{},{},{},{},{},{}\n".format(t,S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12))
        print("{},{},{},{},{},{},{},{},{},{},{},{},{}\n".format(t,S1,S2,S3,S4,S5,S6,S7,S8,S9,S10,S11,S12))
        ti+=1
        t+=1
    f.close()
    uos.umount('/sd')
    return filename
Esempio n. 18
0
def i2s_callback_rx(arg):
    global state
    global num_sample_bytes_written_to_wav
    global mic_samples_mv
    global num_read

    if state == RECORD:
        num_bytes_written = wav.write(mic_samples_mv[:num_read])
        num_sample_bytes_written_to_wav += num_bytes_written
        # read samples from the I2S device.  This callback function
        # will be called after 'mic_samples_mv' has been completely filled
        # with audio samples
        num_read = audio_in.readinto(mic_samples_mv)
    elif state == RESUME:
        state = RECORD
        num_read = audio_in.readinto(mic_samples_mv)
    elif state == PAUSE:
        # in the PAUSE state read audio samples from the I2S device
        # but do not write the samples to SD card
        num_read = audio_in.readinto(mic_samples_mv)
    elif state == STOP:
        # create header for WAV file and write to SD card
        wav_header = create_wav_header(
            SAMPLE_RATE_IN_HZ,
            WAV_SAMPLE_SIZE_IN_BITS,
            NUM_CHANNELS,
            num_sample_bytes_written_to_wav //
            (WAV_SAMPLE_SIZE_IN_BYTES * NUM_CHANNELS),
        )
        pos = wav.seek(
            0)  # advance to first byte of Header section in WAV file
        num_bytes_written = wav.write(wav_header)
        # cleanup
        wav.close()
        if uos.uname().machine.find("PYBD") == 0:
            uos.umount("/sd")
        if uos.uname().machine.find("ESP32") == 0:
            uos.umount("/sd")
            sd.deinit()
        audio_in.deinit()
        print("Done")
    else:
        print("Not a valid state.  State ignored")
Esempio n. 19
0
def fstest(format=False):
    eep = get_eep()
    try:
        uos.umount('/eeprom')
    except OSError:
        pass
    # ***** CODE FOR FATFS *****
    #if format:
    #os.VfsFat.mkfs(eep)
    # ***** CODE FOR LITTLEFS *****
    if format:
        uos.VfsLfs2.mkfs(eep)
    # General
    try:
        uos.mount(eep, '/eeprom')
    except OSError:
        raise OSError("Can't mount device: have you formatted it?")
    print('Contents of "/": {}'.format(uos.listdir('/')))
    print('Contents of "/eeprom": {}'.format(uos.listdir('/eeprom')))
    print(uos.statvfs('/eeprom'))
Esempio n. 20
0
    def _create_disk(self):
        mnt = "/ramdisk"
        self.disk = Ramdisk(512, 200)  # 500 KiB
        uos.VfsFat.mkfs(self.disk)
        vfs = uos.VfsFat(self.disk)
        uos.mount(vfs, mnt)

        entries = uos.listdir(self.folder)
        self.mtime = 0
        for entry in entries:
            path = self.folder + "/" + entry
            mtime_entry = uos.stat(path)[-1]
            if self.mtime < mtime_entry:
                self.mtime = mtime_entry
            # print(entry, mtime_entry)
            src = open(path, "r")
            dest = open(mnt + "/" + entry, "w")
            dest.write(src.read())
            src.close()
            dest.close()
        uos.umount(mnt)
Esempio n. 21
0
        pass
    def stat(self, path):
        print('stat', path)
        if path in self.files:
            return (32768, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        raise OSError
    def open(self, path, mode):
        print('open', path, mode)
        return UserFile(self.files[path])


# create and mount a user filesystem
user_files = {
    '/data.txt': b"some data in a text file\n",
    '/usermod1.py': b"print('in usermod1')\nimport usermod2",
    '/usermod2.py': b"print('in usermod2')",
}
uos.mount(UserFS(user_files), '/userfs')

# open and read a file
f = open('/userfs/data.txt')
print(f.read())

# import files from the user filesystem
sys.path.append('/userfs')
import usermod1

# unmount and undo path addition
uos.umount('/userfs')
sys.path.pop()
Esempio n. 22
0
        #print("ioctl(%d, %r)" % (op, arg))
        if op == 4:  # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
            return self.blocks
        if op == 5:  # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
            return self.SEC_SIZE


try:
    bdev = RAMBDevSparse(4 * 1024 * 1024 * 1024 // RAMBDevSparse.SEC_SIZE)
    uos.VfsFat.mkfs(bdev)
except MemoryError:
    print("SKIP")
    raise SystemExit

vfs = uos.VfsFat(bdev)
uos.mount(vfs, "/ramdisk")

print("statvfs:", vfs.statvfs("/ramdisk"))

f = open('/ramdisk/test.txt', 'w')
f.write('test file')
f.close()

print("statvfs:", vfs.statvfs("/ramdisk"))

f = open('/ramdisk/test.txt')
print(f.read())
f.close()

uos.umount(vfs)
Esempio n. 23
0
import uos

import computer
from filesystem import FileSystem

uos.umount('/')
uos.mount(FileSystem(__path__), '/')
uos.mount(FileSystem(computer.get_tmp_address()), '/tmp')
Esempio n. 24
0
        b'\x51'  # LOAD_CONST_NONE
        b'\x63'  # RETURN_VALUE
        b'\x02m\x02m\x00\x02'  # simple_name, source_file, n_obj, n_raw_code
        b'\x22'  # n bytes, viper code
        b'\x00\x00\x00\x00\x00\x00'  # dummy machine code
        b'\x00\x00'  # qstr0
        b'\x01\x0c\x0aprint'  # n_qstr, qstr0
        b'\x00\x00\x00'  # scope_flags, n_obj, n_raw_code
        b'\x23'  # n bytes, asm code
        b'\x00\x00\x00\x00\x00\x00\x00\x00'  # dummy machine code
        b'\x00\x00\x00'  # scope_flags, n_pos_args, type_sig
    ),
}

# create and mount a user filesystem
uos.mount(UserFS(user_files), '/userfs')
sys.path.append('/userfs')

# import .mpy files from the user filesystem
for i in range(len(user_files)):
    mod = 'mod%u' % i
    try:
        __import__(mod)
        print(mod, 'OK')
    except ValueError as er:
        print(mod, 'ValueError', er)

# unmount and undo path addition
uos.umount('/userfs')
sys.path.pop()
Esempio n. 25
0
    def stat(self, path):
        print(self.id, "stat", path)
        return (self.id, )

    def statvfs(self, path):
        print(self.id, "statvfs", path)
        return (self.id, )

    def open(self, file, mode):
        print(self.id, "open", file, mode)


# first we umount any existing mount points the target may have
try:
    uos.umount("/")
except OSError:
    pass
for path in uos.listdir("/"):
    uos.umount("/" + path)

# stat root dir
print(uos.stat("/"))

# statvfs root dir; verify that f_namemax has a sensible size
print(uos.statvfs("/")[9] >= 32)

# getcwd when in root dir
print(uos.getcwd())

# basic mounting and listdir
Esempio n. 26
0
print(b"FOO_FILETXT" in bdev.data)
print(b"hello!" in bdev.data)

vfs.mkdir("foo_dir")
vfs.chdir("foo_dir")
print("getcwd:", vfs.getcwd())
print(list(vfs.ilistdir()))

with vfs.open("sub_file.txt", "w") as f:
    f.write("subdir file")

try:
    vfs.chdir("sub_file.txt")
except OSError as e:
    print(e.args[0] == uerrno.ENOENT)

vfs.chdir("..")
print("getcwd:", vfs.getcwd())

uos.umount(vfs)

vfs = uos.VfsFat(bdev)
print(list(vfs.ilistdir(b"")))

# list a non-existent directory
try:
    vfs.ilistdir(b"no_exist")
except OSError as e:
    print('ENOENT:', e.args[0] == uerrno.ENOENT)
Esempio n. 27
0
def umount():
    try:
        uos.umount("/sd")
        return True
    except:
        return False
Esempio n. 28
0
        print(self.id, 'rename', old_path, new_path)
    def rmdir(self, path):
        print(self.id, 'rmdir', path)
    def stat(self, path):
        print(self.id, 'stat', path)
        return (self.id,)
    def statvfs(self, path):
        print(self.id, 'statvfs', path)
        return (self.id,)
    def open(self, file, mode):
        print(self.id, 'open', file, mode)


# first we umount any existing mount points the target may have
try:
    uos.umount('/')
except OSError:
    pass
for path in uos.listdir('/'):
    uos.umount('/' + path)

# stat root dir
print(uos.stat('/'))

# statvfs root dir; verify that f_namemax has a sensible size
print(uos.statvfs('/')[9] >= 32)

# getcwd when in root dir
print(uos.getcwd())

# basic mounting and listdir
def unMount():
    with open('/sd/datalogger_output.txt', 'a') as o:
        o.close()
        uos.umount('/sd')
        print('SD card has been unmounted!')
# These are the test .mpy files.
user_files = {
    "/features0.mpy": features0_file_contents[sys.implementation.mpy]
}

# Create and mount a user filesystem.
uos.mount(UserFS(user_files), "/userfs")
sys.path.append("/userfs")

# Import the native function.
gc.collect()
from features0 import factorial

# Free the module that contained the function.
del sys.modules["features0"]

# Run a GC cycle which should reclaim the module but not the function.
gc.collect()

# Allocate lots of fragmented memory to overwrite anything that was just freed by the GC.
for i in range(1000):
    []

# Run the native function, it should not have been freed or overwritten.
print(factorial(10))

# Unmount and undo path addition.
uos.umount("/userfs")
sys.path.pop()
# append
f = open('/sd/test.py', 'a')
f.write('print(\'hello again\')\n')
f.close()

# read again
f = open('/sd/test.py', 'r')
print(f.read())
f.close()

# remove the file
os.remove('/sd/test.py')

# unmount
os.umount('/sd')

# yep, it's gone
os.listdir()
# ['boot.py', 'main.py']

sd.deinit()
# I (1199930) gpio: GPIO[23]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
# I (1199930) gpio: GPIO[19]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0
# I (1199940) gpio: GPIO[18]| InputEn: 0| OutputEn: 0| OpenDrain: 0| Pullup: 1| Pulldown: 0| Intr:0

sd.info()
# (7948206080, 512)
# (7948206080/1024/1024/1024 = 7.4GB) - 8GB SanDisk MicroSD card

# mount (fail)
Esempio n. 32
0
    sck_pin = Pin(SCK_PIN)
    ws_pin = Pin(WS_PIN)
    sd_pin = Pin(SD_PIN)

    audio_in = I2S(
        I2S_ID,
        sck=sck_pin,
        ws=ws_pin,
        sd=sd_pin,
        mode=I2S.RX,
        bits=WAV_SAMPLE_SIZE_IN_BITS,
        format=FORMAT,
        rate=SAMPLE_RATE_IN_HZ,
        bufferlen=BUFFER_LENGTH_IN_BYTES,
    )

    wav = open("/sd/{}".format(WAV_FILE), "wb")
    asyncio.run(main(audio_in, wav))
except (KeyboardInterrupt, Exception) as e:
    print("Exception {} {}\n".format(type(e).__name__, e))
finally:
    # cleanup
    wav.close()
    if uos.uname().machine.find("PYBD") == 0:
        uos.umount("/sd")
    if uos.uname().machine.find("ESP32") == 0:
        uos.umount("/sd")
        sd.deinit()
    audio_in.deinit()
    ret = asyncio.new_event_loop()  # Clear retained uasyncio state
Esempio n. 33
0
        if op == 4:  # MP_BLOCKDEV_IOCTL_BLOCK_COUNT
            return len(self.data) // self.SEC_SIZE
        if op == 5:  # MP_BLOCKDEV_IOCTL_BLOCK_SIZE
            return self.SEC_SIZE


try:
    bdev = RAMFS(50)
    bdev2 = RAMFS(50)
except MemoryError:
    print("SKIP")
    raise SystemExit

# first we umount any existing mount points the target may have
try:
    uos.umount("/")
except OSError:
    pass
for path in uos.listdir("/"):
    uos.umount("/" + path)

uos.VfsFat.mkfs(bdev)
uos.mount(bdev, "/")

print(uos.getcwd())

f = open("test.txt", "w")
f.write("hello")
f.close()

print(uos.listdir())
# Simple demo of FRAM on ESP8266 using pins marked on Feather Huzzah (4,5).
# assumes device has already been formatted
# Has been tested with two contiguous FRAM boards
from fram import FRAM
import uos
import machine
scl = machine.Pin(5, machine.Pin.OUT)
sda = machine.Pin(4, machine.Pin.OUT)
i2c = machine.I2C(scl, sda)
i2c.scan()
fram = FRAM(i2c, verbose=True)
uos.umount() # alas can only mount one FS
fs = uos.VfsFat(fram, '/')
uos.listdir('/')

Esempio n. 35
0
        if op == 4:  # BP_IOCTL_SEC_COUNT
            return len(self.data) // self.SEC_SIZE
        if op == 5:  # BP_IOCTL_SEC_SIZE
            return self.SEC_SIZE


try:
    bdev = RAMFS(50)
    bdev2 = RAMFS(50)
except MemoryError:
    print("SKIP")
    raise SystemExit

# first we umount any existing mount points the target may have
try:
    uos.umount('/')
except OSError:
    pass
for path in uos.listdir('/'):
    uos.umount('/' + path)

uos.VfsFat.mkfs(bdev)
uos.mount(bdev, '/')

print(uos.getcwd())

f = open('test.txt', 'w')
f.write('hello')
f.close()

print(uos.listdir())