-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathutil.go
More file actions
30 lines (26 loc) · 849 Bytes
/
util.go
File metadata and controls
30 lines (26 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
package main
import (
"fmt"
"github.com/fluepke/esptool/common/serial"
"github.com/fluepke/esptool/esp32"
"log"
)
func bold(s string) string {
return fmt.Sprintf("\033[1m%s\033[0m", s)
}
func underline(s string) string {
return fmt.Sprintf("\033[4m%s\033[0m", s)
}
func connectEsp32(portPath string, connectBaudrate uint32, transferBaudrate uint32, retries uint, logger *log.Logger) (*esp32.ESP32ROM, error) {
serialConfig := serial.NewConfig(portPath, connectBaudrate)
serialPort, err := serial.OpenPort(serialConfig)
if err != nil {
return nil, fmt.Errorf("Failed to open serial port: %s", err.Error())
}
esp32 := esp32.NewESP32ROM(serialPort, logger)
err = esp32.Connect(retries)
if err != nil {
return nil, fmt.Errorf("Failed to connect to ESP32: %s", err.Error())
}
return esp32, esp32.ChangeBaudrate(transferBaudrate)
}