Skip to content

Instantly share code, notes, and snippets.

@charlestsai1995
Last active October 4, 2024 11:00
Show Gist options
  • 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

@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!

@laonan
Copy link

laonan commented May 25, 2024

Hello, does anyone know how to set Google Pinyin to a black background? I have a white background.

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