1 //---------------------------------------------------------------------------
2 // Copyright (C) 2000 Dallas Semiconductor Corporation, All Rights Reserved.
3 //
4 // Permission is hereby granted, free of charge, to any person obtaining a
5 // copy of this software and associated documentation files (the "Software"),
6 // to deal in the Software without restriction, including without limitation
7 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 // and/or sell copies of the Software, and to permit persons to whom the
9 // Software is furnished to do so, subject to the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be included
12 // in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17 // IN NO EVENT SHALL DALLAS SEMICONDUCTOR BE LIABLE FOR ANY CLAIM, DAMAGES
18 // OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 // OTHER DEALINGS IN THE SOFTWARE.
21 //
22 // Except as contained in this notice, the name of Dallas Semiconductor
23 // shall not be used except as stated in the Dallas Semiconductor
24 // Branding Policy.
25 //---------------------------------------------------------------------------
26 //
27 // screenio.c - Utility functions for SHA iButton applications
28 //
29 // Version: 2.00
30 // History:
31 //
32
33 #include "ownet.h"
34
35 // Include files for the Palm and Visor
36 #ifdef __MC68K__
37 #include <PalmOS.h>
38 #include <Window.h>
39 #endif
40
41 // defines
42 #define MAXLINE 16
43
44 // External functions
45 extern void msDelay(int);
46
47 // local function prototypes
48 void output_status(int, char *);
49 void reset_screen(void);
50 int available_screen(int);
51 void ClearScreen(int);
52
53 // globals
54 int VERBOSE=0;
55
56 // keep track of line number on screen
57 int current_line = 0;
58
59 //--------------------------------------------------------------------------
60 // output status message
61 //
output_status(int level,char * st)62 void output_status(int level, char *st)
63 {
64 char *p;
65 static char linebuf[256];
66 static int cnt = 0;
67
68 // skip null strings
69 if (st[0] == 0)
70 return;
71
72 // check if in verbose mode
73 if ((level >= LV_ALWAYS) || VERBOSE)
74 {
75 // look for embedded \n
76 for (p = st; *p; p++)
77 {
78 if (*p == 0x0A || ((cnt>33) && (*p==' ')) || (*(p + 1) == 0))
79 {
80 // zero terminate the line
81 linebuf[cnt] = 0;
82
83 // print it out ???????? replace
84 #ifndef __MC68K__
85 printf("%s",linebuf);
86 #else
87 WinDrawChars(linebuf,StrLen(linebuf),5,10*current_line++);
88 #endif
89
90 // check if too many lines
91 if (current_line == MAXLINE)
92 reset_screen();
93 cnt = 0;
94 }
95 else
96 linebuf[cnt++] = *p;
97 }
98 }
99 }
100
101 //--------------------------------------------------------------------------
102 // check for available space on screen. Return 1 if available 0 otherwise
103 //
available_screen(int lines)104 int available_screen(int lines)
105 {
106 return !((current_line + lines) > MAXLINE);
107 }
108
109 //--------------------------------------------------------------------------
110 // reset the screen
111 //
reset_screen(void)112 void reset_screen(void)
113 {
114 // set lines back to zero
115 current_line = 0;
116
117 // reset screen
118 ClearScreen(0);
119
120 }
121
122
123 //------------------------------------------------------------------------
124 // Clears the screen on the palm device
125 //
ClearScreen(int row)126 void ClearScreen(int row)
127 {
128 #ifdef __MC68K__
129 int i;
130
131 for(i=row;i<16;i++)
132 WinDrawChars((char *) " ",80,5,i*10);
133 #endif
134 }
135
136