Commit 28724946 authored by Sli's avatar Sli

Minimal support for AZERTY, usable for UIDs

parent db59f96f
Pipeline #1753 canceled with stages
......@@ -11,6 +11,8 @@ const (
CharFlagSemiColon
CharFlagColon
CharFlagComma
LayoutFlagEN
LayoutFlagFR
)
type CharFlagDef struct {
......@@ -18,6 +20,11 @@ type CharFlagDef struct {
output string
}
var layoutFlagStrings = map[CharFlag]CharFlagDef{
LayoutFlagEN: CharFlagDef{"en", "en"},
LayoutFlagFR: CharFlagDef{"fr", "fr"},
}
var charFlagStrings = map[CharFlag]CharFlagDef{
CharFlagNone: CharFlagDef{"none", ""},
CharFlagSpace: CharFlagDef{"space", " "},
......@@ -29,8 +36,8 @@ var charFlagStrings = map[CharFlag]CharFlagDef{
CharFlagComma: CharFlagDef{"comma", ","},
}
func StringToCharFlag(s string) (CharFlag, bool) {
for k, v := range charFlagStrings {
func stringToFlag(s string, flags map[CharFlag]CharFlagDef) (CharFlag, bool) {
for k, v := range flags {
if v.name == s {
return k, true
}
......@@ -38,6 +45,14 @@ func StringToCharFlag(s string) (CharFlag, bool) {
return 0, false
}
func StringToLayoutFlag(s string) (CharFlag, bool) {
return stringToFlag(s, layoutFlagStrings)
}
func StringToCharFlag(s string) (CharFlag, bool) {
return stringToFlag(s, charFlagStrings)
}
func (charFlag CharFlag) Name() string {
return charFlagStrings[charFlag].name
}
......@@ -46,10 +61,18 @@ func (charFlag CharFlag) Output() string {
return charFlagStrings[charFlag].output
}
func CharFlagOptions() string {
func flagOptions(flags map[CharFlag]CharFlagDef) string {
var s string
for _, v := range charFlagStrings {
for _, v := range flags {
s = s + "'" + v.name + "', "
}
return s
}
func LayoutFlagOptions() string {
return flagOptions(layoutFlagStrings)
}
func CharFlagOptions() string {
return flagOptions(charFlagStrings)
}
......@@ -7,11 +7,12 @@ import (
func main() {
var appFlags Flags
var endChar, inChar string
var endChar, inChar, layout string
var ok bool
//Read application flags
flag.StringVar(&endChar, "end-char", "none", "Character at the end of UID. Options: "+CharFlagOptions())
flag.StringVar(&inChar, "in-char", "none", "Сharacter between bytes of UID. Options: "+CharFlagOptions())
flag.StringVar(&layout, "layout", "en", "Keyboard layout to use. Options: "+LayoutFlagOptions())
flag.BoolVar(&appFlags.CapsLock, "caps-lock", false, "UID with Caps Lock")
flag.BoolVar(&appFlags.Reverse, "reverse", false, "UID reverse order")
flag.BoolVar(&appFlags.Decimal, "decimal", false, "UID in decimal format")
......@@ -29,6 +30,11 @@ func main() {
errorExit(errors.New("Unknown in character flag. Run with '-h' flag to check options"))
return
}
appFlags.Layout, ok = StringToLayoutFlag(layout)
if !ok {
errorExit(errors.New("Unknown in character flag. Run with '-h' flag to check options"))
return
}
service := NewService(appFlags)
service.Start()
......
......@@ -10,8 +10,8 @@ import (
"strconv"
"strings"
"ae-dev.utbm.fr/sli/string2keyboard"
"github.com/ebfe/scard"
"github.com/taglme/string2keyboard"
)
type Service interface {
......@@ -29,6 +29,7 @@ type Flags struct {
Decimal bool
EndChar CharFlag
InChar CharFlag
Layout CharFlag
Device int
}
......@@ -140,7 +141,7 @@ func (s *service) Start() {
uidBytes := rsp[0 : len(rsp)-2]
fmt.Printf("UID is: % x\n", uidBytes)
fmt.Printf("Writting as keyboard input...")
err = string2keyboard.KeyboardWrite(s.formatOutput(uidBytes))
err = string2keyboard.KeyboardWrite(s.formatOutput(uidBytes), s.flags.Layout.Name())
if err != nil {
fmt.Printf("Could write as keyboard output. Error: %s\n", err.Error())
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment