Skip to content

Instantly share code, notes, and snippets.

@charlestsai1995
Last active April 11, 2024 21:30
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save charlestsai1995/54ab65a87e2e063ea25eb3aec4193fe1 to your computer and use it in GitHub Desktop.
Save charlestsai1995/54ab65a87e2e063ea25eb3aec4193fe1 to your computer and use it in GitHub Desktop.
CJK support on Beepy

CJK support on Beepy (both display and input)

The Beepy uses a monochrome sharp memory LCD panel which has some caveat. This document includes a way to bring CJK support to Beepy in the framebuffer. The below is based on raspbian on raspberry pi zero, and had ran the Beepy setup script found on https://beepy.sqfmi.com/docs/getting-started.

Install DRM driver for the LCD

We will be using fbterm. Since fbterm supports minimal of 32bpp, we need to install a DRM driver for the sharp memory LCD panel to enable 32bpp mode.

Download the driver made by excel,

$ git clone https://github.com/ardangelo/sharp-drm-driver.git

Compile and install

$ cd ~/sharp-drm-driver
$ make
$ sudo make install

Reboot the raspberry pi to enable the driver

Install Excel's keyboard driver

The official keyboard driver does not function with fcitx IME so we would use Excel's keyboard driver. The driver only works with the customized firmware. Download i2c_puppet.uf2 and update the firmware,

  1. Slide the power switch off (left if facing up)
  2. Connect the Beepy to your computer via USB-C
  3. While holding the "End Call" key (top right on the keypad), slide the power switch on
  4. The Beepy will present itself as a USB mass storage device, drag'n'drop the new firmware (*.uf2) into the drive and it will reboot with the new firmware

Now boot the raspberry pi. The keyboard won't work so need to ssh into the pi. Install the driver

$ git clone https://github.com/ardangelo/beepberry-keyboard-driver.git
$ cd beepberry-keyboard-driver
$ make
$ sudo make install

Re-compile fbterm

Download fbterm from https://github.com/onokatio/fbterm2

$ git clone https://github.com/onokatio/fbterm2.git

Change the "/dev/fb0" to "/dev/fb1" in /src/fbdev.cpp using any editor of your choice, and execute the below to compile and install fbterm.

$ sudo apt-get install libfontconfig1-dev
$ cd ~/fbterm2
$./configure && make && sudo make install

Make sure you execute the below so fbterm can be run by non-root user and can capture shortcut keys

$ sudo gpasswd -a YOUR_USERNAME video
$ sudo setcap 'cap_sys_tty_config+ep' /usr/local/bin/fbterm

Configure fbterm

Now execute fbterm once. The text might be wonky but we will configure it.

$ fbterm

Install fonts. The below fonts should be good for English, Chinese, and Japanese.

$ sudo apt install xfonts-wqy fonts-terminus-otb fonts-dotgothic16

Now edit the fbterm configure file ~/.fbtermrc, change the following

font-names=Terminus,WenQuanYi Bitmap Song,DotGothic16
font-size=14
font-width=8
font-height=16
text-encodings=utf-8
term=xterm-mono

Restart fbterm to make the change effective. Now Beepy should display CJK characters without issue.

(Optional) Install tmux and enable fbterm by default

Running tmux in fbterm seems to resolve many key mapping issues. First install tmux if you have not already,

$ sudo apt install tmux

Now add the below to your ~/.bashrc

if [ -z "$SSH_CONNECTION" ]; then
 # if in virtual terminal, start fbterm
   if [[ "$(tty)" =~ /dev/tty ]] && type fbterm > /dev/null 2>&1; then
        fbterm
  # otherwise, start/attach to tmux
   elif [ -z "$TMUX" ] && type tmux >/dev/null 2>&1; then
        tmux new -As "$(basename $(tty))"
   fi
fi

Logout and back in to have it take effect.

Install fcitx and enable IMEs

Now we can install fcitx and enable IMEs,

$ sudo apt install fcitx-frontend-fbterm

