Skip to content

Commit

Permalink
Make Offset type private
Browse files Browse the repository at this point in the history
  • Loading branch information
z-riley committed Oct 28, 2024
1 parent 8e123b6 commit b0dd501
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 51 deletions.
8 changes: 4 additions & 4 deletions tic/registers.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// getVar8 reads an 8 bit value from the Tic at a given register offset.
func (d *Dev) getVar8(offset Offset) (uint8, error) {
func (d *Dev) getVar8(offset offset) (uint8, error) {
const length = 1
buffer, err := d.getSegment(cmdGetVariable, offset, length)
if err != nil {
Expand All @@ -20,7 +20,7 @@ func (d *Dev) getVar8(offset Offset) (uint8, error) {
}

// getVar16 reads a 16 bit value from the Tic at a given register offset.
func (d *Dev) getVar16(offset Offset) (uint16, error) {
func (d *Dev) getVar16(offset offset) (uint16, error) {
const length = 2
buffer, err := d.getSegment(cmdGetVariable, offset, length)
if err != nil {
Expand All @@ -31,7 +31,7 @@ func (d *Dev) getVar16(offset Offset) (uint16, error) {
}

// getVar32 reads a 32 bit value from the Tic at a given register offset.
func (d *Dev) getVar32(offset Offset) (uint32, error) {
func (d *Dev) getVar32(offset offset) (uint32, error) {
const length = 4
buffer, err := d.getSegment(cmdGetVariable, offset, length)
if err != nil {
Expand Down Expand Up @@ -67,7 +67,7 @@ func (d *Dev) commandW32(cmd command, val uint32) error {

// getSegment sends a command and receives "length" bytes back.
func (d *Dev) getSegment(
cmd command, offset Offset, length uint,
cmd command, offset offset, length uint,
) ([]byte, error) {
// Transmit command and offset value
writeBuf := [2]byte{byte(cmd), byte(offset)}
Expand Down
8 changes: 4 additions & 4 deletions tic/registers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
func TestGetVar8(t *testing.T) {
for _, test := range []struct {
name string
offset Offset
offset offset
ops []i2ctest.IO
want uint8
expectErr bool
Expand Down Expand Up @@ -72,7 +72,7 @@ func TestGetVar8(t *testing.T) {
func TestGetVar16(t *testing.T) {
for _, test := range []struct {
name string
offset Offset
offset offset
ops []i2ctest.IO
want uint16
expectErr bool
Expand Down Expand Up @@ -129,7 +129,7 @@ func TestGetVar16(t *testing.T) {
func TestGetVar32(t *testing.T) {
for _, test := range []struct {
name string
offset Offset
offset offset
ops []i2ctest.IO
want uint32
expectErr bool
Expand Down Expand Up @@ -276,7 +276,7 @@ func TestGetSegment(t *testing.T) {
for _, test := range []struct {
name string
cmd command
offset Offset
offset offset
length uint
want []uint8
ops []i2ctest.IO
Expand Down
86 changes: 43 additions & 43 deletions tic/tic.go
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ const (
// // The reading is less than about 2.4 V.
// }
func (d *Dev) GetAnalogReading(pin Pin) (uint16, error) {
offset := OffsetAnalogReadingSCL + 2*Offset(pin)
offset := OffsetAnalogReadingSCL + 2*offset(pin)

Check failure on line 1110 in tic/tic.go

View workflow job for this annotation

GitHub Actions / lint: ubuntu-latest

declaration of "offset" shadows declaration at line 1265

Check failure on line 1110 in tic/tic.go

View workflow job for this annotation

GitHub Actions / lint: macos-latest

declaration of "offset" shadows declaration at line 1265

Check failure on line 1110 in tic/tic.go

View workflow job for this annotation

GitHub Actions / lint: windows-latest

declaration of "offset" shadows declaration at line 1265
return d.getVar16(offset)

Check warning on line 1111 in tic/tic.go

View check run for this annotation

Codecov / codecov/patch

tic/tic.go#L1109-L1111

Added lines #L1109 - L1111 were not covered by tests
}

Expand Down Expand Up @@ -1252,58 +1252,58 @@ func (d *Dev) GetLastHPDriverErrors() (uint8, error) {
// This library does not attempt to interpret the settings and say what they
// mean. If you are interested in how the settings are encoded in the Tic's
// EEPROM, see the "Settings reference" section of the Tic user's guide.
func (d *Dev) GetSetting(offset Offset, length uint) ([]uint8, error) {
func (d *Dev) GetSetting(offset offset, length uint) ([]uint8, error) {
if length > 15 {
return nil, errors.New("maximum length exceeded")
}

Check warning on line 1258 in tic/tic.go

View check run for this annotation

Codecov / codecov/patch

tic/tic.go#L1255-L1258

Added lines #L1255 - L1258 were not covered by tests

return d.getSegment(cmdGetSetting, offset, length)

Check warning on line 1260 in tic/tic.go

View check run for this annotation

Codecov / codecov/patch

tic/tic.go#L1260

Added line #L1260 was not covered by tests
}

// Offset represents where settings are stored in the Tic's EEPROM memory. See
// offset represents where settings are stored in the Tic's EEPROM memory. See
// the "Variable reference" section of the Tic user's guide for details.
type Offset uint8
type offset uint8

const (
OffsetOperationState Offset = 0x00 // uint8 return type
OffsetMiscFlags1 Offset = 0x01 // uint8 return type
OffsetErrorStatus Offset = 0x02 // uint16 return type
OffsetErrorsOccurred Offset = 0x04 // uint32 return type
OffsetPlanningMode Offset = 0x09 // uint8 return type
OffsetTargetPosition Offset = 0x0A // int32 return type
OffsetTargetVelocity Offset = 0x0E // int32 return type
OffsetStartingSpeed Offset = 0x12 // uint32 return type
OffsetSpeedMax Offset = 0x16 // uint32 return type
OffsetDecelMax Offset = 0x1A // uint32 return type
OffsetAccelMax Offset = 0x1E // uint32 return type
OffsetCurrentPosition Offset = 0x22 // int32 return type
OffsetCurrentVelocity Offset = 0x26 // int32 return type
OffsetActingTargetPosition Offset = 0x2A // int32 return type
OffsetTimeSinceLastStep Offset = 0x2E // uint32 return type
OffsetDeviceReset Offset = 0x32 // uint8 return type
OffsetVoltageIn Offset = 0x33 // uint16 return type
OffsetUpTime Offset = 0x35 // uint32 return type
OffsetEncoderPosition Offset = 0x39 // int32 return type
OffsetRCPulseWidth Offset = 0x3D // uint16 return type
OffsetAnalogReadingSCL Offset = 0x3F // uint16 return type
OffsetAnalogReadingSDA Offset = 0x41 // uint16 return type
OffsetAnalogReadingTX Offset = 0x43 // uint16 return type
OffsetAnalogReadingRX Offset = 0x45 // uint16 return type
OffsetDigitalReadings Offset = 0x47 // uint8 return type
OffsetPinStates Offset = 0x48 // uint8 return type
OffsetStepMode Offset = 0x49 // uint8 return type
OffsetCurrentLimit Offset = 0x4A // uint8 return type
OffsetDecayMode Offset = 0x4B // uint8 return type
OffsetInputState Offset = 0x4C // uint8 return type
OffsetInputAfterAveraging Offset = 0x4D // uint16 return type
OffsetInputAfterHysteresis Offset = 0x4F // uint16 return type
OffsetInputAfterScaling Offset = 0x51 // uint16 return type
OffsetLastMotorDriverError Offset = 0x55 // uint8 return type
OffsetAGCMode Offset = 0x56 // uint8 return type
OffsetAGCBottomCurrentLimit Offset = 0x57 // uint8 return type
OffsetAGCCurrentBoostSteps Offset = 0x58 // uint8 return type
OffsetAGCFrequencyLimit Offset = 0x59 // uint8 return type
OffsetLastHPDriverErrors Offset = 0xFF // uint8 return type
OffsetOperationState offset = 0x00 // uint8 return type
OffsetMiscFlags1 offset = 0x01 // uint8 return type
OffsetErrorStatus offset = 0x02 // uint16 return type
OffsetErrorsOccurred offset = 0x04 // uint32 return type
OffsetPlanningMode offset = 0x09 // uint8 return type
OffsetTargetPosition offset = 0x0A // int32 return type
OffsetTargetVelocity offset = 0x0E // int32 return type
OffsetStartingSpeed offset = 0x12 // uint32 return type
OffsetSpeedMax offset = 0x16 // uint32 return type
OffsetDecelMax offset = 0x1A // uint32 return type
OffsetAccelMax offset = 0x1E // uint32 return type
OffsetCurrentPosition offset = 0x22 // int32 return type
OffsetCurrentVelocity offset = 0x26 // int32 return type
OffsetActingTargetPosition offset = 0x2A // int32 return type
OffsetTimeSinceLastStep offset = 0x2E // uint32 return type
OffsetDeviceReset offset = 0x32 // uint8 return type
OffsetVoltageIn offset = 0x33 // uint16 return type
OffsetUpTime offset = 0x35 // uint32 return type
OffsetEncoderPosition offset = 0x39 // int32 return type
OffsetRCPulseWidth offset = 0x3D // uint16 return type
OffsetAnalogReadingSCL offset = 0x3F // uint16 return type
OffsetAnalogReadingSDA offset = 0x41 // uint16 return type
OffsetAnalogReadingTX offset = 0x43 // uint16 return type
OffsetAnalogReadingRX offset = 0x45 // uint16 return type
OffsetDigitalReadings offset = 0x47 // uint8 return type
OffsetPinStates offset = 0x48 // uint8 return type
OffsetStepMode offset = 0x49 // uint8 return type
OffsetCurrentLimit offset = 0x4A // uint8 return type
OffsetDecayMode offset = 0x4B // uint8 return type
OffsetInputState offset = 0x4C // uint8 return type
OffsetInputAfterAveraging offset = 0x4D // uint16 return type
OffsetInputAfterHysteresis offset = 0x4F // uint16 return type
OffsetInputAfterScaling offset = 0x51 // uint16 return type
OffsetLastMotorDriverError offset = 0x55 // uint8 return type
OffsetAGCMode offset = 0x56 // uint8 return type
OffsetAGCBottomCurrentLimit offset = 0x57 // uint8 return type
OffsetAGCCurrentBoostSteps offset = 0x58 // uint8 return type
OffsetAGCFrequencyLimit offset = 0x59 // uint8 return type
OffsetLastHPDriverErrors offset = 0xFF // uint8 return type
)

// command represents Tic command codes which are used for its I²C interface.
Expand Down

0 comments on commit b0dd501

Please sign in to comment.