Post B6D2XZ3yR1nETHQHo0 by kabel42@polymaths.social
 (DIR) More posts by kabel42@polymaths.social
 (DIR) Post #B6D2XYGLPY5tzMCeRs by jns@mastodon.linkerror.com
       0 likes, 0 repeats
       
       Got the keyboard vfd to do custom character glyphs :)Following little bit of userland cpp code does the thing when my dekokbd kernel driver is loaded:happy_sad.cpp```#include <filesystem>#include <fstream>#include <iostream>#include <stdexcept>static const std::filesystem::path devicePath{"/dev/dekovfd"};unsigned char glyph_smile[8] = {    0b11011,       0b11011,    0b00000,      0b00000,      0b11111,     0b01110,     0b00000,    0b00000};unsigned char glyph_frown[8] = {    0b11011,       0b11011,      0b00000,      0b00000,      0b01110,     0b11011,     0b00000,    0b00000};enum class VfdBrightness : char {  Dim = 0x03,  Medium = 0x02,  Bright = 0x01,  VeryBright = 0x00};/// Clears the screen of the VFD display.void clear_screen(std::ofstream& deviceStream){  deviceStream << "\xe4\x01";}/// Sends cursor to row 1, line 1.void cursor_home(std::ofstream& deviceStream){  deviceStream << "\xe4\x02";}/// Moves cursor left 1 space.void cursor_left(std::ofstream& deviceStream){  deviceStream << "\xe4\x10";}/// Moves cursor right 1 space.void cursor_right(std::ofstream& deviceStream){  deviceStream << "\xe4\x14";}/** * Sends the cursor to a specific position. * * @param deviceStream the device to write to. * @param y Should be either 0 or 1. * @param x Visible characters range between 0 and 19,  *          but there's a hidden buffer behind it up to 39  *          (useful for scroll effects or instant paging). */void gotoxy(std::ofstream& deviceStream, int x, int y){    unsigned char address{};    if (x < 0) x = 0;    if (x > 39) x = 39;    address = y <= 0 ? 0x80 + x : 0xc0 + x;    deviceStream << "\xe4" << static_cast<char>(address);}/**  * Shifts the entire contents of the vfd display to the left. *  * It will also shift the hidden off-screen buffer onto the  * screen this way. */void shift_display_left(std::ofstream& deviceStream){  deviceStream << "\xe4\x18";}/**  * Shifts the entire contents of the vfd display to the left. *  * It will also shift screen contents into the hidden off-screen * buffer this way. */void shift_display_right(std::ofstream& deviceStream){  deviceStream << "\xe4\x1c";}/// Turns the vfd display on.void display_on(std::ofstream& deviceStream){  deviceStream << "\xe4\x0c";}/// Makes the cursor visible on the vfd display.void cursor_on(std::ofstream& deviceStream){  deviceStream << "\xe4\x0e";}/// Makes the cursor visible and makes it blink.void cursor_on_blinking(std::ofstream& deviceStream){  deviceStream << "\xe4\x0f";}/// Turns the vfd display off.void display_off(std::ofstream& deviceStream){  deviceStream << "\xe4\x08";}/** * Enable 8-bits per character mode. * * The display can also operate in a 4-bits per character * mode, and when it's in that mode, you'll get garbage on the * screen when trying to write normal text. This forces the * vfd into normal 8-bit mode. */void display_8bit(std::ofstream& deviceStream){  deviceStream << "\xe4\x38";  deviceStream << "\xe4\x38";  deviceStream << "\xe4\x38";}/** * Set vfd display brightness. * * @param deviceStream the device to write to. * @param brightness The desired screen brightness. */void display_brightness(std::ofstream& deviceStream, VfdBrightness brightness){  deviceStream << "\xe4\x38\xe6" << static_cast<const char>(brightness);}/** * Stores a custom glyph in one of the 8 UDF slots. * * @param deviceStream The device to write to. * @param slot The custom character slot (0 through 7, the vfd can store up to 8 custom glyphs) * @param data A pointer to 8 bytes of pixel data (5 bits used per byte) */void define_custom_char(std::ofstream& deviceStream, int slot, const unsigned char* data){    std::string buff{};    if (slot < 0 || slot > 7)    {        throw std::runtime_error("Invalid slot passed to define_custom_char().");    }    buff.reserve(18);    buff.push_back('\xe4');    buff.push_back(static_cast<char>(0x40 + (slot * 8)));    for (int i = 0; i < 8; ++i)     {        buff.push_back('\xe6');        buff.push_back(static_cast<char>(data[i]));    }    deviceStream.write(buff.data(), buff.size());}/// Entry pointint main(int argc, char* argv[]){  if (!std::filesystem::exists(devicePath))  {    std::cerr << devicePath.string() << " does not exist." << std::endl;    return 1;  }  std::ofstream deviceStream(devicePath);  if (!deviceStream.is_open())  {    std::cerr << "Could not open " << devicePath.string() << "\n";    return 1;  }  /* This is a bit of an initialization dance, to make sure everything works     no matter what state the vfd is in.      First we mke sure the display is in 8-bit character mode instead of the     weird 4-bit character mode, then we make sure the display is on, and has     the right brightness set etc... */  display_8bit(deviceStream);  display_on(deviceStream);  display_brightness(deviceStream, VfdBrightness::VeryBright);  deviceStream.flush();  define_custom_char(deviceStream, 1, glyph_smile);  define_custom_char(deviceStream, 2, glyph_frown);  deviceStream.flush();  clear_screen(deviceStream);  cursor_home(deviceStream);  deviceStream.flush();  deviceStream << "Happy: (\1)";  gotoxy(deviceStream, 0, 1);  deviceStream << "Sad: (\2)";  return 0;}```
       
 (DIR) Post #B6D2XYf9vHwZEJoT7w by kabel42@polymaths.social
       0 likes, 0 repeats
       
       @jns how and why does your keyboard have a VFD?
       
 (DIR) Post #B6D2XYrZB9rtqncNSy by jns@mastodon.linkerror.com
       0 likes, 0 repeats
       
       @kabel42 It was originally a video editing keyboard made by Pinnacle (they are still around making video editing thingies) -- it has a ton of extra individually controllable leds and keys, and the built-in vfd - all controllable with custom ps2 commands - which kinda needs a custom kernel driver to get working properly - I wrote one for FreeBSD initially, and recently one for Linux - A couple of years ago I released a peertube video showing how it works with FreeBSD - https://toobnix.org/w/dXMkWYitfejhPsxoydpCts(skip to the end around 22:50 or so for a proper demo)You can still find them on ebay from time to time.
       
 (DIR) Post #B6D2XZ3yR1nETHQHo0 by kabel42@polymaths.social
       0 likes, 0 repeats
       
       @jns nice, that's a lot of keyboard :)
       
 (DIR) Post #B6D2XZGjfa096rOThI by jns@mastodon.linkerror.com
       0 likes, 1 repeats
       
       @kabel42 All of my keyboards have been big historically my main keyboard before this one was a unicomp PC122I also built a Hyper7 kit (one of these https://imgur.com/a/hyper7-Z8pIW  - picture not mine) - (With the bulk of the keycaps re-used for the pinnacle deko) - but i never ended up using the hyper7 because it's design is AWFUL haha - It's actually SMALLER than the unicomp PC122, with the keys more cramped, and the modern keycaps the kids make these days don't have proper j/f key nibs to position your hands without looking - and due to the cramped layout and no spacing to 'feel' your way to the main keyboard, 70% of the time you end up mis-aligning your hands. - The pinnacle deko is much more practical, and technically has more individual keycodes it sends by default :p I ended up 'solving' the j/f key problem by using a punch to punch a bubble into the plastic - sigh - there's plenty of other problems with the 'fancy' keycap set though - like no led light-channels for caps-lock/numlock/scroll-lock/etc...
       
 (DIR) Post #B6D37wlBo7F8OJz8jo by mirabilos@toot.mirbsd.org
       0 likes, 0 repeats
       
       @jns your Markdown is broken
       
 (DIR) Post #B6D7AeSWhqHsJinihE by jns@mastodon.linkerror.com
       0 likes, 0 repeats
       
       @mirabilos oh well.. not sure if it's fixable.
       
 (DIR) Post #B6D7AehPoUCH3tlbu4 by mirabilos@toot.mirbsd.org
       0 likes, 0 repeats
       
       @jns ah, probably not if you’re on Mastodon