Moved CTK terminal support into backyard as it depends on stuff recently moved in backyard as well.

This commit is contained in:
oliverschmidt 2007-05-26 21:54:08 +00:00
parent 4521c330d5
commit 5e7ecef8ab
8 changed files with 8 additions and 8 deletions

View file

@ -0,0 +1,123 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: ctk-term-ascii.h,v 1.1 2007/05/26 21:54:33 oliverschmidt Exp $
*/
/* ascii_control.h
*
* ASCII CONTROL CHARACTERS
* from American National Standard Code for Information Interchange X3.4-1977
*
* Abbreviations
*
* CC: communication control
* FE: format effector
* IS: information separator
* Delim: delimiter
* Intro: introducer
*/
/* ----------------------------------------------------------------------- */
/* C0 (7-bit) set */
/* ----------------------------------------------------------------------- */
/* mnemonic octal decimal C meaning */
/* ----------------------------------------------------------------------- */
#define ASCII_NUL (000) /* 0 '\0' Null */
#define ASCII_SOH (001) /* 1 Start of Heading (CC) */
#define ASCII_STX (002) /* 2 Start of Text (CC) */
#define ASCII_ETX (003) /* 3 End of Text (CC) */
#define ASCII_EOT (004) /* 4 End of Transmission (CC) */
#define ASCII_ENQ (005) /* 5 Enquiry (CC) */
#define ASCII_ACK (006) /* 6 Acknowledge (CC) */
#define ASCII_BEL (007) /* 7 '\a' Bell / Alert */
#define ASCII_BS (010) /* 8 '\b' Backspace (FE) */
#define ASCII_HT (011) /* 9 '\t' Horizontal Tabulation (FE) */
#define ASCII_LF (012) /* 10 '\n' Line Feed / Newline (FE) */
#define ASCII_VT (013) /* 11 '\v' Vertical Tabulation (FE) */
#define ASCII_FF (014) /* 12 '\f' Form Feed (FE) */
#define ASCII_CR (015) /* 13 '\r' Carriage Return (FE) */
#define ASCII_SO (016) /* 14 Shift Out */
#define ASCII_SI (017) /* 15 Shift In */
#define ASCII_DLE (020) /* 16 Data Link Escape (CC) */
#define ASCII_DC1 (021) /* 17 Device Control 1 XON */
#define ASCII_DC2 (022) /* 18 Device Control 2 */
#define ASCII_DC3 (023) /* 19 Device Control 3 XOFF */
#define ASCII_DC4 (024) /* 20 Device Control 4 */
#define ASCII_NAK (025) /* 21 Negative Acknowledge (CC) */
#define ASCII_SYN (026) /* 22 Synchronous Idle (CC) */
#define ASCII_ETB (027) /* 23 End of Transmission Block (CC) */
#define ASCII_CAN (030) /* 24 Cancel */
#define ASCII_EM (031) /* 25 End of Medium */
#define ASCII_SUB (032) /* 26 Substitute */
#define ASCII_ESC (033) /* 27 Escape */
#define ASCII_FS (034) /* 28 File Separator */
#define ASCII_GS (035) /* 29 Group Separator */
#define ASCII_RS (036) /* 30 Record Separator */
#define ASCII_US (037) /* 31 Unit Separator */
#define ASCII_DEL (0177) /* 127 Delete */
#define ASCII_NL ASCII_LF /* 10 alias for Newline */
/* ----------------------------------------------------------------------- */
/* C1 (8-bit) set (which have equivalent 7-bit multi-char sequences) */
/* ----------------------------------------------------------------------- */
/* mnemonic octal decimal 7-bit meaning */
/* ----------------------------------------------------------------------- */
#define ASCII_IND (0204) /* 132 Esc D Index (FE) */
#define ASCII_NEL (0205) /* 133 Esc E Next Line (FE) */
#define ASCII_SSA (0206) /* 134 Esc F Start Selected Area */
#define ASCII_ESA (0207) /* 135 Esc G End Selected Area */
#define ASCII_HTS (0210) /* 136 Esc H Horizontal Tab Set (FE) */
#define ASCII_HTJ (0211) /* 137 Esc I Horizontal Tab w/Justificat(FE)*/
#define ASCII_VTS (0212) /* 138 Esc J Vertical Tab Set (FE) */
#define ASCII_PLD (0213) /* 138 Esc K Partial Line Down (FE) */
#define ASCII_PLU (0214) /* 140 Esc L Partial Line Up (FE) */
#define ASCII_RI (0215) /* 141 Esc M Reverse Index (FE) */
#define ASCII_SS2 (0216) /* 142 Esc N Single Shift G2 (Intro) */
#define ASCII_SS3 (0217) /* 143 Esc O Single Shift G3 (Intro) */
#define ASCII_DCS (0220) /* 144 Esc P Device Control String (Delim) */
#define ASCII_PU1 (0221) /* 145 Esc Q Private Use 1 */
#define ASCII_PU2 (0222) /* 146 Esc R Private Use 2 */
#define ASCII_STS (0223) /* 147 Esc S Set Transmit State */
#define ASCII_CCH (0224) /* 148 Esc T Cancel Previous Character */
#define ASCII_MW (0225) /* 149 Esc U Message Waiting */
#define ASCII_SPA (0226) /* 150 Esc V Start Protected Area */
#define ASCII_EPA (0227) /* 151 Esc W End Protected Area */
#define ASCII_CSI (0233) /* 155 Esc [ Control Sequence Introducer */
#define ASCII_ST (0234) /* 156 Esc \ String Terminator (Delim) */
#define ASCII_OSC (0235) /* 157 Esc ] Operating System Control (Delim*/
#define ASCII_PM (0236) /* 158 Esc ^ Privacy Message (Delim) */
#define ASCII_APC (0237) /* 159 Esc _ Application Program Command (De*/
/* ------------------------------------------------------------------------- */