Run fcitx-config-gtk3 under Xorg to enable IMEs or go to ~/.config/fcitx and edit profile (example below enables google pinyin),

EnabledIMList=fcitx-keyboard-us:True,googlepinyin:True,pinyin:False

You can also configure the hotkeys in ~/.config/fcitx/config

Uncomment and change the following in ~/.fbtermrc,

input-method=fcitx-fbterm

Now reboot and launch fcitx,

$ fcitx &

Now press Ctrl + space (phone + space) you should be able to use the input method enabled.

Showcase of the end result

wttr.inClock screensaverDisplaying JapaneseDisplaying Chinese IME

Special thanks to discord/beeper members teenux, themediocritist, _burr_, excel

@wastee
Copy link

wastee commented Aug 16, 2023

Thanks for sharing! I recommend uncommenting term=linux in ~/.fbtermrc. Otherwise, the value of 'term' will be set to None, and something will go wrong.

@wastee
Copy link

wastee commented Aug 16, 2023

I encountered an issue with tmux. When using beepberry within tmux and logging into a remote machine via SSH, which is also within a tmux session, pressing Ctrl + B and then D will detach me from the beepberry's tmux session, not from the remote machine's tmux session.

The simplest solution would be to avoid using tmux on beepberry if the remote machine is already utilizing tmux.

My mistake. It can use ctrl + b twice to control the tmux inside.

@wastee
Copy link

wastee commented Aug 16, 2023

I'm stuck at the fcitx & step. It's showing the error message FATAL xim.c x11 not initialized. Have you encountered this issue before?

@charlestsai1995
Copy link
Author

Thanks for sharing! I recommend uncommenting term=linux in ~/.fbtermrc. Otherwise, the value of 'term' will be set to None, and something will go wrong.

Thanks actually term=xterm-mono will be a better choice

I'm stuck at the fcitx & step. It's showing the error message FATAL xim.c x11 not initialized. Have you encountered this issue before?

No, but it should be expected as beepy is not running x11. Have you installed fcitx-frontend-fbterm?

@wastee
Copy link

wastee commented Aug 17, 2023

actually term=xterm-mono will be a better choice

Thanks

Have you installed fcitx-frontend-fbterm?

Yes. I followed these step but dont know what missed.

@wastee
Copy link

wastee commented Aug 17, 2023

I found the solution in Fcitx's wiki fcitx-fbterm-helper -l

https://fcitx-im.org/wiki/Fbterm

Thanks again!

@charlestsai1995
Copy link
Author

charlestsai1995 commented Aug 17, 2023

I found the solution in Fcitx's wiki fcitx-fbterm-helper -l

https://fcitx-im.org/wiki/Fbterm

Thanks again!

That's werid because all fcitx-fbterm-helper -l does is just launch both fcitx and fbterm. I tried again and the FATAL xim.c x11 not initialized error should not stop fcitx from functioning as we are not running it in X11 environment.

@wastee
Copy link

wastee commented Aug 18, 2023

the FATAL xim.c x11 not initialized error should not stop fcitx from functioning as we are not running it in X11 environment.

Yes, that's weird. Maybe I triggered some bugs. May I ask if you are running the 32-bit or 64-bit version? I'm using 32-bit Raspbian.

@wastee
Copy link

wastee commented Aug 22, 2023

Hi,

I've found the solution for the issue where hot keys for changing pages do not work and typing numbers will not choose character candidates.

To resolve this, follow these steps:

  1. Install beepy-kbd from https://ardangelo.github.io/beepy-ppa/
  2. After installation, the issue should be resolved. You can now use the Up and Down keys to change pages in Meta mode.

For more information about the keymap details, you can visit: https://github.com/ardangelo/beepberry-keyboard-driver

@jd3096-mpy
Copy link

I follow every your step.
But I cant't run tmux in fbterm
open terminal failed:missing or unsuitable terminal: unknown
run tmux without fbterm is ok.
In fbterm, there are key mapping issues.
How to slove it?

@wastee
Copy link

