Skip to content
Merged
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
4 changes: 2 additions & 2 deletions pi5/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,9 +640,9 @@ func (b *pinctrlpi5) updateBTbaudrate(configPath string, rate int) (bool, bool)
}

func (b *pinctrlpi5) configureI2C(cfg *rpiutils.Config) {
b.logger.Debugf("cfg.BoardSettings.TurnI2COn=%v", cfg.BoardSettings.TurnI2COn)
b.logger.Debugf("cfg.BoardSettings.I2Cenable=%v", cfg.BoardSettings.I2Cenable)
// Only enable I2C if turn_i2c_on is true, otherwise do nothing
if !cfg.BoardSettings.TurnI2COn {
if !cfg.BoardSettings.I2Cenable {
return
}

Expand Down
6 changes: 3 additions & 3 deletions rpi/board.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ var (
)

var (
boardInstance *piPigpio // global instance of raspberry pi borad for interrupt callbacks
boardInstance *piPigpio // global instance of raspberry pi board for interrupt callbacks
boardInstanceMu sync.RWMutex // mutex to protect boardInstance
)

Expand Down Expand Up @@ -484,9 +484,9 @@ func (pi *piPigpio) updateBTbaudrate(configPath string, rate int) (bool, bool) {
}

func (pi *piPigpio) configureI2C(cfg *rpiutils.Config) error {
pi.logger.Debugf("cfg.BoardSettings.TurnI2COn=%v", cfg.BoardSettings.TurnI2COn)
pi.logger.Debugf("cfg.BoardSettings.I2Cenable=%v", cfg.BoardSettings.I2Cenable)
// Only enable I2C if turn_i2c_on is true, otherwise do nothing
if !cfg.BoardSettings.TurnI2COn {
if !cfg.BoardSettings.I2Cenable {
return nil
}

Expand Down
4 changes: 2 additions & 2 deletions utils/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ var RaspiFamily = resource.NewModelFamily("viam", "raspberry-pi")

// BoardSettings contains board-level configuration options.
type BoardSettings struct {
TurnI2COn bool `json:"turn_i2c_on,omitempty"`
I2Cenable bool `json:"enable_i2c,omitempty"`
BTenableuart *bool `json:"bluetooth_enable_uart,omitempty"`
BTdtoverlay *bool `json:"bluetooth_dtoverlay_miniuart,omitempty"`
BTkbaudrate *int `json:"bluetooth_baud_rate,omitempty"`
Expand All @@ -23,7 +23,7 @@ type BoardSettings struct {
type Config struct {
AnalogReaders []mcp3008helper.MCP3008AnalogConfig `json:"analogs,omitempty"`
Pins []PinConfig `json:"pins,omitempty"`
BoardSettings BoardSettings `json:"board_settings,omitempty"`
BoardSettings BoardSettings `json:"board_settings"`
}

// Validate ensures all parts of the config are valid.
Expand Down
28 changes: 14 additions & 14 deletions utils/file_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,49 +15,49 @@ func TestI2CConfiguration(t *testing.T) {

testCases := []struct {
name string
turnI2COn bool
i2cEnable bool
expectChange bool
initialConfig string
initialModule string
}{
{
name: "turn_on_from_scratch",
turnI2COn: true,
i2cEnable: true,
expectChange: true,
initialConfig: "",
initialModule: "",
},
{
name: "turn_on_already_enabled",
turnI2COn: true,
i2cEnable: true,
expectChange: false,
initialConfig: "dtparam=i2c_arm=on\n",
initialModule: "i2c-dev\n",
},
{
name: "turn_on_from_commented",
turnI2COn: true,
i2cEnable: true,
expectChange: true,
initialConfig: "#dtparam=i2c_arm=on\n",
initialModule: "#i2c-dev\n",
},
{
name: "false_does_nothing_empty",
turnI2COn: false,
i2cEnable: false,
expectChange: false,
initialConfig: "",
initialModule: "",
},
{
name: "false_does_nothing_enabled",
turnI2COn: false,
i2cEnable: false,
expectChange: false,
initialConfig: "dtparam=i2c_arm=on\n",
initialModule: "i2c-dev\n",
},
{
name: "false_does_nothing_disabled",
turnI2COn: false,
i2cEnable: false,
expectChange: false,
initialConfig: "dtparam=i2c_arm=off\n",
initialModule: "#i2c-dev\n",
Expand All @@ -81,7 +81,7 @@ func TestI2CConfiguration(t *testing.T) {
var configChanged, moduleChanged bool
var err error

if tc.turnI2COn {
if tc.i2cEnable {
configChanged, err = UpdateConfigFile(configPath, "dtparam=i2c_arm", "on", logger)
test.That(t, err, test.ShouldBeNil)

Expand Down Expand Up @@ -126,25 +126,25 @@ func TestI2CConfigIntegration(t *testing.T) {
expectCalls bool
}{
{
name: "turn_i2c_on_true",
name: "i2c_enable_true",
config: Config{
BoardSettings: BoardSettings{
TurnI2COn: true,
I2Cenable: true,
},
},
expectCalls: true,
},
{
name: "turn_i2c_on_false",
name: "i2c_enable_false",
config: Config{
BoardSettings: BoardSettings{
TurnI2COn: false,
I2Cenable: false,
},
},
expectCalls: false,
},
{
name: "turn_i2c_on_omitted",
name: "i2c_enable_omitted",
config: Config{
BoardSettings: BoardSettings{},
},
Expand All @@ -155,7 +155,7 @@ func TestI2CConfigIntegration(t *testing.T) {
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
// Test that the logic correctly interprets the config
shouldEnable := tc.config.BoardSettings.TurnI2COn
shouldEnable := tc.config.BoardSettings.I2Cenable
test.That(t, shouldEnable, test.ShouldEqual, tc.expectCalls)
})
}
Expand Down