Skip to content

Commit

Permalink
refactoring for uploading firmware
Browse files Browse the repository at this point in the history
  • Loading branch information
EiichiroIto committed Apr 4, 2023
1 parent 1855a2b commit 059a9c3
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion microwitch.changes

Large diffs are not rendered by default.

Binary file modified microwitch.image
Binary file not shown.
1 change: 1 addition & 0 deletions v07/refactoring for uploading firmware2.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
'From MIT Squeak 0.9.4 (June 1, 2003) [No updates present.] on 4 April 2023 at 8:04:21 pm'!!ScratchFrameMorph methodsFor: 'microwitch'!connectMicrobit | list menu selection | scriptsPane thumbnailOff. list _ mpboard portNames sort. list isEmpty ifTrue: [^ DialogBoxMorph inform: 'no micro:bit found' localized]. list size = 1 ifTrue: [selection _ list first] ifFalse: [menu _ CustomMenu new. list do: [:each | menu add: each action: each]. selection _ menu startUp. selection ifNil: [^ self]]. self connectPort: selection ifConnectedDo: [scriptsPane thumbnailOn. ^ self]. self uploadFirmware! !!ScratchFrameMorph methodsFor: 'microwitch'!uploadFirmware | pair | self stopAll. self closeMediaEditorsAndDialogs ifFalse: [^ self]. pair := self firmwarePathByManually: true ifFail: [:str | ^ DialogBoxMorph inform: str]. (DialogBoxMorph ask: 'initialize micro:bit?' localized) ifFalse: [^ self]. self writeString: pair first as: pair second title: 'Initializing micro:bit. Do not remove your micro:bit.' localized. DialogBoxMorph inform: 'micro:bit was initialized.' localized! !!ScratchFrameMorph methodsFor: 'microwitch'!writePythonProgram | path script | self currentHatBlocks isEmpty ifTrue: [^ self]. self hasDuplicateHatBlocks ifTrue: [^ DialogBoxMorph inform: 'has duplicate hat blocks.' localized]. path := self programPathByUser. path ifNil: [^ self]. script := MicrobitCode new pythonScriptFrom: self currentHatBlocks stageMorph: workPane. self stopAll. self writeString: script as: path title: 'Writing MicroPython file.' localized. Delay waitMSecs: 500! !!ScratchFrameMorph methodsFor: 'microwitch'!writeString: aString as: pathName title: aString3 | f dir fName dialog | dir := FileDirectory default. FileDirectory splitName: pathName to: [:dir2 :name | fName := name. dir2 isEmpty ifFalse: [dir := FileDirectory on: dir2]]. (dir fileExists: fName) ifTrue: [dir deleteFileNamed: fName]. f := StandardFileStream fileNamed: pathName. f ifNil: [^ self]. dialog := DialogBoxMorph new title: ''; message: aString3. dialog openInWorld; centerOnScreen. self world doOneCycle. [f nextPutAll: aString. f close] ifError: [:err :rcvr | rcvr]. dialog delete! !ScratchFrameMorph removeSelector: #writePythonProgramAs:!ScratchFrameMorph removeSelector: #writeString:as:!
Expand Down

0 comments on commit 059a9c3

Please sign in to comment.