1
0
Fork 0
mirror of https://github.com/rfc2822/GfxTablet synced 2025-10-03 09:39:16 +02:00

Eyecandy color Mod + GIMP Pressure Curve fix initial

This commit is contained in:
= 2015-03-17 16:53:33 -04:00
parent ff865c297b
commit d33e1a9f79
3 changed files with 206 additions and 8 deletions

49
driver-uinput/README Normal file
View file

@ -0,0 +1,49 @@
GfxTablet network manager daemon.
Protocol version 1.0 -- quadcore-dev proposed commit.
This code has been modified from it's original source on
GitHub -- https://github.com/edtrind/GfxTablet-master
Author: bitfire web engineering/GfxTablet -- Richard Hirner
http://rfc2822.github.io/GfxTablet/
Modified by quadcore-dev/loopyd - Robert Smith
lupinedreamexpress@gmail.com
This version provides higher compatability for GIMP (by
converting the output values to larger ones so that the
pressure curve function becomes usable in "Input Settings"
-> "Network Tablet".
It also contains some eyecandy, a visible pressure bar that
indicates how hard your last stroke was. It does not spam
your terminal window with the events, but will exit with
an error code if there is a problem.
This code was tested on Ubuntu 14.04 LTS Studio and is
verified working on this platform.
I am not responsible if my code causes your GfxTablet
daemon to stop functioning, your computer to catch fire,
or your pets to die from said fire, etc.
---
Modified:
networktablet.c - network tablet daemon
Added:
qccolor.h - eyecandy for your terminal
README - this file
Deleted:
None
--
Have a wonderful life!
~quadcore-dev/loopyd
"We write code because we like to."

View file

@ -1,3 +1,34 @@
// networktablet.c -- GfxTablet network manager daemon.
//
// This code has been modified from it's original source on
// GitHub -- https://github.com/edtrind/GfxTablet-master
// Author: bitfire web engineering/GfxTablet -- Richard Hirner
// http://rfc2822.github.io/GfxTablet/
//
// Modified by quadcore-dev/loopyd - Robert Smith
// lupinedreamexpress@gmail.com
//
// This version provides higher compatability for GIMP (by
// converting the output values to larger ones so that the
// pressure curve function becomes usable in "Input Settings"
// -> "Network Tablet".
//
// It also contains some eyecandy, a visible pressure bar that
// indicates how hard your last stroke was. It does not spam
// your terminal window with the events, but will exit with
// an error code if there is a problem.
//
// This code was tested on Ubuntu 14.04 LTS Studio and is
// verified working on this platform.
//
// I am not responsible if my code causes your GfxTablet
// daemon to stop functioning, your computer to catch fire,
// and your pets to die, etc.
//
// Have a wonderful life!
//
// ~quadcore-dev/loopyd
// "We write code because we like to."
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
@ -11,16 +42,15 @@
#include <linux/input.h> #include <linux/input.h>
#include <linux/uinput.h> #include <linux/uinput.h>
#include "protocol.h" #include "protocol.h"
#include "qccolor.h"
#define die(str, args...) { \ #define die(str, args...) { \
perror(str); \ perror(str); \
exit(EXIT_FAILURE); \ exit(EXIT_FAILURE); \
} }
int udp_socket; int udp_socket;
void init_device(int fd) void init_device(int fd)
{ {
struct uinput_user_dev uidev; struct uinput_user_dev uidev;
@ -93,7 +123,6 @@ void quit(int signal) {
close(udp_socket); close(udp_socket);
} }
int main(void) int main(void)
{ {
int device; int device;
@ -105,12 +134,24 @@ int main(void)
init_device(device); init_device(device);
udp_socket = prepare_socket(); udp_socket = prepare_socket();
printf("GfxTablet driver (protocol version %u) is ready and listening on 0.0.0.0:%u (UDP)\n" cls_screen();
"Hint: Make sure that this port is not blocked by your firewall.\n", PROTOCOL_VERSION, GFXTABLET_PORT); textcolor(RESET, WHITE, BLACK);
textcolor(BRIGHT, GREEN, BLACK);
printf("GfxTablet driver (protocol version %u) is ready and listening on:\n", PROTOCOL_VERSION);
printf("\t0.0.0.0:%u (UDP)\n\n", GFXTABLET_PORT);
textcolor(BRIGHT, RED, BLACK);
printf("Hint: Make sure that this port is not blocked by your firewall!\n");
textcolor(BRIGHT, WHITE, BLACK);
printf("FIX applied by quadcore-dev/loopyd\nRobert Smith -- lupinedreamexpress@gmail.com.\n");
textcolor(DIM, WHITE, BLACK);
printf("For GIMP Pressure curve + eyecandy pressure bar!\n\n");
signal(SIGINT, quit); signal(SIGINT, quit);
signal(SIGTERM, quit); signal(SIGTERM, quit);
long fixed_pressure = 0L;
short progj = 0L;
while (recv(udp_socket, &ev_pkt, sizeof(ev_pkt), 0) >= 9) { // every packet has at least 9 bytes while (recv(udp_socket, &ev_pkt, sizeof(ev_pkt), 0) >= 9) { // every packet has at least 9 bytes
printf("."); fflush(0); printf("."); fflush(0);
@ -127,9 +168,20 @@ int main(void)
ev_pkt.x = ntohs(ev_pkt.x); ev_pkt.x = ntohs(ev_pkt.x);
ev_pkt.y = ntohs(ev_pkt.y); ev_pkt.y = ntohs(ev_pkt.y);
ev_pkt.pressure = ntohs(ev_pkt.pressure);
printf("x: %hi, y: %hi, pressure: %hi\n", ev_pkt.x, ev_pkt.y, ev_pkt.pressure); // FIX: More precise pressure value for GIMP
fixed_pressure = (long) ((float) (LONG_MAX / SHRT_MAX) * (float) ntohs(ev_pkt.pressure));
ev_pkt.pressure = fixed_pressure;
// Calculate and draw our pressure bar.
progj = (short) (((float) fixed_pressure / (float) LONG_MAX) * 64.00f);
textcolor(RESET, WHITE, BLACK);
printf("A1 (X): %hi, A2 (Y): %hi, \t A3 (Pressure): ", ev_pkt.x, ev_pkt.y);
progbar(progj, 16);
textcolor(RESET, WHITE, BLACK);
printf(" \r");
// Send the events to the app.
send_event(device, EV_ABS, ABS_X, ev_pkt.x); send_event(device, EV_ABS, ABS_X, ev_pkt.x);
send_event(device, EV_ABS, ABS_Y, ev_pkt.y); send_event(device, EV_ABS, ABS_Y, ev_pkt.y);
send_event(device, EV_ABS, ABS_PRESSURE, ev_pkt.pressure); send_event(device, EV_ABS, ABS_PRESSURE, ev_pkt.pressure);
@ -148,7 +200,8 @@ int main(void)
} }
close(udp_socket); close(udp_socket);
printf("Removing network tablet from device list\n"); textcolor(RESET, WHITE, BLACK);
printf("\nRemoving network tablet from device list\n");
ioctl(device, UI_DEV_DESTROY); ioctl(device, UI_DEV_DESTROY);
close(device); close(device);

96
driver-uinput/qccolor.h Normal file
View file

@ -0,0 +1,96 @@
// qccolor.h -- Some color effects for your terminal!
//
// By quadcore-dev/loopyd -- Robert Smith
// lupinedreamexpress@gmail.com
//
// Replacement for conio.h. This module contains some
// eyecandy for your terminal. Including a color set
// subroutine and a neat little progress bar routine!
//
// By quadcore-dev on GitHub
// "We write code because we like to!"
//
#pragma once
#define RESET 0
#define BRIGHT 1
#define DIM 2
#define UNDERLINE 3
#define BLINK 4
#define REVERSE 7
#define HIDDEN 8
#define BLACK 0
#define RED 1
#define GREEN 2
#define YELLOW 3
#define BLUE 4
#define MAGENTA 5
#define CYAN 6
#define WHITE 7
void textcolor(int attr, int fg, int bg);
void reset_screen(void);
void progbar(short ipVal, short ipMaxVal);
// textcolor by QuadCore -- Sets text color at current cursor
// position.
//
// int attr - Color attribute
// int fg - Foreground color
// int bg - Background color
//
void textcolor(int attr, int fg, int bg)
{
char command[13];
sprintf(command, "%c[%d;%d;%dm", 0x1B, attr, fg + 30, bg + 40);
printf("%s", command);
}
// cls_screen by QuadCore -- Clears screen of all text
//
// Nothing. (void)
//
void cls_screen(void)
{
system("reset");
return;
}
// progbar by QuadCore -- Draw a simple progress bar
//
// int ipVal = Current Value.
// int ipMaxVal = Max Value.
//
// Don't pass large values or you'll get a large progress
// bar! Convert them first using a ratio! Also don't
// pass 0 for ipMaxVal or you get divison by zero crash!
//
void progbar(short ipVal, short ipMaxVal) {
short iProgC = ipVal;
int ipColor = 0;
if ((float) ((float) ipVal / (float) ipMaxVal) <= 0.25f) {
ipColor = BLUE;
}
if ((float) ((float) ipVal / (float) ipMaxVal) > 0.25f) {
ipColor = GREEN;
}
if ((float) ((float) ipVal / (float) ipMaxVal) > 0.65f) {
ipColor = YELLOW;
}
if ((float) ((float) ipVal / (float) ipMaxVal) > 0.85f) {
ipColor = RED;
}
iProgC = ipMaxVal - ipVal;
while (iProgC++ <= ipMaxVal && iProgC != 0) {
textcolor (DIM, ipColor, ipColor);
printf (" ");
}
iProgC = ipVal;
while (iProgC++ <= ipMaxVal) {
textcolor (DIM, WHITE, WHITE);
printf ("_");
}
}