|
58 | 58 | code = Espruino.Core.Utils.asUTF8Bytes(code); |
59 | 59 | // Depending on settings, choose how we package code for upload |
60 | 60 | var isFlashPersistent = Espruino.Config.SAVE_ON_SEND == 2; |
61 | | - var isStorageUpload = Espruino.Config.SAVE_ON_SEND == 3; |
62 | | - var isFlashUpload = Espruino.Config.SAVE_ON_SEND == 1 || isFlashPersistent || isStorageUpload; |
63 | | - if (!isFlashUpload) return callback(code); |
| 61 | + var isStorageUpload = Espruino.Config.SAVE_ON_SEND == Espruino.Core.Send.SEND_MODE_STORAGE; |
| 62 | + var isSDCardUpload = Espruino.Config.SAVE_ON_SEND == Espruino.Core.Send.SEND_MODE_SDCARD; |
| 63 | + var isFlashUpload = Espruino.Config.SAVE_ON_SEND == Espruino.Core.Send.SEND_MODE_FLASH || isFlashPersistent || isStorageUpload; |
| 64 | + if (!isFlashUpload && !isSDCardUpload) return callback(code); |
64 | 65 |
|
65 | 66 | var asJS = Espruino.Core.Utils.toJSONishString; |
66 | 67 |
|
|
75 | 76 | hasStorage = true; |
76 | 77 | } |
77 | 78 | } |
| 79 | + const CHUNKSIZE = 1024; |
78 | 80 |
|
79 | 81 | // Now create the commands to do the upload |
80 | 82 | console.log("Uploading "+code.length+" bytes to flash"); |
| 83 | + // FIXME: We should use Serial's Connection class packet stuff for file uploads |
81 | 84 | if (!hasStorage) { // old style |
82 | | - if (isStorageUpload) { |
| 85 | + if (isStorageUpload || isSDCardUpload) { |
83 | 86 | Espruino.Core.Notifications.error("You have pre-1v96 firmware - unable to upload to Storage"); |
84 | 87 | code = ""; |
85 | 88 | } else { |
86 | 89 | Espruino.Core.Notifications.error("You have pre-1v96 firmware. Upload size is limited by available RAM"); |
87 | | - code = "E.setBootCode("+asJS(code)+(isFlashPersistent?",true":"")+");load()\n"; |
| 90 | + code = "E.setBootCode("+asJS(code)+(isFlashPersistent?",true":"")+");"; |
88 | 91 | } |
| 92 | + } else if (isSDCardUpload) { |
| 93 | + var filename = Espruino.Config.SAVE_STORAGE_FILE;; |
| 94 | + var newCode = [ `let _ul = E.openFile(${asJS(filename)},"w");` ]; |
| 95 | + var len = code.length; |
| 96 | + for (var i=0;i<len;i+=CHUNKSIZE) |
| 97 | + newCode.push(`_ul.write(${asJS(code.substr(i,CHUNKSIZE))});`); |
| 98 | + newCode.push(`_ul.close();delete _ul;`); |
| 99 | + code = newCode.join("\n"); |
89 | 100 | } else { // new style |
90 | 101 | var filename; |
91 | 102 | if (isStorageUpload) |
|
96 | 107 | Espruino.Core.Notifications.error("Invalid Storage file name "+JSON.stringify(filename)); |
97 | 108 | code = ""; |
98 | 109 | } else { |
99 | | - var CHUNKSIZE = 1024; |
100 | 110 | var newCode = []; |
101 | 111 | var len = code.length; |
102 | 112 | newCode.push('require("Storage").write('+asJS(filename)+','+asJS(code.substr(0,CHUNKSIZE))+',0,'+len+');'); |
103 | 113 | for (var i=CHUNKSIZE;i<len;i+=CHUNKSIZE) |
104 | 114 | newCode.push('require("Storage").write('+asJS(filename)+','+asJS(code.substr(i,CHUNKSIZE))+','+i+');'); |
105 | 115 | code = newCode.join("\n"); |
106 | | - if (Espruino.Config.LOAD_STORAGE_FILE==2 && isStorageUpload) |
107 | | - code += "\nload("+asJS(filename)+")\n"; |
108 | | - else if (Espruino.Config.LOAD_STORAGE_FILE!=0) |
109 | | - code += "\nload()\n"; |
110 | 116 | } |
111 | 117 | } |
| 118 | + if (Espruino.Config.LOAD_STORAGE_FILE==2 && isStorageUpload) |
| 119 | + code += "\nload("+asJS(filename)+")\n"; |
| 120 | + else if (Espruino.Config.LOAD_STORAGE_FILE!=0) |
| 121 | + code += "\nload()\n"; |
| 122 | + else code += "\n"; |
112 | 123 | callback(code); |
113 | 124 | } |
114 | 125 |
|
|
0 commit comments