olup / kobowriter

A simple typewriter written in go for KOBO e-readers
315 stars 14 forks source link

problem building kobowriter #18

Open cittadhammo opened 5 months ago

cittadhammo commented 5 months ago

Dear @olup,

I finally put my hand on a machine where I was able to install Linux.

I have successfully built the KOReader Cross Compile ToolChains , by running the gen-tc.sh file, which took more than 2 hours:

[INFO ]  Build completed at 20240118.201720
[INFO ]  (elapsed: 131:19.72)
[INFO ]  Finishing installation (may take a few seconds)...
[131:21] / 
[INFO ]  =================================================================
[INFO ]  Build done. Please add /home/user/x-tools/arm-kobo-linux-gnueabihf/bin to your PATH.
[INFO ]  =================================================================
~/Downloads/kobowriter-main/build ~/Downloads/kobowriter-main
~/Downloads/kobowriter-main
[INFO ]  =================================================================
[INFO ]  The x-compile.sh script can do that (and more) for you:
[INFO ]  * If you need a persistent custom sysroot (e.g., if you intend to build a full dependency chain)
[INFO ]    > source /home/user/Downloads/kobowriter-main/refs/x-compile.sh kobo env
[INFO ]  * If you just need a compiler:
[INFO ]    > source /home/user/Downloads/kobowriter-main/refs/x-compile.sh kobo env bare

I have run the:

source /home/user/Downloads/kobowriter-main/refs/x-compile.sh kobo env bare
* Setting environment up . . .

* Environment has been set up for the KOBO TC, enjoy :)
* Not using our custom sysroot! :)

to set up the environment.

After installing golang-go via apt, when I run the make file, I have the following error:

make
CGO_ENABLED=1 GOARCH=arm GOOS=linux CC=arm-kobo-linux-gnueabihf-gcc CXX=arm-kobo-linux-gnueabihf-g++ go build -o ./build/kobowriter
go: downloading github.com/MarinX/keylogger v0.0.0-20210528193429-a54d7834cc1a
go: downloading github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef
go: downloading github.com/fogleman/gg v1.3.0
go: downloading github.com/shermp/go-fbink-v2 v1.20.2
go: downloading github.com/matoous/go-nanoid/v2 v2.0.0
go: downloading github.com/matoous/go-nanoid v1.5.0
go: downloading github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
go: downloading github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0
go: downloading golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d
# github.com/olup/kobowriter/screener
screener/screen.go:90:9: too many arguments in call to fb.ClearScreen
    have (*gofbink.FBInkConfig, *gofbink.FBInkRect)
    want (*gofbink.FBInkConfig)
screener/screen.go:125:25: not enough arguments in call to fb.Refresh
    have (number, number, number, number, *gofbink.FBInkConfig)
    want (uint32, uint32, uint32, uint32, gofbink.HWDither, *gofbink.FBInkConfig)
screener/screen.go:161:43: too many arguments in call to s.fb.ClearScreen
    have (*gofbink.FBInkConfig, *gofbink.FBInkRect)
    want (*gofbink.FBInkConfig)
screener/screen.go:166:59: too many arguments in call to s.fb.ClearScreen
    have (*gofbink.FBInkConfig, *gofbink.FBInkRect)
    want (*gofbink.FBInkConfig)
make: *** [Makefile:3: build] Error 2

I can try to correct these small errors in the code, but I am wondering if I am not doing something else wrong.

Thank you.

cittadhammo commented 5 months ago

yes ! it works !!!

I fixed the screen.go file with the help of phind.com and getting rid of the 4 errors. The replacement screener/screen.go file is :

package screener

import (
    "bytes"
    "image"
    "math"

    "github.com/fogleman/gg"
    "github.com/olup/kobowriter/matrix"
    "github.com/shermp/go-fbink-v2/gofbink"
)

type Screen struct {
    originalMatrix matrix.Matrix
    presentMatrix  matrix.Matrix
    fb             *gofbink.FBInk
    state          gofbink.FBInkState
    Width          int
    Height         int
    fontType       string
    ttSize         int
}

var dc = gg.NewContext(25, 40)
var charCache = map[string][]byte{}

