Skip to content

Commit

Permalink
Copied supporting H and CPP files from Workshop4
Browse files Browse the repository at this point in the history
  • Loading branch information
cruzjuniel committed Apr 20, 2023
1 parent a23d38e commit 72982f5
Show file tree
Hide file tree
Showing 13 changed files with 532 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Pixxi-Serial-Arduino-Library
version=1.0.2
version=1.0.3
author=4D Systems
maintainer=4D Systems
sentence=Provides library access to communicate with the 4D Systems Pixxi processors, when configured in Serial/SPE mode
Expand Down
126 changes: 126 additions & 0 deletions src/Pixxi_ColourRoutines.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
#if (ARDUINO >= 100)
#include "Arduino.h" // for Arduino 1.0
#else
#include "WProgram.h" // for Arduino 23
#endif

//#include "Picaso_Serial_4DLib.h"
//#include "Picaso_Const4D.h"

#define HLSMAX 127 // HLS vary over 0-HLSMAX
#define HLSMAXm2d3 (HLSMAX* 2 / 3 )
#define HLSMAXd12 (HLSMAX / 12 )
#define HLSMAXd6 (HLSMAX / 6 )
#define HLSMAXd2 (HLSMAX / 2 )
#define HLSMAXd3 (HLSMAX / 3 )
#define RGBMAX 127 // R,G, and B vary over 0-RGBMAX
#define RGBMAXm2 (RGBMAX*2)
// HLSMAX BEST IF DIVISIBLE BY 6
// RGBMAX, HLSMAX must each fit in a byte.

// Hue is undefined if Saturation is 0 (grey-scale) *
// This value determines where the Hue scrollbar is
// initially set for achromatic colors
#define UNDEFINED (127 * 2 / 3 )

// color conversion routines seem to be based on http://support.microsoft.com/kb/29240
// My copy seem to have been around since the MSDOS days, I don't know if it came from another source

uint16_t RGBs2COL(int16_t r, int16_t g, int16_t b)
{
return (b >> 2) | (g & 0x7E) << 4 | (r & 0x7c) << 9 ;
}

void c565toRGBs(int16_t i565, int16_t * red, int16_t * green, int16_t * blue)
{
*red = (i565 & 0xF800) >> 9 ;
*green = (i565 & 0x07E0) >> 4 ;
*blue = (i565 & 0x001F) << 2 ;
}

void RGB2HLS(int16_t red, int16_t green, int16_t blue, int16_t * h, int16_t * l, int16_t * s)
{
int16_t cMax, cMin, Rdelta, Gdelta, Bdelta, cMpM, cMmM ;
// calculate lightness
cMax = max( max(red,green), blue);
cMin = min( min(red,green), blue);
cMpM = cMax+cMin ;
cMmM = cMax-cMin ;

*l = ( (cMpM*HLSMAX) + RGBMAX ) / RGBMAXm2;

if (cMax == cMin) // r=g=b --> achromatic case
{
*s = 0;
*h = UNDEFINED;
}
else // chromatic case
{
// saturation
if (*l <= (HLSMAX/2))
*s = ( (cMmM*HLSMAX) + (cMpM / 2) ) / cMpM ;
else
*s = ( (cMmM*HLSMAX) + ((RGBMAXm2-cMpM) / 2) ) / (RGBMAXm2-cMpM);

// hue
Rdelta = ( ((cMax-red)* HLSMAXd6) + (cMmM / 2) ) / cMmM;
Gdelta = ( ((cMax-green)* HLSMAXd6) + (cMmM / 2) ) / cMmM;
Bdelta = ( ((cMax-blue)* HLSMAXd6) + (cMmM / 2) ) / cMmM;

if (red == cMax)
*h = Bdelta - Gdelta ;
else if (green == cMax)
*h = HLSMAXd3 + Rdelta - Bdelta ;
else
*h = HLSMAXm2d3 + Gdelta - Rdelta;

if (*h < 0) *h += HLSMAX;
if (*h > HLSMAX) *h -= HLSMAX;
}
}

int16_t hue_RGB(int16_t Hin, int16_t M1, int16_t M2)
{
int16_t Value ;
if (Hin < 0)
Hin += HLSMAX ;
else if (Hin > HLSMAX)
Hin -= HLSMAX ;

if (Hin < HLSMAXd6)
Value = M1 + ( (M2 - M1) * Hin + HLSMAXd12 ) / HLSMAXd6 ;
else if (Hin < HLSMAXd2 )
Value = M2 ;
else if (Hin < HLSMAXm2d3)
Value = M1 + ( (M2 - M1) * (HLSMAXm2d3 - Hin) + HLSMAXd12) / HLSMAXd6 ;
else
Value = M1 ;
return Value ;
}

