<commit_before>// Package buspirate interfaces with the binary mode of the BusPirate.
// http://dangerousprototypes.com/docs/Bus_Pirate
package buspirate

import (
	"fmt"
	"github.com/pkg/term"
	"time"
)

// Open opens a connection to a BusPirate module and places it into binary mode.
func Open(dev string) (*BusPirate, error) {
	t, err := term.Open(dev, term.Speed(115200), term.RawMode)
	if err != nil {
		return nil, err
	}
	bp := BusPirate{term: t}
	return &bp, bp.enterBinaryMode()
}

// BusPirate represents a connection to a remote BusPirate device.
type BusPirate struct {
	term *term.Term
}

// enterBinaryMode resets the BusPirate and enters binary mode.
// http://dangerousprototypes.com/docs/Bitbang
func (bp *BusPirate) enterBinaryMode() error {
	bp.term.Flush()
	bp.term.Write([]byte{'\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n'})
	const n = 30
	for i := 0; i < n; i++ {
		// send binary reset
		bp.term.Write([]byte{0x00})
		time.Sleep(10 * time.Millisecond)
		n, err := bp.term.Available()
		if err != nil {
			return err
		}
		buf := make([]byte, n)
		_, err = bp.term.Read(buf)
		if err != nil {
			return err
		}
		if string(buf) == "BBIO1" {
			return nil
		}
	}
	return fmt.Errorf("could not enter binary mode")
}

// PowerOn turns on the 5v and 3v3 regulators.
func (bp *BusPirate) PowerOn() {
	buf := []byte{0xc0}
	bp.term.Write(buf)
	bp.term.Read(buf)
}

// PowerOff turns off the 5v and 3v3 refulators.
func (bp *BusPirate) PowerOff() {<commit_msg>how many typos am I going to make ?<commit_after>// Package buspirate interfaces with the binary mode of the BusPirate.
// http://dangerousprototypes.com/docs/Bus_Pirate
package buspirate

import (
	"fmt"
	"github.com/pkg/term"
	"time"
)

// Open opens a connection to a BusPirate module and places it into binary mode.
func Open(dev string) (*BusPirate, error) {
	t, err := term.Open(dev, term.Speed(115200), term.RawMode)
	if err != nil {
		return nil, err
	}
	bp := BusPirate{term: t}
	return &bp, bp.enterBinaryMode()
}

// BusPirate represents a connection to a remote BusPirate device.
type BusPirate struct {
	term *term.Term
}

// enterBinaryMode resets the BusPirate and enters binary mode.
// http://dangerousprototypes.com/docs/Bitbang
func (bp *BusPirate) enterBinaryMode() error {
	bp.term.Flush()
	bp.term.Write([]byte{'\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n', '\n'})
	const n = 30
	for i := 0; i < n; i++ {
		// send binary reset
		bp.term.Write([]byte{0x00})
		time.Sleep(10 * time.Millisecond)
		n, err := bp.term.Available()
		if err != nil {
			return err
		}
		buf := make([]byte, n)
		_, err = bp.term.Read(buf)
		if err != nil {
			return err
		}
		if string(buf) == "BBIO1" {
			return nil
		}
	}
	return fmt.Errorf("could not enter binary mode")
}

// PowerOn turns on the 5v and 3v3 regulators.
func (bp *BusPirate) PowerOn() {
	buf := []byte{0xc0}
	bp.term.Write(buf)
	bp.term.Read(buf)
}

// PowerOff turns off the 5v and 3v3 regulators.
func (bp *BusPirate) PowerOff() {
{'fraction_non_alphanumeric': 0.1591060707138092, 'fraction_numerical': 0.015343562374916611, 'mean_word_length': 3.4038179148311305, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7337392', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1137, 'n_words': 338}