Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make delay before uploading files configurable #142

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions scripts/microupload.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@

Options:
-X --exclude=PATH Path to exclude, may be repeated.
-C --chdir=PATH Change current directory to path.
-C --chdir=PATH Change current directory to <PATH>.
-D --delay=DELAY Wait for DELAY seconds before trying to upload files.
-v --verbose Verbose output.
"""

Expand All @@ -46,6 +47,11 @@ def main(args: List[str]) -> None:
opts = docopt(__doc__, argv=args)
verbose = opts['--verbose']
root = opts['PATH']
try:
delay = float(opts.get('--delay', 0.5))
except ValueError:
delay = 0.5
print("Got incorrect 'delay' value, defaulting to 0.5 seconds.", file=sys.stderr)

chdir = opts['--chdir']
if chdir:
Expand All @@ -57,7 +63,8 @@ def main(args: List[str]) -> None:
files = Files(board)
rel_root = os.path.relpath(root, os.getcwd())

wait_for_board()
print('Waiting {} seconds before connecting to board...'.format(delay), file=sys.stderr)
wait_for_board(delay)

if os.path.isdir(root):
to_upload = [os.path.join(rel_root, x)
Expand Down Expand Up @@ -116,9 +123,9 @@ def list_files(path: str, excluded: List[str]) -> Iterable[str]:
yield os.path.relpath(os.path.join(root, f), path)


def wait_for_board() -> None:
def wait_for_board(delay: float = 0.5) -> None:
"""Wait for some ESP8266 devices to become ready for REPL commands."""
time.sleep(0.5)
time.sleep(delay)


def progress(msg: str, xs: Sequence[T]) -> Iterable[T]:
Expand Down
8 changes: 5 additions & 3 deletions src/main/kotlin/com/jetbrains/micropython/run/MicroUpload.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ fun getMicroUploadCommand(path: String, module: Module): List<String>? {
.map { listOf("-X", it) }
.flatten()
.toList()
return listOf(pythonPath, "${MicroPythonFacet.scriptsPath}/microupload.py", "-C", rootDir.path) +
excludes +
listOf("-v", devicePath, path)
return listOf(
pythonPath, "${MicroPythonFacet.scriptsPath}/microupload.py",
"-C", rootDir.path,
"-D", facet.boardConnectionDelay.toString()
) + excludes + listOf("-v", devicePath, path)
}

private fun getClosestRoot(file: VirtualFile, module: Module): VirtualFile? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class MicroPythonDevicesConfiguration : PersistentStateComponent<MicroPythonDevi

@Attribute var autoDetectDevicePath: Boolean = true

@Attribute var boardConnectionDelay: Float = 0.5F

override fun getState() = this

override fun loadState(state: MicroPythonDevicesConfiguration) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ class MicroPythonFacet(facetType: FacetType<out Facet<*>, *>, module: Module, na
MicroPythonDevicesConfiguration.getInstance(module.project).autoDetectDevicePath = value
}

var boardConnectionDelay: Float
get() = MicroPythonDevicesConfiguration.getInstance(module.project).boardConnectionDelay
set(value) {
MicroPythonDevicesConfiguration.getInstance(module.project).boardConnectionDelay = value
}

fun getOrDetectDevicePathSynchronously(): String? =
if (autoDetectDevicePath)
detectDevicePathSynchronously(configuration.deviceProvider)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ import com.intellij.util.ui.SwingHelper
import com.intellij.util.ui.UIUtil
import com.jetbrains.micropython.devices.MicroPythonDeviceProvider
import java.awt.BorderLayout
import javax.swing.JButton
import javax.swing.JList
import javax.swing.JPanel
import javax.swing.*

/**
* @author vlan
Expand All @@ -40,6 +38,9 @@ class MicroPythonSettingsPanel(private val module: Module) : JPanel() {
private val deviceTypeCombo = ComboBox(MicroPythonDeviceProvider.providers.toTypedArray())
private val docsHyperlink = SwingHelper.createWebHyperlink("")
private val devicePath = TextFieldWithBrowseButton()

private val connectionDelayModel = SpinnerNumberModel(0.5F, 0.0F, 599.9F, 0.1F)
private val boardConnectionDelaySpinner = JSpinner(connectionDelayModel)
private val autoDetectDevicePath = CheckBox("Auto-detect device path").apply {
addActionListener {
update()
Expand All @@ -48,34 +49,37 @@ class MicroPythonSettingsPanel(private val module: Module) : JPanel() {

private val devicePathPanel: JPanel by lazy {
FormBuilder.createFormBuilder()
.addLabeledComponent("Device path:", JPanel(BorderLayout()).apply {
add(devicePath, BorderLayout.CENTER)
add(JButton("Detect").apply {
addActionListener {
devicePath.text = module.microPythonFacet?.detectDevicePathSynchronously(selectedProvider) ?: ""
}
}, BorderLayout.EAST)
})
.panel
.addLabeledComponent("Device path:", JPanel(BorderLayout()).apply {
add(devicePath, BorderLayout.CENTER)
add(JButton("Detect").apply {
addActionListener {
devicePath.text = module.microPythonFacet?.detectDevicePathSynchronously(selectedProvider) ?: ""
}
}, BorderLayout.EAST)
})
.panel
}

init {
layout = BorderLayout()
border = IdeBorderFactory.createEmptyBorder(UIUtil.PANEL_SMALL_INSETS)

val contentPanel = FormBuilder.createFormBuilder()
.addLabeledComponent("Device type:", deviceTypeCombo)
.addComponent(autoDetectDevicePath)
.addComponent(devicePathPanel)
.addComponent(docsHyperlink)
.panel
.addLabeledComponent("Device type:", deviceTypeCombo)
.addComponent(autoDetectDevicePath)
.addComponent(devicePathPanel)
.addLabeledComponent("Board detection delay (in seconds):", boardConnectionDelaySpinner)
.addComponent(docsHyperlink)
.panel

add(contentPanel, BorderLayout.NORTH)

deviceTypeCombo.apply {
renderer = object: SimpleListCellRenderer<MicroPythonDeviceProvider>() {
override fun customize(list: JList<out MicroPythonDeviceProvider>, value: MicroPythonDeviceProvider?,
index: Int, selected: Boolean, hasFocus: Boolean) {
renderer = object : SimpleListCellRenderer<MicroPythonDeviceProvider>() {
override fun customize(
list: JList<out MicroPythonDeviceProvider>, value: MicroPythonDeviceProvider?,
index: Int, selected: Boolean, hasFocus: Boolean
) {
text = value?.presentableName ?: return
}
}
Expand All @@ -97,22 +101,25 @@ class MicroPythonSettingsPanel(private val module: Module) : JPanel() {
}

fun isModified(configuration: MicroPythonFacetConfiguration, facet: MicroPythonFacet): Boolean =
deviceTypeCombo.selectedItem != configuration.deviceProvider
|| devicePath.text.nullize(true) != facet.devicePath
|| autoDetectDevicePath.isSelected != facet.autoDetectDevicePath
deviceTypeCombo.selectedItem != configuration.deviceProvider
|| devicePath.text.nullize(true) != facet.devicePath
|| autoDetectDevicePath.isSelected != facet.autoDetectDevicePath
|| boardConnectionDelaySpinner.value != facet.boardConnectionDelay

fun getDisplayName(): String = "MicroPython"

fun apply(configuration: MicroPythonFacetConfiguration, facet: MicroPythonFacet) {
configuration.deviceProvider = selectedProvider
facet.devicePath = devicePath.text.nullize(true)
facet.autoDetectDevicePath = autoDetectDevicePath.isSelected
facet.boardConnectionDelay = boardConnectionDelaySpinner.value as Float
}

fun reset(configuration: MicroPythonFacetConfiguration, facet: MicroPythonFacet) {
deviceTypeCombo.selectedItem = configuration.deviceProvider
devicePath.text = facet.devicePath ?: ""
autoDetectDevicePath.isSelected = facet.autoDetectDevicePath
boardConnectionDelaySpinner.value = facet.boardConnectionDelay
update()
}

Expand Down