View file

@ -0,0 +1,381 @@
/*
* Copyright (c) 2004, Adam Dunkels.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* Author: Adam Dunkels <adam@sics.se>
*
* $Id: ctk-term-in.c,v 1.1 2007/05/26 21:54:33 oliverschmidt Exp $
*/
#include <string.h>
#include "ctk/ctk.h"
#include "ctk-term.h"
#include "ctk-term-int.h"
#include "ctk-term-ascii.h"
#define PRINTF(x)
/*-----------------------------------------------------------------------------------*/
/*
* #defines and enums
*/
/*-----------------------------------------------------------------------------------*/
/* Size of input key buffer */
#define NUMKEYS 20
/* ANSI character classes */
enum {ACC_C0, ACC_INTERM, ACC_PARAM, ACC_LOWCASE, ACC_UPCASE,ACC_C1, ACC_G1, ACC_DEL, ACC_SPEC };
/*-----------------------------------------------------------------------------------*/
/*
* Structures
*/
/*-----------------------------------------------------------------------------------*/
/* Structure for mapping a character sequence to a key */
struct seqmap
{
const char* seq;
const ctk_arch_key_t key;
};
/*-----------------------------------------------------------------------------------*/
/*
* Local variables
*/
/*-----------------------------------------------------------------------------------*/
static ctk_arch_key_t keys[NUMKEYS];
static int firstkey, lastkey;
/* Sequences starting with ESC [ .... */
const static struct seqmap ctrlmap[] =
{
{"A",CH_CURS_UP},
{"B",CH_CURS_DOWN},
{"C",CH_CURS_RIGHT},
{"D",CH_CURS_LEFT},
{"11~",CH_F1},
{"12~",CH_F2},
{"13~",CH_F3},
{"14~",CH_F4},
// linux console
{"[A",CH_F1},
{"[B",CH_F2},
{"[C",CH_F3},
{"[D",CH_F4},
{0,0}
};
/* Sequences starting with ESC O .... */
const static struct seqmap ss3map[] =
{
{"A",CH_CURS_UP},
{"B",CH_CURS_DOWN},
{"C",CH_CURS_RIGHT},
{"D",CH_CURS_LEFT},
{"P",CH_F1},
{"Q",CH_F2},
{"R",CH_F3},
{"S",CH_F4},
{0,0}
};
/*-----------------------------------------------------------------------------------*/
/*
* Add a key to the input buffer
*/
/*-----------------------------------------------------------------------------------*/
static void
enqueue_key(ctk_arch_key_t k)
{
keys[lastkey] = k;
++lastkey;
if(lastkey >= NUMKEYS) {
lastkey = 0;
}
}
/*-----------------------------------------------------------------------------------*/
/*
* Classify a character
*/
/*-----------------------------------------------------------------------------------*/
static unsigned char
classify(unsigned char c)
{
if (0x00 <= c && c <=0x1f) return ACC_C0;
if (0x20 <= c && c <=0x2f) return ACC_INTERM;
if (0x30 <= c && c <=0x3f) return ACC_PARAM;
if (0x40 <= c && c <=0x5f) return ACC_UPCASE;
if (0x60 <= c && c <=0x7e) return ACC_LOWCASE;
if (c == 0x7f) return ACC_DEL;
if (0x90 <= c && c <=0x9f) return ACC_C1;
if (c == 0xa0) return ACC_SPEC;
if (0xA1 <= c && c <=0xfe) return ACC_G1;
if (0x90 <= c && c <=0x9f) return ACC_C1;
if (c == 0xff) return ACC_SPEC;
return ACC_SPEC;
}
/*-----------------------------------------------------------------------------------*/
/*
* Lookup a key sequence in a sequencemap and queue the key if sequence found
*/
/*-----------------------------------------------------------------------------------*/
static void
lookup_seq(const char* str, const struct seqmap* map)
{
while (map->seq != 0) {
if (strcmp(str,map->seq) == 0) {
enqueue_key(map->key);
return;
}
map++;
}
}
/*-----------------------------------------------------------------------------------*/
/* \internal
* Parse a character stream
* Returns -1 if c is consumed by the state machine 1 else.
*/
/*-----------------------------------------------------------------------------------*/
static int
parse_input(struct ctk_term_state* st, unsigned char c)
{
unsigned char cl = classify(c);
int ret = -1;
switch(st->inputstate) {
case ANS_IDLE:
switch(cl) {
case ACC_C0:
{
switch(c) {
case ASCII_ESC: st->inputstate = ANS_ESCSEQ; break;
case ASCII_BS: enqueue_key(CH_DEL); break;
case ASCII_HT: enqueue_key(CH_TAB); break;
case ASCII_FF: ctk_term_redraw(st); break;
case ASCII_CR: enqueue_key(CH_ENTER); break;
}
}
break;
case ACC_INTERM:
case ACC_PARAM:
case ACC_LOWCASE:
case ACC_UPCASE:
case ACC_G1:
ret = 1;
break;
case ACC_C1:
if (c == ASCII_CSI) {
st->inputstate = ANS_CTRLSEQ;
st->ctrlCnt = 0;
}
else if (c == ASCII_SS3) {
st->inputstate = ANS_SS3;
st->ctrlCnt = 0;
}
break;
case ACC_DEL:
enqueue_key(CH_DEL);
break;
case ACC_SPEC:
break;
}
break;
case ANS_ESCSEQ:
{
switch(cl) {
case ACC_C0:
case ACC_DEL:
break;
case ACC_INTERM:
st->inputstate = ANS_ESCSEQ_1;
break;
case ACC_UPCASE:
/* C1 control character */
if (c == '[') {
st->inputstate = ANS_CTRLSEQ;
st->ctrlCnt = 0;
}
else if (c == 'O') {
st->inputstate = ANS_SS3;
st->ctrlCnt = 0;
}
else {
st->inputstate = ANS_IDLE;
}
break;
case ACC_PARAM:
/* Private 2-character sequence */
case ACC_LOWCASE:
/* Standard 2-character sequence */
default:
st->inputstate = ANS_IDLE;
break;
}
}
break;
case ANS_ESCSEQ_1:
{
switch(cl) {
case ACC_C0:
case ACC_INTERM:
break;
case ACC_PARAM:
/* Private function*/
case ACC_LOWCASE:
case ACC_UPCASE:
/* Standard function */
default:
st->inputstate = ANS_IDLE;
break;
}
}
break;
case ANS_SS3:
{
switch(cl) {
case ACC_PARAM:
if (st->ctrlCnt < CTK_TERM_CTRLBUFLEN) st->ctrlbuf[st->ctrlCnt++]=c;
break;
case ACC_UPCASE:
/* VT100 PF seq */
if (st->ctrlCnt < CTK_TERM_CTRLBUFLEN) st->ctrlbuf[st->ctrlCnt++]=c;
st->inputstate = ANS_IDLE;
st->ctrlbuf[st->ctrlCnt] = 0;
lookup_seq((const char*)(st->ctrlbuf), ss3map);
break;
default:
st->inputstate = ANS_IDLE;
break;
}
}
break;
case ANS_CTRLSEQ:
{
switch(cl) {
case ACC_C0:
break;
case ACC_INTERM:
case ACC_PARAM:
if (st->ctrlCnt < CTK_TERM_CTRLBUFLEN) st->ctrlbuf[st->ctrlCnt++]=c;
break;
case ACC_LOWCASE:
case ACC_UPCASE:
/* Standard control sequence */
if (st->ctrlCnt < CTK_TERM_CTRLBUFLEN) st->ctrlbuf[st->ctrlCnt++]=c;
/* Cygwin console sends ESC [ [ A for function keys */
if (c != '[') {
st->ctrlbuf[st->ctrlCnt] = 0;
lookup_seq((const char*)(st->ctrlbuf), ctrlmap);
st->inputstate = ANS_IDLE;
}
break;
default:
st->inputstate = ANS_IDLE;
break;
}
}
break;
}
return ret;
}
/*-----------------------------------------------------------------------------------*/
/*
* Initialize the input buffer
*/
/*-----------------------------------------------------------------------------------*/
void ctk_term_input_init()
{
firstkey = lastkey = 0;
}
/*-----------------------------------------------------------------------------------*/
/**
* Handles an input character provided by the client
*
* \param ts State information
* \param b Input character
*/
/*-----------------------------------------------------------------------------------*/
void ctk_term_input(struct ctk_term_state* ts, unsigned char b)
{
int ret = parse_input(ts, b);
PRINTF(("terminput: 0x%02x\n", b));
if (ret > 0) {
enqueue_key((ctk_arch_key_t)b);
}
}
/*-----------------------------------------------------------------------------------*/
/**
* Checks the key press input queue to see if there are pending
* keys. Called by the CTK module.
*
* \return Zero if no key presses are in buffer, non-zero if there are
* key presses in input buffer.
*/
/*-----------------------------------------------------------------------------------*/
unsigned char
ctk_arch_keyavail(void)
{
return firstkey != lastkey;
}
/*-----------------------------------------------------------------------------------*/
/**
* Retrieves key presses from the VNC client. Called by the CTK
* module.
*
* \return The next key in the input queue.
*/
/*-----------------------------------------------------------------------------------*/
ctk_arch_key_t
ctk_arch_getkey(void)
{
ctk_arch_key_t key;
key = keys[firstkey];
if(firstkey != lastkey) {
++firstkey;
if(firstkey >= NUMKEYS) {
firstkey = 0;
}
}
return key;
}

