Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Info command to print GoPro settings #86

Open
wants to merge 13 commits into
base: development
Choose a base branch
from
Open
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
100 changes: 100 additions & 0 deletions cmd/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package cmd

import (
"fmt"

"github.com/erdaltsksn/cui"
"github.com/konradit/mmt/pkg/gopro"
"github.com/konradit/mmt/pkg/utils"
"github.com/spf13/cobra"
)

var infoCmd = &cobra.Command{
Use: "info",
Run: func(cmd *cobra.Command, args []string) {
input := getFlagString(cmd, "input")
camera := getFlagString(cmd, "camera")
customCameraOpts := make(map[string]interface{})
if useGoPro, err := cmd.Flags().GetBool("use_gopro"); err == nil && useGoPro {
detectedGoPro, connectionType, err := gopro.Detect()
if err != nil {
cui.Error(err.Error())
}
input = detectedGoPro
customCameraOpts["connection"] = string(connectionType)
camera = "gopro"
}
if camera != "" && input != "" {
c, err := utils.CameraGet(camera)
if err != nil {
cui.Error("Something went wrong", err)
}
switch c {
case utils.GoPro:
if customCameraOpts["connection"] == "" {
connection := getFlagString(cmd, "connection")
if connection == "" {
connection = "sd_card"
}
customCameraOpts["connection"] = connection
}
switch customCameraOpts["connection"] {
case "connect":
printGpStatus(input)
default:
gopro.GetFileInfo(input)
}
}
}
},
}

func printGpStatus(input string) {
var gpStatus = gopro.CameraStatus{}
gpStatus, _ = gopro.GetInfo(input)
fmt.Printf("SSID : %s\n", gpStatus.Status.WiFiSSID)
currentMode := gpStatus.Status.CurrentMode
var modeName = "Video"
var whiteBal = gpStatus.Settings.Num11
var isoMode = gpStatus.Settings.Num74
var isoLimit = gpStatus.Settings.Num13
var isoMin = 0
var proTune = gpStatus.Settings.Num10
switch currentMode {
case 1:
modeName = "Photo"
whiteBal = gpStatus.Settings.Num22
isoMin = gpStatus.Settings.Num75
isoLimit = gpStatus.Settings.Num24
proTune = gpStatus.Settings.Num21
case 2:
modeName = "MultiShot"
whiteBal = gpStatus.Settings.Num35
isoMin = gpStatus.Settings.Num76
isoLimit = gpStatus.Settings.Num37
proTune = gpStatus.Settings.Num34
}
fmt.Printf("Mode : %s\n", modeName)
fmt.Printf("White Balance : %s\n", gopro.GetWhiteBalance(whiteBal))
if currentMode == 0 {
fmt.Printf("Resolution : %s\n", gopro.GetVidRes(gpStatus.Settings.VideoResolutions))
var isoText = ""
if isoMode == 1 {
isoText = "Lock"
} else {
isoText = "Max"
}
fmt.Printf("ISO Mode : %s\n", isoText)
} else {
fmt.Printf("ISO Min : %d\n", gopro.GetISO(isoMin))
}
fmt.Printf("ISO Limit : %d\n", gopro.GetISO(isoLimit))
fmt.Printf("Protune : %t\n", proTune != 0)
}

func init() {
rootCmd.AddCommand(infoCmd)
infoCmd.Flags().StringP("input", "i", "", "Input IP Address")
infoCmd.Flags().StringP("camera", "c", "", "Camera type")
infoCmd.Flags().StringP("connection", "x", "", "Connexion type: `sd_card`, `connect` (GoPro-specific)")
}
96 changes: 96 additions & 0 deletions pkg/gopro/info.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package gopro

/* GoPro Connect - API exposed over USB Ethernet */

import (
"fmt"

"github.com/konradit/mmt/pkg/utils"
)

func GetInfo(in string) (CameraStatus, error) {
var gpStatus = &CameraStatus{}
err := caller(in, "gp/gpControl/status", gpStatus)
if err != nil {
return *gpStatus, err
}
return *gpStatus, nil
}
Comment on lines +11 to +18
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

better to:

return nil, err

and have CameraStatus be a pointer


func GetISO(in int) int {
switch in {
Comment on lines +20 to +21
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private

case 0:
return 800
case 1:
return 400
case 2:
return 200
case 3:
return 100
default:
return 0
}
}

func GetVidRes(in int) string {
switch in {
Comment on lines +34 to +36
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also needs more resolutions, 5k, 5k 4:3, etc...

case 1:
return "4K"
case 2:
return "4K SuperView"
case 4:
return "2.7K"
case 5:
return "2.7K SuperView"
case 6:
return "2.7K 4:3"
case 7:
return "1440"
case 8:
return "1080 SuperView"
case 9:
return "1080"
case 10:
return "960"
case 11:
return "720 SuperView"
case 12:
return "720"
case 13:
return "WVGA"
default:
return ""
}
}

func GetWhiteBalance(in int) string {
switch in {
Comment on lines +65 to +67
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

private.

Not sure if hardcoding these values is the way to go, especially when we have that stuff on /gp/gpControl manifest. Better to parse the manifest and build functions / maps from it

case 0:
return "Auto"
case 1:
return "3000K"
case 5:
return "4000K"
case 6:
return "4800K"
case 2:
return "5500K"
case 7:
return "6000K"
case 3:
return "6500K"
case 4:
return "Native"
default:
return ""
}
}

func GetFileInfo(in string) (*utils.Result, error) {
var result utils.Result
returned, err := fromMP4(in)
if returned != nil {
fmt.Printf("\n\treturned: %f %f\n", returned.Latitude, returned.Longitude)
}
return &result, err
}
Loading