25
25
:properties [" openFile" ]
26
26
:filters filters})
27
27
callback)))
28
+ (defn- dfu-command
29
+ []
30
+ (when ((.-sync command-exists) " dfu-util" )
31
+ " dfu-util" ))
28
32
29
33
(defn flash-firmware
30
34
[]
31
- (r/with-let [loaded? (r/atom false )
32
- dfu-path (r/atom (if ((.-sync command-exists) " dfu-util" ) " dfu-util" " " ))
33
- bin-file (r/atom " " )
34
- flashing? (r/atom false )
35
- progress (r/atom " " )
36
- status (r/atom :none )]
37
- (fn []
38
- ; ; TODO - Read this in on start...
39
- (when (false ? @loaded?)
40
- (go
41
- (let [cfg-val (<? (config/get :dfu-util-path ))
42
- last-dl (<? (config/get :last-download ))]
43
- (when (some? cfg-val) (reset! dfu-path cfg-val))
44
- (when (some? last-dl) (reset! bin-file last-dl))
45
- (reset! loaded? true )
46
- )))
47
-
48
- (add-watch dfu-path :path-update
49
- (fn [k a prev next]
50
- (when (not= prev next)
51
- (config/set :dfu-util-path next))))
52
- (letfn [(exec-flash []
53
- (reset! progress " " )
54
- (reset! flashing? true )
55
- (reset! status :in-progress )
56
- (let [cmd (.spawn child-process @dfu-path #js [" -D" @bin-file])
57
- stdout (.-stdout cmd)
58
- stderr (.-stderr cmd)]
59
- (.on cmd " close"
60
- (fn [code]
61
- (reset! status (if (= code 0 ) :success :failure ))
62
- (swap! progress str
63
- (if (= code 0 )
64
- " SUCCESS!"
65
- " FAILED!" ))))
66
- (.on stdout " data" (fn [data] (swap! progress str data)))
67
- (.on stderr " data" (fn [data] (swap! progress str " ERROR: " data)))
68
- ))]
69
- [:div
70
- [:div {:style {:float " left"
71
- :width " 310px" }}
72
- [:h3 " Flash Firmware" ]
73
- [:div {:style {:display " flex" }}
74
- [kii-mui/text-field
75
- {:floating-label-text " dfu-util command"
76
- :value @dfu-path
77
- :on-change (fn [_ val] (reset! dfu-path val))
78
- :error-text (when-not (or (= 0 (count @dfu-path)) (str/includes? @dfu-path " dfu-util" ))
79
- " does not appear to be the dfu-util binary" )
80
- :error-style {:color (mui-core/color :deep-orange300 )}
81
- }
82
- ]
35
+ (let [last-download (<<= [:local/last-download ])
36
+ dfu-util-path (<<= [:local/dfu-util-path ])]
37
+ (logf :info " %s" last-download)
38
+ (r/with-let [loaded? (r/atom false )
39
+ dfu-path (r/atom (or dfu-util-path (dfu-command ) nil ))
40
+ bin-file (r/atom (or (:bin last-download) " " ))
41
+ flashing? (r/atom false )
42
+ progress (r/atom " " )
43
+ status (r/atom :none )]
44
+ (fn []
45
+ (letfn [(exec-flash []
46
+ (reset! progress " " )
47
+ (reset! flashing? true )
48
+ (reset! status :in-progress )
49
+ (let [cmd (.spawn child-process @dfu-path #js [" -D" @bin-file])
50
+ stdout (.-stdout cmd)
51
+ stderr (.-stderr cmd)]
52
+ (.on cmd " close"
53
+ (fn [code]
54
+ (reset! status (if (= code 0 ) :success :failure ))
55
+ (swap! progress str
56
+ (if (= code 0 )
57
+ " SUCCESS!"
58
+ " FAILED!" ))))
59
+ (.on stdout " data" (fn [data] (swap! progress str data)))
60
+ (.on stderr " data" (fn [data] (swap! progress str " ERROR: " data)))
61
+ ))
62
+ (change-dfu-path [val]
63
+ (reset! dfu-path val)
64
+ (=>> [:local/set-dfu-util-path val]))]
65
+ [:div
66
+ [:div {:style {:float " left"
67
+ :width " 310px" }}
68
+ [:h3 " Flash Firmware" ]
69
+ [:div {:style {:display " flex" }}
70
+ [kii-mui/text-field
71
+ {:floating-label-text " dfu-util command"
72
+ :value @dfu-path
73
+ :on-change (fn [_ val] (change-dfu-path val))
74
+ :error-text (when-not (or (= 0 (count @dfu-path)) (str/includes? @dfu-path " dfu-util" ))
75
+ " does not appear to be the dfu-util binary" )
76
+ :error-style {:color (mui-core/color :deep-orange300 )}
77
+ }
78
+ ]
83
79
84
- [mui/icon-button
85
- {:style {:margin-left " 1em" :align-self " flex-end" }
86
- :on-click #(open-dialog " path to dfu-util" [{:name " All Files" :extensions [" *" ]}]
87
- (fn [selected]
88
- (when-let [file (first selected)]
89
- ( reset! dfu-path file))))
80
+ [mui/icon-button
81
+ {:style {:margin-left " 1em" :align-self " flex-end" }
82
+ :on-click #(open-dialog " path to dfu-util" [{:name " All Files" :extensions [" *" ]}]
83
+ (fn [selected]
84
+ (when-let [file (first selected)]
85
+ ( change- dfu-path file))))
90
86
91
- }
92
- [mui-icons/navigation-more-vert
93
- {:color " black" }]
94
- ]
95
- ]
87
+ }
88
+ [mui-icons/navigation-more-vert
89
+ {:color " black" }]
90
+ ]
91
+ ]
96
92
97
- [:div {:style {:display " flex" }}
98
- [kii-mui/text-field
99
- {:floating-label-text " .bin file to flash"
100
- :value @bin-file
101
- :on-change (fn [_ val] (reset! bin-file val))
102
- :error-text (when-not (or (= 0 (count @bin-file)) (str/ends-with? @bin-file " .bin" ))
103
- " does not appear to be a .bin file" )
104
- :error-style {:color (mui-core/color :deep-orange300 )}
105
- }
93
+ [:div {:style {:display " flex" }}
94
+ [kii-mui/text-field
95
+ {:floating-label-text " .bin file to flash"
96
+ :value @bin-file
97
+ :on-change (fn [_ val] (reset! bin-file val))
98
+ :error-text (when-not (or (= 0 (count @bin-file)) (str/ends-with? @bin-file " .bin" ))
99
+ " does not appear to be a .bin file" )
100
+ :error-style {:color (mui-core/color :deep-orange300 )}
101
+ }
106
102
107
- ]
103
+ ]
108
104
109
- [mui/icon-button
110
- {:style {:margin-left " 1em" :align-self " flex-end" }
111
- :on-click #(open-dialog " firmware to flash" [{:name " bin files" :extensions [" bin" ]}]
112
- (fn [selected]
113
- (when-let [file (first selected)]
114
- (reset! bin-file file))))
105
+ [mui/icon-button
106
+ {:style {:margin-left " 1em" :align-self " flex-end" }
107
+ :on-click #(open-dialog " firmware to flash" [{:name " bin files" :extensions [" bin" ]}]
108
+ (fn [selected]
109
+ (when-let [file (first selected)]
110
+ (reset! bin-file file))))
115
111
116
- }
117
- [mui-icons/navigation-more-vert
118
- {:color " black" }]
119
- ]
120
- ]
121
- [mui/raised-button
122
- {:style {:float " right" :margin-right " 55px" :margin-top " 20px" }
123
- :label " Flash"
124
- :primary true
125
- :disabled (or (str/empty-or-nil? @dfu-path) (str/empty-or-nil? @bin-file) (= @status :in-progress ))
126
- :on-click #(exec-flash )}]
127
- ]
128
- (when @flashing?
129
- [:div {:style {; :margin-right "320px"
130
- :display " inline-block" }}
131
- [mui/text-field
132
- {:value @progress
133
- :floating-label-fixed true
134
- :floating-label-text " flashing progress"
135
- :disabled true
136
- :multi-line true
137
- :rows 20
138
- :style {:display " block"
139
- :width " 900px"
140
- :font-family styling/monospace-font-stack
141
- :border-top (str/fmt " 10px solid %s" (case @status :success " green" :failure " red" " lightgray" ))}
142
- :textarea-style {:white-space " pre"
143
- :padding-bottom " 1.2em"
144
- :overflow-y " hidden"
145
- :color " black"
146
- :font-size " 0.9em" }}
112
+ }
113
+ [mui-icons/navigation-more-vert
114
+ {:color " black" }]
115
+ ]
147
116
]
148
- ])
149
- ]))
150
- )
151
- )
117
+ [mui/raised-button
118
+ {:style {:float " right" :margin-right " 55px" :margin-top " 20px" }
119
+ :label " Flash"
120
+ :primary true
121
+ :disabled (or (str/empty-or-nil? @dfu-path) (str/empty-or-nil? @bin-file) (= @status :in-progress ))
122
+ :on-click #(exec-flash )}]
123
+ ]
124
+ (when @flashing?
125
+ [:div {:style {; :margin-right "320px"
126
+ :display " inline-block" }}
127
+ [mui/text-field
128
+ {:value @progress
129
+ :floating-label-fixed true
130
+ :floating-label-text " flashing progress"
131
+ :disabled true
132
+ :multi-line true
133
+ :rows 20
134
+ :style {:display " block"
135
+ :width " 900px"
136
+ :font-family styling/monospace-font-stack
137
+ :border-top (str/fmt " 10px solid %s" (case @status :success " green" :failure " red" " lightgray" ))}
138
+ :textarea-style {:white-space " pre"
139
+ :padding-bottom " 1.2em"
140
+ :overflow-y " hidden"
141
+ :color " black"
142
+ :font-size " 0.9em" }}
143
+ ]
144
+ ])
145
+ ]))
146
+ ))
147
+ )
0 commit comments