func InitScreen() (s *Screen) {
    s = &Screen{}
    s.fontType = "bitmap"

    s.state = gofbink.FBInkState{}

    fbinkOpts := gofbink.FBInkConfig{}
    rOpts := gofbink.RestrictedConfig{
        Fontmult: 3,
        Fontname: gofbink.Ctrld,
    }
    s.fb = gofbink.New(&fbinkOpts, &rOpts)

    s.fb.Open()
    s.fb.Init(&fbinkOpts)
    s.fb.AddOTfont("/mnt/onboard/.adds/kobowriter/inc.ttf", gofbink.FntRegular)

    s.fb.GetState(&fbinkOpts, &s.state)

    // clear screen on initialisation
    s.ClearFlash()

    if s.fontType == "truetype" {
        dc.LoadFontFace("inc.ttf", 96)
        s.ttSize = 40
        s.Width = int(s.state.ScreenWidth) / ((s.ttSize / 5) * 3)
        s.Height = int(s.state.ScreenHeight) / s.ttSize
    } else {
        s.Width = int(s.state.MaxCols)
        s.Height = int(s.state.MaxRows)
    }

    s.presentMatrix = matrix.CreateNewMatrix(s.Width, s.Height)
    s.originalMatrix = matrix.CreateNewMatrix(s.Width, s.Height)

    println("Screen struct inited")

    return

}

func (s *Screen) Clean() {
    s.fb.Close()
}

func (s *Screen) Print(matrix matrix.Matrix) {
    printDiff(s.presentMatrix, matrix, s.fb, s.fontType, s.ttSize)
    s.presentMatrix = matrix
}

func same(a matrix.MatrixElement, b matrix.MatrixElement) bool {
    return a.Content == b.Content && a.IsInverted == b.IsInverted
}

func printDiff(previous matrix.Matrix, next matrix.Matrix, fb *gofbink.FBInk, fontType string, ttSize int) {
    for i := range previous {
        for j := range previous[i] {
            if !same(previous[i][j], next[i][j]) {
                if fontType == "truetype" {
                    ttWidth := ((ttSize / 5) * 3)
                    fb.ClearScreen(&gofbink.FBInkConfig{
                        IsInverted: next[i][j].IsInverted,
                        NoRefresh:  true,
                    })

                    fb.PrintOT(string(next[i][j].Content), &gofbink.FBInkOTConfig{
                        Margins: struct {
                            Top    int16
                            Bottom int16
                            Left   int16
                            Right  int16
                        }{
                            Top:  int16(i * ttSize),
                            Left: int16(j * ttWidth),
                        },
                        SizePx:      uint16(ttSize),
                        IsFormatted: false,
                    }, &gofbink.FBInkConfig{IsInverted: next[i][j].IsInverted, NoRefresh: true})

                } else {
                    fb.FBprint(string(next[i][j].Content), &gofbink.FBInkConfig{
                        Row:        int16(i),
                        Col:        int16(j),
                        NoRefresh:  true,
                        IsInverted: next[i][j].IsInverted,
                    })
                }

            }

        }
    }

    fb.Refresh(0, 0, 0, 0, gofbink.DitherFloydSteingberg ,&gofbink.FBInkConfig{})
}

func (s *Screen) PrintPng(imgBytes []byte, w int, h int, x int, y int) {
    img, _, _ := image.Decode(bytes.NewReader(imgBytes))
    buffer, _ := getPixelsFromImage(img)
    s.fb.PrintRawData(buffer, w, h, uint16(x), uint16(y), &gofbink.FBInkConfig{})
}

func getCharImage(s string) []byte {
    if char, ok := charCache[s]; ok {
        return char
    } else {
        dc.SetRGB(1, 1, 1)
        dc.Clear()

        dc.SetRGB(0, 0, 0)
        dc.DrawString(s, 0, 35)
        img := dc.Image()
        buffer, _ := getPixelsFromImage(img)
        charCache[s] = buffer
        return buffer
    }
}

func (s *Screen) PrintAlert(message string, width int) {
    thisMatrix := matrix.CreateMatrixFromText(message, width)
    x := math.Floor((float64(s.state.MaxCols)/2)-float64(width)/2) - 1
    y := math.Floor((float64(s.state.MaxRows)/2)-float64(len(thisMatrix))/2) - 1
    outerMatrix := matrix.CreateNewMatrix(width+2, len(thisMatrix)+2)
    thisMatrix = matrix.PasteMatrix(outerMatrix, thisMatrix, 1, 1)
    thisMatrix = matrix.InverseMatrix(thisMatrix)
    s.Print(matrix.PasteMatrix(s.originalMatrix, thisMatrix, int(x), int(y)))
}

func (s *Screen) Clear() {
    s.fb.ClearScreen(&gofbink.FBInkConfig{})
    s.presentMatrix = matrix.FillMatrix(s.presentMatrix, ' ')
}

func (s *Screen) ClearFlash() {
    s.fb.ClearScreen(&gofbink.FBInkConfig{IsFlashing: true})
    s.presentMatrix = matrix.FillMatrix(s.presentMatrix, ' ')
}

func (s *Screen) RefreshFlash() {
    presenMatrix := s.presentMatrix
    s.ClearFlash()
    s.Print(presenMatrix)
}

