-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
342 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package kefw2 | ||
|
||
type EQProfileV2 struct { | ||
SubwooferCount int `json:"subwooferCount"` // 0, 1, 2 | ||
TrebleAmount float32 `json:"trebleAmount"` | ||
DeskMode bool `json:"deskMode"` | ||
BassExtension string `json:"bassExtension"` // less, standard, more | ||
HighPassMode bool `json:"highPassMode"` | ||
AudioPolarity string `json:"audioPolarity"` | ||
IsExpertMode bool `json:"isExpertMode"` | ||
DeskModeSetting int `json:"deskModeSetting"` | ||
SubwooferPreset string `json:"subwooferPreset"` | ||
HighPassModeFreq int `json:"highPassModeFreq"` | ||
WallModeSetting float32 `json:"wallModeSetting"` | ||
Balance int `json:"balance"` | ||
SubEnableStereo bool `json:"subEnableStereo"` | ||
SubwooferPolarity string `json:"subwooferPolarity"` | ||
SubwooferGain int `json:"subwooferGain"` | ||
IsKW1 bool `json:"isKW1"` | ||
PhaseCorrection bool `json:"phaseCorrection"` | ||
WallMode bool `json:"wallMode"` | ||
ProfileId string `json:"profileId"` | ||
ProfileName string `json:"profileName"` | ||
SubOutLPFreq float32 `json:"subOutLPFreq"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package kefw2 | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
) | ||
|
||
func JSONStringValue(data []byte, err error) (value string, err2 error) { | ||
if err != nil { | ||
return "", err | ||
} | ||
var jsonData []map[string]interface{} | ||
err2 = json.Unmarshal(data, &jsonData) | ||
if err2 != nil { | ||
return "", err | ||
} | ||
value = jsonData[0]["string_"].(string) | ||
return value, nil | ||
} | ||
|
||
func JSONStringValueByKey(data []byte, key string, err error) (value string, err2 error) { | ||
if err != nil { | ||
return "", err | ||
} | ||
var jsonData []map[string]string | ||
err2 = json.Unmarshal(data, &jsonData) | ||
if err2 != nil { | ||
return "", err | ||
} | ||
value = jsonData[0]["value"] | ||
return value, nil | ||
} | ||
|
||
func JSONIntValue(data []byte, err error) (value int, err2 error) { | ||
if err != nil { | ||
return 0, err | ||
} | ||
var jsonData []map[string]interface{} | ||
err2 = json.Unmarshal(data, &jsonData) | ||
if err2 != nil { | ||
return 0, err | ||
} | ||
fvalue, _ := jsonData[0]["i32_"].(float64) | ||
return int(fvalue), nil | ||
} | ||
|
||
func JSONUnmarshalValue(data []byte, err error) (value any, err2 error) { | ||
// Easing the call chain | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
// Unmarshal the JSON data into a map of strings to any | ||
var jsonData []map[string]any | ||
err2 = json.Unmarshal(data, &jsonData) | ||
if err2 != nil { | ||
return 0, err | ||
} | ||
// Locate the value and set the type | ||
tvalue := jsonData[0]["type"].(string) | ||
switch tvalue { | ||
case "i32_": | ||
value = jsonData[0]["i32_"].(int) | ||
case "i64_": | ||
value = jsonData[0]["i64_"].(int) | ||
case "string_": | ||
value = jsonData[0]["string_"].(string) | ||
case "bool_": | ||
value = jsonData[0]["bool_"].(bool) | ||
case "kefPhysicalSource": | ||
value = Source(jsonData[0]["kefPhysicalSource"].(string)) | ||
case "kefSpeakerStatus": | ||
value = SpeakerStatus(jsonData[0]["kefSpeakerStatus"].(string)) | ||
default: | ||
return nil, errors.New("Unknown type: " + tvalue) | ||
} | ||
return value, nil | ||
} |
Oops, something went wrong.