void HLS2RGB(int16_t H, int16_t L, int16_t S, int16_t * red, int16_t * green, int16_t * blue)
{
int16_t M1, M2 ;

if (S == 0)
{
*red = L ;
*green = L ;
*blue = L ;
}
else
{
if (L <= HLSMAXd2)
M2 = (L * (HLSMAX + S) + HLSMAXd2) / HLSMAX ;
else
M2 = L + S - ((L * S + HLSMAXd2) / HLSMAX) ;

M1 = 2 * L - M2 ;
// Determine levels of primary colours.
if ((H > HLSMAX ) || (H < 0)) H = 0 ;
*red = hue_RGB( H+HLSMAXd3, M1, M2 ) ;
*green = hue_RGB( H, M1, M2 ) ;
*blue = hue_RGB( H-HLSMAXd3, M1, M2 ) ;
}

}
28 changes: 28 additions & 0 deletions src/Pixxi_ColourRoutines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// color conversion routines seem to be based on http://support.microsoft.com/kb/29240
// My copy seem to have been around since the MSDOS days, I don't know if it came from another source
#define HLSMAX 127 // HLS vary over 0-HLSMAX
#define HLSMAXm2d3 HLSMAX* 2 / 3
#define HLSMAXd12 HLSMAX / 12
#define HLSMAXd6 HLSMAX / 6
#define HLSMAXd2 HLSMAX / 2
#define HLSMAXd3 HLSMAX / 3
#define RGBMAX 127 // R,G, and B vary over 0-RGBMAX
#define RGBMAXm2 RGBMAX*2
// HLSMAX BEST IF DIVISIBLE BY 6
// RGBMAX, HLSMAX must each fit in a byte.

// Hue is undefined if Saturation is 0 (grey-scale) *
// This value determines where the Hue scrollbar is
// initially set for achromatic colors
#define UNDEFINED 127 * 2 / 3

uint16_t RGBs2COL(int16_t r, int16_t g, int16_t b) ;

void c565toRGBs(int16_t i565, int16_t * red, int16_t * green, int16_t * blue);

void RGB2HLS(int16_t red, int16_t green, int16_t blue, int16_t * h, int16_t * l, int16_t * s) ;

uint16_t hue_RGB(int16_t Hin, int16_t M1, int16_t M2) ;

void HLS2RGB(int16_t H, int16_t L, int16_t S, int16_t * r, int16_t * g, int16_t * b);

131 changes: 131 additions & 0 deletions src/Pixxi_KBRoutines.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
#include "Pixxi_Serial_4DLib.h"
#include "Pixxi_Const4D.h"

#include "Pixxi_KBRoutines.h"

#define KbShiftBit 01
#define KbCapsBit 02
#define KbShiftCapsBits 03
#define KbCtrlBit 04

#if (ARDUINO >= 100)
#include "Arduino.h" // for Arduino 1.0
#else
#include "WProgram.h" // for Arduino 23
#endif

void refreshstate(Pixxi_Serial_4DLib Display, word hndl, int8_t iKB, int8_t * oKB)
{
int8_t shifted ;
shifted = oKB[KbState] & KbShiftCapsBits ;
if (!shifted || (shifted == KbShiftCapsBits))
{
shifted = 0 ;
oKB[KbCaps] = 0 ;
}
else
{
shifted = 1 ;
oKB[KbCaps] = 2 ;
}
setkeystate(Display, hndl, iKB, shifted) ;
if (oKB[KbState] & KbCapsBit)
setkeystate(Display, hndl, iKB + oKB[KbLock],1) ;
if ((oKB[KbState] & KbShiftBit) && (shifted))
{
setkeystate(Display, hndl, iKB + oKB[KbShift1],1) ;
setkeystate(Display, hndl, iKB + oKB[KbShift2],1) ;
}
if (oKB[KbState] & KbCtrlBit)
{
setkeystate(Display, hndl, iKB +oKB[KbCtrl1],1) ;
setkeystate(Display, hndl, iKB + oKB[KbCtrl2],1) ;
}
}


void kbDown(Pixxi_Serial_4DLib Display, word hndl, int8_t iKB, int8_t * oKB, uint8_t * KBKeys, int8_t key, Callback handler)
{
int8_t keyval ;
oKB[KbMvt] = 1 ;
oKB[KbIgn] = 0 ;
if ((key == oKB[KbShift1]) || (key == oKB[KbShift2]))
{
if (oKB[KbState] & KbShiftBit)
{
oKB[KbState] &= ~KbShiftBit ;
oKB[KbMvt] = 0 ;
}
else
oKB[KbState] |= KbShiftBit ;
refreshstate(Display, hndl, iKB, oKB) ;
oKB[KbIgn] = 1 ;
}
else if ((key == oKB[KbCtrl1]) || (key == oKB[KbCtrl2]))
{
if (oKB[KbState] & KbCtrlBit)
{
oKB[KbState] &= ~KbCtrlBit ;
oKB[KbMvt] = 0 ;
}
else
oKB[KbState] |= KbCtrlBit ;
setkeystate(Display, hndl, iKB + oKB[KbCtrl1],oKB[KbMvt]) ;
key = oKB[KbCtrl2] ;
oKB[KbIgn] = 1 ;
}
else if (key == oKB[KbLock])
{
if (oKB[KbState] & KbCapsBit)
{
oKB[KbState] &= ~KbCapsBit ;
oKB[KbMvt] = 0 ;
}
else
oKB[KbState] |= KbCapsBit ;
refreshstate(Display, hndl, iKB, oKB) ;
oKB[KbIgn] = 1 ;
}

if (!oKB[KbIgn])
{
if (oKB[KbShiftCaps])
keyval = (oKB[KbState] & KbShiftCapsBits) * oKB[KbButtons] - 1 ;
else if (((oKB[KbState] & KbShiftCapsBits) == 0) || ((oKB[KbState] & KbShiftCapsBits) == KbShiftCapsBits))
keyval = - 1 ;
else
keyval = oKB[KbButtons] - 1 ;
keyval = KBKeys[key+keyval] ;
if (oKB[KbState] & KbCtrlBit) keyval &= 0x9F ;
handler(keyval & 0xFF) ;
setkeystate(Display, hndl, iKB + key,oKB[KbMvt]+oKB[KbCaps]) ;
}
oKB[KbDown] = key ;
}