func (s *Screen) GetOriginalMatrix() matrix.Matrix {
    return matrix.CopyMatrix(s.originalMatrix)
}

and then the kobowriter file gets created in the build folder and you just need to replace it with the one in .adds/kobowriter/ ;-)

I need to tweek my keyboard key layout, but it is good to have a qwerty !

PS:

cittadhammo commented 5 months ago

my final CSA keybinding layout for reference (most comments made by AI are not accurate) :

//CSAkeybindings

package event

var KeyCode = map[int]string{
    0: "KEY_RESERVED",
    1: "KEY_ESC",

    2:  "1", // CSA: "&" is replaced with "1"
    3:  "2", // CSA: "é" is replaced with "2"
    4:  "3", // CSA: "\"" is replaced with "3"
    5:  "4", // CSA: "'" is replaced with "4"
    6:  "5", // CSA: "(" is replaced with "5"
    7:  "6", // CSA: "-" is replaced with "6"
    8:  "7", // CSA: "è" is replaced with "7"
    9:  "8", // CSA: "_" is replaced with "8"
    10: "9", // CSA: "ç" is replaced with "9"
    11: "0", // CSA: "à" is replaced with "0"
    12: "-", // CSA: ")" is replaced with "-"
    13: "=", // CSA: "=" stays "="

    14: "KEY_BACKSPACE",
    15: "KEY_TAB",

    16: "q", // CSA: "a" is replaced with "q"
    17: "w", // CSA: "z" is replaced with "w"
    18: "e", // CSA: "e" stays "e"
    19: "r", // CSA: "r" stays "r"
    20: "t", // CSA: "t" stays "t"
    21: "y", // CSA: "y" stays "y"
    22: "u", // CSA: "u" stays "u"
    23: "i", // CSA: "i" stays "i"
    24: "o", // CSA: "o" stays "o"
    25: "p", // CSA: "p" stays "p"
    26: "^", // CSA: "^" is replaced with "["
    27: "ç", // CSA: "$" is replaced with "]"
    28: "KEY_ENTER",
    29: "KEY_L_CTRL",

    30: "a", // CSA: "q" is replaced with "a"
    31: "s", // CSA: "s" stays "s"
    32: "d", // CSA: "d" stays "d"
    33: "f", // CSA: "f" stays "f"
    34: "g", // CSA: "g" stays "g"
    35: "h", // CSA: "h" stays "h"
    36: "j", // CSA: "j" stays "j"
    37: "k", // CSA: "k" stays "k"
    38: "l", // CSA: "l" stays "l"
    39: ";", // CSA: "m" is replaced with ";"
    40: "è", // CSA: "ù" is replaced with "'"
    41: "ù", // CSA: "*" is replaced with "`" // seems to be dead on hp keyboard

    // 41 seems to be reverse with 43 on my hp keyboard

    42: "KEY_L_SHIFT",
    43: "à", // CSA: "<" is replaced with "\"
    44: "z", // CSA: "w" is replaced with "z"
    45: "x", // CSA: "x" stays "x"
    46: "c", // CSA: "c" stays "c"
    47: "v", // CSA: "v" stays "v"
    48: "b", // CSA: "b" stays "b"
    49: "n", // CSA: "n" stays "n"
    50: "m", // CSA: "," stays ","
    51: ",", // CSA: ";" is replaced with "."
    52: ".", // CSA: ":" is replaced with "/"
    53: "é", // CSA: "!" is replaced with "KEY_R_SHIFT"

    55: "KEY_KPASTERISK",
    56: "KEY_L_ALT",

    57: "KEY_SPACE",
    58: "KEY_CAPSLOCK",
    59: "KEY_F1",
    60: "KEY_F2",
    61: "KEY_F3",
    62: "KEY_F4",
    63: "KEY_F5",
    64: "KEY_F6",
    65: "KEY_F7",
    66: "KEY_F8",
    67: "KEY_F9",
    68: "KEY_F10",

    87: "KEY_F11",
    88: "KEY_F12",

    100: "KEY_ALT_GR",

    103: "KEY_UP",
    105: "KEY_LEFT",
    106: "KEY_RIGHT",
    108: "KEY_DOWN",

    111: "KEY_DEL",

    183: "KEY_F13",
    184: "KEY_F14",
    185: "KEY_F15",
    186: "KEY_F16",
    187: "KEY_F17",
    188: "KEY_F18",
    189: "KEY_F19",
    190: "KEY_F20",
    191: "KEY_F21",
    192: "KEY_F22",
    193: "KEY_F23",
    194: "KEY_F24",
}

