Error handling was added

This commit is contained in:
2016-06-26 11:41:34 +05:00
parent b65825b367
commit f4aaee99fb

View File

@@ -131,46 +131,58 @@ func (n *NooliteAdapter) composeCommand(cmd command, channel int, args ...int) [
return c return c
} }
func (n *NooliteAdapter) sendCommand(command []byte) { func (n *NooliteAdapter) sendCommand(command []byte) error {
n.Configuration(1) n.Configuration(1)
if n.LastError() != "No error" {
return errors.New(n.LastError())
}
n.Interface(0) n.Interface(0)
if n.LastError() != "No error" {
return errors.New(n.LastError())
}
n.ControlMsg(0x21, 0x09, 0x300, 0, command) n.ControlMsg(0x21, 0x09, 0x300, 0, command)
if n.LastError() != "No error" {
return errors.New(n.LastError())
}
return nil
} }
// Turn power OFF for specified channel // Turn power OFF for specified channel
func (n *NooliteAdapter) Off(channel int) { func (n *NooliteAdapter) Off(channel int) error {
cmd := n.composeCommand(off, channel) cmd := n.composeCommand(off, channel)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Smooth brightnes decrase for specified channel // Smooth brightnes decrase for specified channel
func (n *NooliteAdapter) DecraseBrightnes(channel int) { func (n *NooliteAdapter) DecraseBrightnes(channel int) error {
cmd := n.composeCommand(decBrightnes, channel) cmd := n.composeCommand(decBrightnes, channel)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Turn power ON for specified channel // Turn power ON for specified channel
func (n *NooliteAdapter) On(channel int) { func (n *NooliteAdapter) On(channel int) error {
cmd := n.composeCommand(on, channel) cmd := n.composeCommand(on, channel)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Smooth brightnes incrase for specified channel // Smooth brightnes incrase for specified channel
func (n *NooliteAdapter) IncraseBrightnes(channel int) { func (n *NooliteAdapter) IncraseBrightnes(channel int) error {
cmd := n.composeCommand(incBrightnes, channel) cmd := n.composeCommand(incBrightnes, channel)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Switch power state between off and on for specified channel // Switch power state between off and on for specified channel
func (n *NooliteAdapter) Switch(channel int) { func (n *NooliteAdapter) Switch(channel int) error {
cmd := n.composeCommand(cSwitch, channel) cmd := n.composeCommand(cSwitch, channel)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Smooth brightnes incrase or decrase for specified channel // Smooth brightnes incrase or decrase for specified channel
func (n *NooliteAdapter) InvertBrightnes(channel int) { func (n *NooliteAdapter) InvertBrightnes(channel int) error {
cmd := n.composeCommand(invertBrightnes, channel) cmd := n.composeCommand(invertBrightnes, channel)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Set brightnes value for specified channel // Set brightnes value for specified channel
@@ -178,49 +190,49 @@ func (n *NooliteAdapter) InvertBrightnes(channel int) {
// Value must be in range 35..155. // Value must be in range 35..155.
// When value == 0 lights off. // When value == 0 lights off.
// When value > 155 lights on for full brightness. // When value > 155 lights on for full brightness.
func (n *NooliteAdapter) SetBrightnesValue(channel, value int) { func (n *NooliteAdapter) SetBrightnesValue(channel, value int) error {
cmd := n.composeCommand(set, channel, value) cmd := n.composeCommand(set, channel, value)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Set brightnes values for independens channels // Set brightnes values for independens channels
// //
// Available for SD111-180 only // Available for SD111-180 only
func (n *NooliteAdapter) SetBrightnesValues(channel, val1, val2, val3 int) { func (n *NooliteAdapter) SetBrightnesValues(channel, val1, val2, val3 int) error {
cmd := n.composeCommand(set, channel, val1, val2, val3) cmd := n.composeCommand(set, channel, val1, val2, val3)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Call scenario for specified channel // Call scenario for specified channel
func (n *NooliteAdapter) CallScenario(channel int) { func (n *NooliteAdapter) CallScenario(channel int) error {
cmd := n.composeCommand(callScenario, channel) cmd := n.composeCommand(callScenario, channel)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Save scenario for specified channel // Save scenario for specified channel
func (n *NooliteAdapter) SaveScenario(channel int) { func (n *NooliteAdapter) SaveScenario(channel int) error {
cmd := n.composeCommand(saveScenario, channel) cmd := n.composeCommand(saveScenario, channel)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Unbind signal for specified channel // Unbind signal for specified channel
func (n *NooliteAdapter) UnbindChannel(channel int) { func (n *NooliteAdapter) UnbindChannel(channel int) error {
cmd := n.composeCommand(unbind, channel) cmd := n.composeCommand(unbind, channel)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Stop color selection for specified channel // Stop color selection for specified channel
// //
// Available for SD111-180 only // Available for SD111-180 only
func (n *NooliteAdapter) StopColorSelection(channel int) { func (n *NooliteAdapter) StopColorSelection(channel int) error {
cmd := n.composeCommand(stopColorSelection, channel) cmd := n.composeCommand(stopColorSelection, channel)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Set binding for specified channel // Set binding for specified channel
func (n *NooliteAdapter) BindChannel(channel int) { func (n *NooliteAdapter) BindChannel(channel int) error {
cmd := n.composeCommand(bind, channel) cmd := n.composeCommand(bind, channel)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Smooth color changing for specified channel // Smooth color changing for specified channel
@@ -228,31 +240,31 @@ func (n *NooliteAdapter) BindChannel(channel int) {
// Stop with StopColorSelection method // Stop with StopColorSelection method
// //
// Avialable for SD111-180 only // Avialable for SD111-180 only
func (n *NooliteAdapter) ColorSelection(channel int) { func (n *NooliteAdapter) ColorSelection(channel int) error {
cmd := n.composeCommand(colorSelection, channel) cmd := n.composeCommand(colorSelection, channel)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Switch color for specified channel // Switch color for specified channel
// //
// Avialable for SD111-180 only // Avialable for SD111-180 only
func (n *NooliteAdapter) ColorSwitch(channel int) { func (n *NooliteAdapter) ColorSwitch(channel int) error {
cmd := n.composeCommand(colorSwitch, channel) cmd := n.composeCommand(colorSwitch, channel)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Switch work mode for specified channel // Switch work mode for specified channel
// //
// Avialable for SD111-180 only // Avialable for SD111-180 only
func (n *NooliteAdapter) ModeSwitch(channel int) { func (n *NooliteAdapter) ModeSwitch(channel int) error {
cmd := n.composeCommand(modeSwitch, channel) cmd := n.composeCommand(modeSwitch, channel)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }
// Set change color speed for specified channel // Set change color speed for specified channel
// //
// Avialable for SD111-180 only // Avialable for SD111-180 only
func (n *NooliteAdapter) EffectSpeed(channel int) { func (n *NooliteAdapter) EffectSpeed(channel int) error {
cmd := n.composeCommand(effectSpeed, channel) cmd := n.composeCommand(effectSpeed, channel)
n.sendCommand(cmd) return n.sendCommand(cmd)
} }