View file

@ -0,0 +1,99 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: ctk-term-int.h,v 1.1 2007/05/26 21:54:33 oliverschmidt Exp $
*/
#ifndef __CTK_TERM_INT_H__
#define __CTK_TERM_INT_H__
/* Color definitions */
#define TERM_BACKGROUNDCOLOR 0
#define TERM_WINDOWCOLOR 1
#define TERM_SEPARATORCOLOR 7 /*(TERM_WINDOWCOLOR + 6)*/
#define TERM_LABELCOLOR 13 /*(TERM_SEPARATORCOLOR + 6)*/
#define TERM_BUTTONCOLOR 19 /*(TERM_LABELCOLOR + 6)*/
#define TERM_HYPERLINKCOLOR 25 /*(TERM_BUTTONCOLOR + 6)*/
#define TERM_TEXTENTRYCOLOR 31 /*(TERM_HYPERLINKCOLOR + 6)*/
#define TERM_ICONCOLOR 37 /*(TERM_TEXTENTRYCOLOR + 6)*/
#define TERM_MENUCOLOR 43 /*(TERM_ICONCOLOR + 6)*/
#define TERM_OPENMENUCOLOR 44/*(TERM_MENUCOLOR + 1)*/
#define TERM_ACTIVEMENUCOLOR 45 /*(TERM_OPENMENUCOLOR + 1) */
/* Structure describing an updated region */
struct ctk_term_update {
struct ctk_term_update *next;
#define UPDATE_NONE 0
#define UPDATE_PARTS 1
#define UPDATE_FULL 2
unsigned char type;
unsigned char x, y;
unsigned char w, h;
};
/* Character sequence parsing states */
enum { ANS_IDLE, ANS_ESCSEQ,ANS_ESCSEQ_1,ANS_SS3, ANS_CTRLSEQ};
struct ctk_term_state {
unsigned char type;
unsigned char state;
unsigned char height, width;
/* Variables used when sending screen updates. */
unsigned char x, y, x1, y1, x2, y2;
unsigned char w, h;
unsigned char c1, c2;
#define CTK_TERM_MAX_UPDATES 8
struct ctk_term_update *updates_current;
struct ctk_term_update *updates_pending;
struct ctk_term_update *updates_free;
struct ctk_term_update updates_pool[CTK_TERM_MAX_UPDATES];
/* Variables used when parsing input sequences */
unsigned char inputstate;
#define CTK_TERM_CTRLBUFLEN 5
unsigned char ctrlbuf[CTK_TERM_CTRLBUFLEN+1];
unsigned char ctrlCnt;
};
struct ctk_term_update * ctk_term_update_alloc(struct ctk_term_state *vs);
void ctk_term_update_free(struct ctk_term_state *ts, struct ctk_term_update *a);
void ctk_term_update_remove(struct ctk_term_state *ts, struct ctk_term_update *a);
void ctk_term_update_add(struct ctk_term_state *ts, struct ctk_term_update *a);
struct ctk_term_update * ctk_term_update_dequeue(struct ctk_term_state *ts);
void ctk_term_input_init();
#endif /* __CTK_TERM_INT_H__ */

View file

@ -0,0 +1,350 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: ctk-term-out.c,v 1.1 2007/05/26 21:54:33 oliverschmidt Exp $
*/
#include "libconio.h"
#include "ctk-term-int.h"
#include <string.h>
#include <stdio.h> // sprintf
#define PRINTF(x)
/*-----------------------------------------------------------------------------------*/
/*
* #defines and enums
*/
/*-----------------------------------------------------------------------------------*/
#define CHARS_WIDTH LIBCONIO_CONF_SCREEN_WIDTH
#define CHARS_HEIGHT LIBCONIO_CONF_SCREEN_HEIGHT
/*-----------------------------------------------------------------------------------*/
/*
* Local variables
*/
/*-----------------------------------------------------------------------------------*/
/* ANSI/VT100 colors
0 - None
1 - Bold (inc. inten)
4 - Underscore
7 - Reverse
x0 - black
x1 - red
x2 - green
x3 - yellow
x4 - blue
x5 - magenta
x6 - cyan
x7 - white
x = 3 fg x = 4 bg
*/
#if 0 /* Colorfull theme */
static const char backgroundcolor[] = "\033[0;37;40m";
static const char wincol[] = "\033[0;37;40m";
static const char wincol_f[] = "\033[0;1;37;40m";
static const char wincol_d[] = "\033[0;30;47m";
static const char sepcol[] = "\033[0;37;40m";
static const char sepcol_f[] = "\033[0;1;37;40m";
static const char sepcol_d[] = "\033[0;30;47m";
static const char labcol[] = "\033[0;37;40m";
static const char labcol_f[] = "\033[1;37;40m";
static const char labcol_d[] = "\033[0;30;47m";
static const char butcol[] = "\033[0;37;40m";
static const char butcol_w[] = "\033[0;30;47m";
static const char butcol_f[] = "\033[0;1;37;40m";
static const char butcol_fw[] = "\033[0;1;37;46m";
static const char butcol_d[] = "\033[0;30;47m";
static const char butcol_dw[] = "\033[0;37;46m";
static const char hlcol[] = "\033[0;4;36;40m";
static const char hlcol_w[] = "\033[0;4;30;47m";
static const char hlcol_f[] = "\033[0;1;4;36;40m";
static const char hlcol_fw[] = "\033[0;1;4;37;46m";
static const char hlcol_d[] = "\033[0;4;34;47m";
static const char hlcol_dw[] = "\033[0;4;37;46m";
static const char iconcol[] = "\033[0;32;40m";
static const char iconcol_w[] = "\033[0;30;42m";
static const char menucolor[] = "\033[0;37;43m";
static const char activemenucolor[] = "\033[0;1;37;43m";
#endif
#if 1 /* B/W theme */
static const char backgroundcolor[] = "\033[0m";
static const char wincol[] = "\033[0m";
static const char wincol_f[] = "\033[0;1m";
static const char wincol_d[] = "\033[0;7m";
static const char sepcol[] = "\033[0m";
static const char sepcol_f[] = "\033[0;1m";
static const char sepcol_d[] = "\033[0;7m";
static const char labcol[] = "\033[0m";
static const char labcol_f[] = "\033[0;1m";
static const char labcol_d[] = "\033[0;7m";
static const char butcol[] = "\033[0m";
static const char butcol_w[] = "\033[0m";
static const char butcol_f[] = "\033[0;1m";
static const char butcol_fw[] = "\033[0;1;7m";
static const char butcol_d[] = "\033[0;7m";
static const char butcol_dw[] = "\033[0m";
static const char hlcol[] = "\033[0;4m";
static const char hlcol_w[] = "\033[0;4;7m";
static const char hlcol_f[] = "\033[0;1;4m";
static const char hlcol_fw[] = "\033[0;1;4;7m";
static const char hlcol_d[] = "\033[0;4;7m";
static const char hlcol_dw[] = "\033[0;4m";
static const char iconcol[] = "\033[0m";
static const char iconcol_w[] = "\033[0;7m";
static const char menucolor[] = "\033[0;7m";
static const char activemenucolor[] = "\033[0m";
#endif
static const char* const colortheme[] =
{
backgroundcolor,
/* Window colors */
wincol, wincol, wincol_f, wincol_f, wincol_d, wincol_d,
/* Separator colors. */
sepcol, sepcol, sepcol_f, sepcol_f, sepcol_d, sepcol_d,
/* Label colors. */
labcol, labcol, labcol_f, labcol_f, labcol_d, labcol_d,
/* Button colors. */
butcol, butcol_w, butcol_f, butcol_fw, butcol_d, butcol_dw,
/* Hyperlink colors. */
hlcol, hlcol_w, hlcol_f, hlcol_fw, hlcol_d, hlcol_dw,
/* Textentry colors. */
butcol, butcol_w, butcol_f, butcol_fw, butcol_d, butcol_dw,
/* Icon colors */
iconcol, iconcol_w, iconcol, iconcol_w, iconcol, iconcol_w,
/* Menu colors. */
menucolor, activemenucolor, activemenucolor
};
static unsigned char
screen[CHARS_WIDTH * CHARS_HEIGHT],
colorscreen[CHARS_WIDTH * CHARS_HEIGHT];
/*-----------------------------------------------------------------------------------*/
/*
* Add a character to the screen buffer
*/
/*-----------------------------------------------------------------------------------*/
void
ctk_term_out_update_screen(unsigned char xpos,
unsigned char ypos,
unsigned char c,
unsigned char color)
{
if (c < 0x20) c = 0x20;
screen[xpos + ypos * CHARS_WIDTH] = c;
colorscreen[xpos + ypos * CHARS_WIDTH] = color;
}
/*-----------------------------------------------------------------------------------*/
/*
* Check if there are any updated pending. If so, make the first one current
*/
/*-----------------------------------------------------------------------------------*/
static void
check_updates(struct ctk_term_state* ts)
{
if (ts->updates_current != NULL) return;
ts->updates_current = ctk_term_update_dequeue(ts);
if (ts->updates_current != NULL) {
ts->x = ts->updates_current->x;
ts->y = ts->updates_current->y;
ts->w = ts->updates_current->w;
ts->h = ts->updates_current->h;
ts->x1 = ts->x2 = ts->x;
ts->y1 = ts->y2 = ts->y;
}
}
/*-----------------------------------------------------------------------------------*/
/** \internal
* Adds a cursor position change to buffer. Returns 0 if string doesn't fit else
* number of bytes actually written is returned.
*
* \param x X coordinate (screen coordinates)
* \param y Y coordinate (screen coordinates)
* \param buf Output buffer
* \param maxlen Maximum number of bytes to store in buffer
*/
/*-----------------------------------------------------------------------------------*/
static unsigned short
move_to(unsigned char x, unsigned char y, unsigned char* buf, unsigned short maxlen)
{
if (maxlen < 14) return 0;
return (unsigned short)sprintf((char*)buf, "\033[%d;%dH", y+1, x+1);
}
/*-----------------------------------------------------------------------------------*/
/** \internal
* Adds a attribute string to buffer. Returns 0 if string doesn't fit else
* number of bytes actually written is returned.
*
* \param c Color number
* \param buf Output buffer
* \param maxlen Maximum number of bytes to store in buffer
*/
/*-----------------------------------------------------------------------------------*/
static unsigned short
set_color(unsigned char c, unsigned char* buf, unsigned short maxlen)
{
int len = strlen((const char*)colortheme[c]);
if (maxlen < len) return 0;
memcpy(buf, colortheme[c], len);
return len;
}
/*-----------------------------------------------------------------------------------*/
/**
* Stores terminal data in buffer provided by caller. Returns number of bytes written
* to the output buffer.
*
* \param ts State information
* \param buf Output buffer
* \param maxlen Maximum number of bytes to store in buffer
*/
/*-----------------------------------------------------------------------------------*/
unsigned short
ctk_term_send(struct ctk_term_state* ts,
unsigned char* buf,
unsigned short maxlen)
{
unsigned char x, y, x0;
unsigned char col, c;
unsigned short tmp;
unsigned short totlen;
check_updates(ts);
if (ts->updates_current == NULL) return 0;
x0 = ts->x1;
col = ts->c1;
totlen = 0;
/* Loop across the update region starting at (x1,y1) */
for(y = ts->y1; y < ts->y + ts->h; ++y) {
for(x = x0; x < ts->x + ts->w; ++x) {
/* New line ? */
if (x == ts->x) {
/* Move cursor to start of line */
tmp = move_to(x,y,buf,maxlen);
if (tmp == 0) goto loopend;
buf += tmp;
totlen += tmp;
maxlen -= tmp;
}
/* Check color */
c = colorscreen[x + y * CHARS_WIDTH];
if (c != col) {
PRINTF(("colorchange at (%d, %d) to %d\n", x,y,c));
/* Send new color information */
tmp = set_color(c, buf, maxlen);
if (tmp == 0) goto loopend;
col = c;
buf += tmp;
totlen += tmp;
maxlen -= tmp;
}
/* Check remaining space */
if (maxlen < 1) goto loopend;
/* Add character */
*buf = screen[x + y * CHARS_WIDTH];
buf++;
maxlen--;
totlen++;
}
x0 = ts->x;
}
loopend:
/* Always save current color state */
ts->c2 = col;
PRINTF(("ending loop at (%d, %d)\n", x,y));
/* Check if done */
if (x == ts->x+ts->w && y == ts->y+ts->h) {
/* Signal done with this update */
ts->x2 = ts->y2 = 0;
}
else {
/* Not done. Save state */
ts->x2 = x;
ts->y2 = y;
}
return totlen;
}
/*-----------------------------------------------------------------------------------*/
/**
* Called by client when the data returned by ctk_term_send() are successfully sent.
*
* \param ts State information
*/
/*-----------------------------------------------------------------------------------*/
void ctk_term_sent(struct ctk_term_state* ts)
{
if (ts->updates_current != NULL) {
/* Check if current update done */
if (ts->x2 == 0 && ts->y2 == 0) {
/* Yes, free it */
ctk_term_update_free(ts, ts->updates_current);
ts->updates_current = NULL;
}
else {
/* Nop. Update start posititions */
ts->x1 = ts->x2;
ts->y1 = ts->y2;
}
ts->c1 = ts->c2;
}
}

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: ctk-term-out.h,v 1.1 2007/05/26 21:54:33 oliverschmidt Exp $
*/
#ifndef __CTK_TERM_OUT_H__
#define __CTK_TERM_OUT_H__
void
ctk_term_out_update_screen(unsigned char xpos,
unsigned char ypos,
unsigned char c,
unsigned char color);
#endif /* __CTK_TERM_OUT_H__ */

1028
backyard/core/ctk/ctk-term.c Normal file

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,46 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: ctk-term.h,v 1.1 2007/05/26 21:54:33 oliverschmidt Exp $
*/
#ifndef __CTK_TERM_H__
#define __CTK_TERM_H__
struct ctk_term_state* ctk_term_alloc_state(void);
void ctk_term_dealloc_state(struct ctk_term_state *s);
void ctk_term_redraw(struct ctk_term_state *s);
void ctk_term_sent(struct ctk_term_state* ts);
unsigned short ctk_term_send(struct ctk_term_state* ts,
unsigned char* buf,
unsigned short maxlen);
void ctk_term_input(struct ctk_term_state* ts, unsigned char b);
#endif /* __CTK_TERM_H__ */

View file

@ -0,0 +1,58 @@
/*
* Copyright (c) 2005, Swedish Institute of Computer Science
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* This file is part of the Contiki operating system.
*
* @(#)$Id: ctk-termarch.h,v 1.1 2007/05/26 21:54:33 oliverschmidt Exp $
*/
#ifndef __CTK_TERMARCH_H__
#define __CTK_TERMARCH_H__
typedef char ctk_arch_key_t;
unsigned char ctk_arch_keyavail(void);
ctk_arch_key_t ctk_arch_getkey(void);
#define CH_ENTER 0x0d
#define CH_DEL 0x08
#define CH_TAB 0x09
#define CH_CURS_LEFT 0x11
#define CH_CURS_UP 0x12
#define CH_CURS_RIGHT 0x13
#define CH_CURS_DOWN 0x14
#define CH_F1 0x15
#define CH_F2 0x16
#define CH_F3 0x17
#define CH_F4 0x18
#endif /* __CTK_TERMARCH_H__ */