void setkeystate(Pixxi_Serial_4DLib Display, word hndl, int8_t key, int8_t idx)
{
Display.img_SetWord(hndl, key,IMAGE_INDEX, idx);
Display.img_Show(hndl,key) ;
}

void kbUp(Pixxi_Serial_4DLib Display, word hndl, int8_t iKB, int8_t * oKB)
{
if (!oKB[KbIgn])
{
setkeystate(Display, hndl, iKB + oKB[KbDown], oKB[KbCaps]) ;
if (oKB[KbState] & KbShiftBit)
{
oKB[KbState] &= ~KbShiftBit ;
refreshstate(Display, hndl, iKB, oKB) ;
}
if (oKB[KbState] & KbCtrlBit)
{
oKB[KbState] &= ~KbCtrlBit ;
setkeystate(Display, hndl, iKB + oKB[KbCtrl1],0) ;
setkeystate(Display, hndl, iKB + oKB[KbCtrl2],0) ;
}
oKB[KbDown] = -1 ;
}
}

30 changes: 30 additions & 0 deletions src/Pixxi_KBRoutines.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif

#define KbDown 0
#define KbMvt 1
#define KbState 2
#define KbIgn 3
#define KbCaps 4
#define KbShift1 5
#define KbShift2 6
#define KbCtrl1 7
#define KbCtrl2 8
#define KbLock 9
#define KbButtons 10
#define KbShiftCaps 11

typedef void (*Callback) (int);

void refreshstate(Pixxi_Serial_4DLib Display, word hndl, int8_t iKB, int8_t * oKB) ;

void kbDown(Pixxi_Serial_4DLib Display, word hndl, int8_t iKB, int8_t * oKB, uint8_t * KBKeys, int8_t key, Callback handler) ;

void kbUp(Pixxi_Serial_4DLib Display, word hndl, int8_t iKB, int8_t * oKB) ;

void setkeystate(Pixxi_Serial_4DLib Display, word hndl, int8_t key, int8_t idx) ;


35 changes: 35 additions & 0 deletions src/Pixxi_LedDigitsDisplay.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#if (ARDUINO >= 100)
#include "Arduino.h" // for Arduino 1.0
#else
#include "WProgram.h" // for Arduino 23
#endif

#include "Pixxi_Serial_4DLib.h"
#include "Pixxi_Const4D.h"

// WARNING, this code will crash if newval exceeds maximum displayable number
void LedDigitsDisplay(Pixxi_Serial_4DLib Display, word hndl, word newval, word index, word left, word Digits, word MinDigits, word WidthDigit, word LeadingBlanks)
{
word i, k, l, lb ;
l = 1 ;
for (i = 1; i < Digits; i++)
l *= 10 ;
lb = LeadingBlanks ;
for (i = 0; i < Digits; i++)
{
k = newval / l ;
newval -= k * l ;
if ( lb && (i < Digits - MinDigits) )
{
if (k == 0)
k = 10 ;
else
lb = 0 ;
}
l /= 10 ;
Display.img_SetWord(hndl, index, IMAGE_INDEX, k);
Display.img_SetWord(hndl, index, IMAGE_XPOS, left+i*WidthDigit) ;
Display.img_Show(hndl, index);
}
}

8 changes: 8 additions & 0 deletions src/Pixxi_LedDigitsDisplay.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#if (ARDUINO >= 100)
#include "Arduino.h" // for Arduino 1.0
#else
#include "WProgram.h" // for Arduino 23
#endif

// WARNING, this code will crash if newval exceeds maximum displayable number
void LedDigitsDisplay(Pixxi_Serial_4DLib Display, word hndl, word newval, word index, word left, word Digits, word MinDigits, word WidthDigit, word LeadingBlanks) ;
Loading

0 comments on commit 72982f5

Please sign in to comment.