var KeyCodeMaj = map[int]string{
    2:  "!",
    3:  "\"",
    4:  "#",
    5:  "$",
    6:  "%",
    7:  "?",
    8:  "&",
    9:  "*",
    10: "(",
    11: ")",
    12: "_",
    13: "+",

    16: "Q",
    17: "W",
    18: "E",
    19: "R",
    20: "T",
    21: "Y",
    22: "U",
    23: "I",
    24: "O",
    25: "P",
    26: "^",
    27: "Ç",

    30: "A",
    31: "S",
    32: "D",
    33: "F",
    34: "G",
    35: "H",
    36: "J",
    37: "K",
    38: "L",
    39: ":",
    40: "È",
    41: "Ù",

    43: "À",
    44: "Z",
    45: "X",
    46: "C",
    47: "V",
    48: "B",
    49: "N",
    50: "M",
    51: "'",
    52: ".",
    53: "É",
}

var KeyCodeAlt = map[int]string{
    1:  "\\",
    2:  "¹",
    3:  "@",
    4:  "³",
    5:  "¼",
    6:  "½",
    7:  "¾",
    8:  "{",
    9:  "[",
    10: "]",
    11: "}",
    12: "|",
    13: "¸",

    16: "q",
    17: "w",
    18: "e",
    19: "¶",
    20: "t",
    21: "¥",
    22: "u",
    23: "i",
    24: "ø",
    25: "þ",
    26: "°",
    27: "",

    30: "æ", // CSA: "q" is replaced with "a"
    31: "ß", // CSA: "s" stays "s"
    32: "ð", // CSA: "d" stays "d"
    33: "ª", // CSA: "f" stays "f"
    34: "g", // CSA: "g" stays "g"
    35: "h", // CSA: "h" stays "h"
    36: "j", // CSA: "j" stays "j"
    37: "k", // CSA: "k" stays "k"
    38: "l", // CSA: "l" stays "l"
    39: "´", // CSA: "m" is replaced with ";"
    40: "{", // CSA: "ù" is replaced with "'"
    41: "¬", // CSA: "*" is replaced with "`"

    43: "`", // CSA: "<" is replaced with "\"
    44: "«", // CSA: "w" is replaced with "z"
    45: "»", // CSA: "x" stays "x"
    46: "¢", // CSA: "c" stays "c"
    47: "v", // CSA: "v" stays "v"
    48: "b", // CSA: "b" stays "b"
    49: "n", // CSA: "n" stays "n"
    50: "µ", // CSA: "," stays ","
    51: "<", // CSA: ";" is replaced with "."
    52: ">", // CSA: ":" is replaced with "/"
    53: "//", // CSA: "!" is replaced with "KEY_R_SHIFT"

}

var KeyCodeAltGr = map[int]string{
    1:  "\\",
    2:  "¹",
    3:  "@",
    4:  "³",
    5:  "¼",
    6:  "½",
    7:  "¾",
    8:  "{",
    9:  "[",
    10: "]",
    11: "}",
    12: "|",
    13: "¸",

    16: "q",
    17: "w",
    18: "e",
    19: "¶",
    20: "t",
    21: "¥",
    22: "u",
    23: "i",
    24: "ø",
    25: "þ",
    26: "°",
    27: "",

    30: "æ", // CSA: "q" is replaced with "a"
    31: "ß", // CSA: "s" stays "s"
    32: "ð", // CSA: "d" stays "d"
    33: "ª", // CSA: "f" stays "f"
    34: "g", // CSA: "g" stays "g"
    35: "h", // CSA: "h" stays "h"
    36: "j", // CSA: "j" stays "j"
    37: "k", // CSA: "k" stays "k"
    38: "l", // CSA: "l" stays "l"
    39: "´", // CSA: "m" is replaced with ";"
    40: "{", // CSA: "ù" is replaced with "'"
    41: "¬", // CSA: "*" is replaced with "`"

    43: "`", // CSA: "<" is replaced with "\"
    44: "«", // CSA: "w" is replaced with "z"
    45: "»", // CSA: "x" stays "x"
    46: "¢", // CSA: "c" stays "c"
    47: "v", // CSA: "v" stays "v"
    48: "b", // CSA: "b" stays "b"
    49: "n", // CSA: "n" stays "n"
    50: "µ", // CSA: "," stays ","
    51: "<", // CSA: ";" is replaced with "."
    52: ">", // CSA: ":" is replaced with "/"
    53: "//", // CSA: "!" is replaced with "KEY_R_SHIFT"

}
cittadhammo commented 5 months ago

I was able to built within codespace nicely with the TC prebuilt, see https://github.com/olup/kobowriter/pull/19/files for more detail. No need to have a linux machine, any browser will do it.