wastee commented Aug 27, 2023

open terminal failed:missing or unsuitable terminal: unknown

You can try to add line term=xterm-mono into its config file.

In fbterm, there are key mapping issues.

If you're tired of dealing with key mapping problems, you might wanna give tmux a shot. It can help smooth things out.

@jd3096-mpy
Copy link

term=xterm-mono

It works,thanks a lot.

@youngoris
Copy link

youngoris commented Aug 28, 2023

How can I configure fcitx to start automatically ? I tried using systemctl, but it didn't work. Adding fcitx & to .bashrc under the tmux new -As "$(basename $(tty))" also didn't work.

@youngoris
Copy link

youngoris commented Aug 28, 2023

ran fcitx & in the ssh, somehow the keyboad suddenly dead, plan to reflash.

@charlestsai1995
Copy link
Author

ran fcitx & in the ssh, somehow the keyboad suddenly dead, plan to reflash.

Should be unrelated

How can I configure fcitx to start automatically ? I tried using systemctl, but it didn't work. Adding fcitx & to .bashrc under the tmux new -As "$(basename $(tty))" also didn't work.

Did not work for me neither. Please feel free to share if you got it working

@youngoris
Copy link

youngoris commented Aug 29, 2023

ran fcitx & in the ssh, somehow the keyboad suddenly dead, plan to reflash.

Should be unrelated

How can I configure fcitx to start automatically ? I tried using systemctl, but it didn't work. Adding fcitx & to .bashrc under the tmux new -As "$(basename $(tty))" also didn't work.

Did not work for me neither. Please feel free to share if you got it working

the SQFMI's firmware has a known bug casue keyboard stuck, using ardangelo's firmware indeed solved the keyboard issue.
https://github.com/ardangelo/beepy-ppa#updating-firmware

autostart with fcitx is still working around...

@youngoris
Copy link

youngoris commented Aug 29, 2023

ran fcitx & in the ssh, somehow the keyboad suddenly dead, plan to reflash.

Should be unrelated

How can I configure fcitx to start automatically ? I tried using systemctl, but it didn't work. Adding fcitx & to .bashrc under the tmux new -As "$(basename $(tty))" also didn't work.

Did not work for me neither. Please feel free to share if you got it working

share my method of fcitx autostart:

  1. write a bash script for checking and run fcitx:
    vi ~/fcitx-start-check.sh
  2. copy and paste the code below in this file
#!/bin/bash
if ! pgrep -x "fcitx" > /dev/null; then
    echo "fcitx is not running. Starting fcitx..."
    fcitx &
    sleep 1  # wait fcitx to start
fi
exit
  1. save and make sure this file has +x permission;
    chmod +x ~/fcitx-start-check.sh
  2. edit .tmux.conf, add the following code to the top:
#Start fcitx 
new-session -d -s default "~/fcitx-start-check.sh"
  1. save and reboot, you'll have fcitx started at tmux start, fcitx may take few seconds to initialize or you can try pressing ctrl+ space to switch the input method several times, it will active the input window.

@youngoris
Copy link

youngoris commented Aug 31, 2023

Problem: In an xterm terminal (Beepy), after exiting tmux (prefix key + d), noticed a repeated user@host prompt, followed by a semicolon (;) and a space.

Solution: The issue was resolved by modifying the PS1 variable in the .bashrc file.

The original PS1 setting under the line xterm*|rxvt*) was:
PS1="\[\e]0;${debian_chroot:+($debian_chroot)}\u@\h: \w\a\]$PS1"

The solution was to change the PS1 setting to:
PS1="\[\e]0\a\]$PS1"

Remember, after modifying the .bashrc file, it needs to reboot for the changes to take effect.

@Retrograde-i486
Copy link

Thanks for the guide, i believe I've got it all working correctly including the inverted screen. I was wondering how you got the battery percentage down in the bottom bar?

Oh and what are you using for weather? My usual go-to of curling wttr.in in a terminal is far too big for the beepy's screen. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment