import lvgl as lv def esp32fs_open_cb( fs_file, path, mode): print("Info: opening file '{}'".format(path)) p_mode = 'rb' if mode & 0x2 else '' p_mode = 'wb' if mode & 0x1 else '' p_mode = 'rb+' if mode & 0x3 else '' if p_mode == '': print("Warn: open mode error: {}".format(mode)) return 11 with open(path, p_mode) as f: fs_file.file_d = { 'file': f } print("Info: File {} opened".format(path)) return 0 print("Warn: Opening file {} failed".format(path)) return 4 def esp32fs_close_cb( fs_file): print("Info: called close()") d = fs_file.file_d.cast() try: d['file'].close() except: print("Warn: exception while closing file") return 12 print("Info: File descriptor closed") return 0 def esp32fs_read_cb( fs_file, buf, btr, br): print("Info: called read()") d = fs_file.file_d.cast() try: buf = d['file'].read(btr) except: print("Warn: read exception") return 3 br = len(buf) print("Info: read {}B".format(br)) return 0 def esp32fs_seek_cb( fs_file, pos): print("Info: called seek()") d = fs_file.file_d.cast() try: d['file'].seek( pos, 0) except: print("Warn: seek exception") return 3 print("Info: seek to position {}".format(pos)) return 0 def esp32fs_tell_cb( fs_file, pos): print("Info: called tell()") d = fs_file.file_d.cast() try: pos = d['file'].tell() except: print("Warn: tell exception") return 3 print("Info: position is {}".format(pos)) return 0 def esp32fs_write_cb( fs_file, buf, btw, bw): print("Info: called write()") d = fs_file.file_d.cast() try: d['file'].write(buf) except: print("Warn: write exception") return 3 bw = btw print("Info: write {}B".format(bw)) return 0