Skip to content

Commit 3a5b32a

Browse files
committed
Make WriteStringToFile public
1 parent d57583a commit 3a5b32a

File tree

4 files changed

+11
-12
lines changed

4 files changed

+11
-12
lines changed

hwio.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,8 +380,7 @@ func WriteUIntToPins(value uint32, pins []Pin) error {
380380
}
381381

382382
// Write a string to a file and close it again.
383-
// @todo if we are writing to a /dev file, the driver may emit a message for invalid values. We should return that as an error as well.
384-
func writeStringToFile(filename string, value string) error {
383+
func WriteStringToFile(filename string, value string) error {
385384
// fmt.Printf("writing %s to file %s\n", value, filename)
386385
f, e := os.OpenFile(filename, os.O_WRONLY|os.O_TRUNC, 0666)
387386
if e != nil {

module_bb_pwm.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (module *BBPWMModule) makeOpenPin(pin Pin) (*BBPWMModuleOpenPin, error) {
166166
module.openPins[pin] = result
167167

168168
// ensure polarity is 0, so that the duty time represents the time the signal is high.
169-
e = writeStringToFile(result.polarityFile, "0")
169+
e = WriteStringToFile(result.polarityFile, "0")
170170
if e != nil {
171171
return nil, e
172172
}
@@ -196,7 +196,7 @@ func (module *BBPWMModule) ensureSlot(item string) error {
196196
}
197197

198198
// enable the item
199-
e = writeStringToFile(path, item)
199+
e = WriteStringToFile(path, item)
200200
// delay a little as it seems to take a bit of time set enable the slot
201201
Delay(100)
202202
return e
@@ -213,7 +213,7 @@ func (op *BBPWMModuleOpenPin) closePin() error {
213213
// Set the period in nanoseconds. On BBB, maximum is 1 second (1,000,000,000ns)
214214
func (op *BBPWMModuleOpenPin) setPeriod(ns int64) error {
215215
s := strconv.FormatInt(int64(ns), 10)
216-
e := writeStringToFile(op.periodFile, s)
216+
e := WriteStringToFile(op.periodFile, s)
217217
if e != nil {
218218
return e
219219
}
@@ -223,7 +223,7 @@ func (op *BBPWMModuleOpenPin) setPeriod(ns int64) error {
223223

224224
func (op *BBPWMModuleOpenPin) setDuty(ns int64) error {
225225
s := strconv.FormatInt(int64(ns), 10)
226-
e := writeStringToFile(op.dutyFile, s)
226+
e := WriteStringToFile(op.dutyFile, s)
227227
if e != nil {
228228
return e
229229
}
@@ -233,8 +233,8 @@ func (op *BBPWMModuleOpenPin) setDuty(ns int64) error {
233233

234234
func (op *BBPWMModuleOpenPin) enabled(e bool) error {
235235
if e {
236-
return writeStringToFile(op.runFile, "1")
236+
return WriteStringToFile(op.runFile, "1")
237237
} else {
238-
return writeStringToFile(op.runFile, "0")
238+
return WriteStringToFile(op.runFile, "0")
239239
}
240240
}

module_dtanalog.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (module *DTAnalogModule) Enable() error {
6767
}
6868

6969
// enable analog
70-
e = writeStringToFile(path, "cape-bone-iio")
70+
e = WriteStringToFile(path, "cape-bone-iio")
7171
if e != nil {
7272
return e
7373
}

module_dtgpio.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func (module *DTGPIOModule) makeOpenGPIOPin(pin Pin) (*DTGPIOModuleOpenPin, erro
161161
// Needs to be called to allocate the GPIO pin
162162
func (op *DTGPIOModuleOpenPin) gpioExport() error {
163163
s := strconv.FormatInt(int64(op.gpioLogical), 10)
164-
e := writeStringToFile("/sys/class/gpio/export", s)
164+
e := WriteStringToFile("/sys/class/gpio/export", s)
165165
if e != nil {
166166
return e
167167
}
@@ -174,7 +174,7 @@ func (op *DTGPIOModuleOpenPin) gpioExport() error {
174174
// Needs to be called to allocate the GPIO pin
175175
func (op *DTGPIOModuleOpenPin) gpioUnexport() error {
176176
s := strconv.FormatInt(int64(op.gpioLogical), 10)
177-
e := writeStringToFile("/sys/class/gpio/unexport", s)
177+
e := WriteStringToFile("/sys/class/gpio/unexport", s)
178178
if e != nil {
179179
return e
180180
}
@@ -188,7 +188,7 @@ func (op *DTGPIOModuleOpenPin) gpioDirection(dir string) error {
188188
return errors.New("direction must be in or out")
189189
}
190190
f := op.gpioBaseName + "/direction"
191-
e := writeStringToFile(f, dir)
191+
e := WriteStringToFile(f, dir)
192192

193193
mode := os.O_WRONLY | os.O_TRUNC
194194
if dir == "in" {

0 commit comments

Comments
 (0)