Xiaomi Yi Camera: GUI Control & Configure from PC (Win/Lin/Mac)

Hi @Andy_S , as I said last week, I'd like to share my code for you. In order to thanks for your wonderful program C&C !
first of all, I modified the function of display of the [Usage] of the first page, which to calculate the file size by "KB", "MB", ...
after many times of app hanging for the tricky Python thread call, and the incorrect tabify ident setting...
I made a standard alone function called [FileSizeName], the code as following:
Code:
  #option: 0-Starts From "B", 1-Starts From "KB"
  def FileSizeName(self, fileSizeBytes, option):
    fileName = ""
    while 1:
      if fileSizeBytes > 1024:
        fileSizeBytes = fileSizeBytes/float(1024)
        option += 1
      else:
        break
    pres = ["B", "KB", "MB", "GB", "TB"]
    fileName = "%.1f%s" %(fileSizeBytes, pres[option])
    return fileName

  def UpdateUsage(self):
    tosend = '{"msg_id":5,"token":%s,"type":"total"}' %self.token
    totalspace = self.Comm(tosend)["param"]
    tosend = '{"msg_id":5,"token":%s,"type":"free"}' %self.token
    freespace = float(self.Comm(tosend)["param"])
    usedspace = totalspace-freespace
    #totalpre = 0
    #usedpre = 0
    #while 1:
    # if usedspace > 1024:
    #   usedspace = usedspace/float(1024)
    #   usedpre += 1
    # else:
    #   break
    #while 1:
    # if totalspace > 1024:
    #   totalspace = totalspace/float(1024)
    #   totalpre += 1
    # else:
    #   break
    #pres = ["kB", "MB", "GB", "TB"]
    #usage = "Used %.1f%s of %.1f%s" %(usedspace, pres[usedpre], totalspace, pres[totalpre])
    usage = "Used %s of %s" %(self.FileSizeName(usedspace, 1), self.FileSizeName(totalspace, 1))
    self.usage.config(text=usage) #display usage message in statusbar
    self.usage.update_idletasks()

why I seperate this, because I think [FileSizeName] can be shared to the FileManager, when showing the photo/video file size. And also later display the download speed.
you use this function or not, on your own program consideration.
 
LuckyLZ: Both nice tips :) ECQU already notified me that camera does not properly handle SD insertion. I will try to implement them both. On what condition is this _thm file created? I've never seen it.
 
_thm.mp4 is created by default. Yi Cam mobile phone App. App can preview video only if the _thm.mp4 exists
 
luckylz: about this function - you cannot mix filesize and usage, because usage is returned in kB while filesize in B :)

Oh and...
0.5.2 - Download speed indicator added
 
Yes, I know. ;)
So in usage, the option starts from 1, means KB; in filesize, the option starts from 0, means B.
 
Oh sorry! I didn't notice :( (still half-sleeping :D )
 
0.5.3 - SD card detection implemented (on program launch)

There you go luckylz :) THX for the tip with space size, implemented as well ;)
Program also detects if the memory card is formatted or not and displays request if it isn't.
 
The file speed is too~too~too~ speedy & flashing !
I slow it down for 0.5 second.:cool:
The variable chunks keep receiving bytes for every 0.5 second, chunkpersecond = chuks*2 means filespeed every 1 second.
After sending to FileDownReport, so it won't flashing as fast as percentage.

The code here you are :

Code:
  #option: 0-Starts From "B", 1-Starts From "KB"
  def FileSizeName(self, fileSizeBytes, option):
    fileName = ""
    while 1:
      if fileSizeBytes > 1024:
        fileSizeBytes = fileSizeBytes/float(1024)
        option += 1
      else:
        break
    pres = ["B", "KB", "MB", "GB", "TB"]
    fileName = "%.1f%s" %(fileSizeBytes, pres[option])
    return fileName

  def FileDownReport(self, bytes_so_far, chunk_size, total_size, FileTP):
    percent = float(bytes_so_far) / total_size
    percent = round(percent*100, 2)
    #thistime = time.time()
    #if thistime - self.FileTime > 0.01:
    # ActualSpeed = float(chunk_size/(thistime-self.FileTime))
    # self.FileTime = thistime
    # pre = 0
    # while ActualSpeed > float(1024):
    #   ActualSpeed = ActualSpeed / float(1024)
    #   pre += 1
    #
    # pres = ["B", "kB", "MB", "GB", "TB"]
    # FileSpeed = "%0.2f %s" %(ActualSpeed, pres[pre])
    # self.FileProgress.config(text="Downloading %s at %s (%0.2f%%)" %(FileTP, FileSpeed, percent), bg=self.defaultbg)
    self.FileProgress.config(text="Downloading %s at %s (%0.2f%%)" %(FileTP, self.FileSizeName(chunk_size, 0), percent), bg=self.defaultbg)
    if bytes_so_far >= total_size:
      self.FileProgress.config(text="%s downloaded" %(FileTP), bg="#ddffdd")

  def FileDownChunk(self, response, chunk_size=16384, report_hook=None, FileTP=""):
    total_size = response.info().getheader('Content-Length').strip()
    total_size = int(total_size)
    bytes_so_far = 0

    ThisFileName = "Files/%s" %FileTP
    filek = open(ThisFileName, "wb")
    #self.FileTime = time.time()
    t1 = time.time()
    t2 = t1
    chunks = 0
    chunkpersecond = 0
    while 1:
      chunk = response.read(chunk_size)
      bytes_so_far += len(chunk)
  
      if not chunk:
        break
      filek.write(chunk)
      t2 = time.time()
      chunks += len(chunk)
      if (t2 - t1) >= 0.5:
        chunkpersecond = chunks * 2
        chunks = 0
        t1 = t2
      if report_hook:
        report_hook(bytes_so_far, chunkpersecond, total_size, FileTP)
    filek.close()

    return bytes_so_far

Now I can easily see the download speed.
Slow_Down_By_Half_A_Second.png
 
i see what you did there! Nice idea, you did it from the other side than me :) But still, coding this at 2am was pretty neat from me, wasn't it :D I am working on proper file transfering right now so i will implement this in the code :) Again - Thanks! :)
 
I have zero experience with Python.
Normally could understand what the code means in python, but hard to write something new.
Anyway, this program is just for fun ! You'd have a good rest first, then improve it in your free time!
 
hehe i am no programmer either, i do this just for fun & for my friend :) BTW you still didn't enable expert mode? ;)
 
I've try it, and disabled it directly from the settings.cfg. So when I printscreen, it's in normal mode.
 
:) There is no need to disable it once you are confident enough to enable it, it doesn't do anything on its own, it just allows you to do more, you just have to take responsibility for that :p :D
 
Of course, I surely have faith on you & your code !
 
Anyone found any ambarella commands for capturing RAW files yet?
 
like this http://chernowii.com/raw-gopro. Not sure if that's the raw before debayer or just uncompressed YUV. Photographers will know what I mean..

It's great we have the 7878 json commands reverse engineered but I think that is only a small amount of the functionality the AL7S has.. anyone know if these autoexec.ash "t app" style commands work on the xiaomi?
 
Oh, raw image files. I am affraid that this function is not implemented in the camera. Maybe with some modifications...

Yes, .ash scripts DO (supposedly) work on xiYi and i will be implementing them (will try to) right after i get proper filetransfer ready (i'm working on it right now) :)
 
Think for the .ash scripts you just copy autoexec.ash to the root of the sd card and boot with it?
 
i think so. No idea yet, i will have to read something about it :)
And to upload a file i will have to get rewritten file transfer part working first :D
 
Back
Top