PropWare
C++ objects and CMake build system for Parallax Propeller
Home
Download
Getting Started
Documentation
Reference
About
Related Links
Namespace List
Class List
File List
Examples
Build System
File List
File Members
propsideworkspace
Propeller GCC Demos
sidetv
TvDriver.c
1
/*
2
# #########################################################
3
# This file demonstrates starting and running a PASM TV
4
# driver that interacts with the C stdio library.
5
#
6
# Written by Eric R. Smith
7
# Copyright (c) 2011 Parallax, Inc.
8
# MIT Licensed
9
# #########################################################
10
*/
11
12
#include <stdio.h>
13
#include <stdlib.h>
14
#include <sys/driver.h>
15
#include <compiler.h>
16
#include <errno.h>
17
#include "TvText.h"
18
19
/* default pin for TV */
20
int
_tvpin = 12;
21
static
int
users = 0;
22
23
const
char
TvPrefix[] =
"TV:"
;
24
25
/*
26
* hook called by fopen while setting up the file descriptor fp
27
* "str" is the file name (excluding driver prefix) passed to fopen
28
* we could use that to control various parameters, like the pin
29
* used
30
*/
31
int
32
Tv_fopen(FILE *fp,
const
char
*str,
const
char
*mode)
33
{
34
if
(*str)
35
{
36
_tvpin = atoi(str);
37
}
38
if
(users == 0) {
39
/* need to start the cog */
40
if
(tvText_start(_tvpin) == 0) {
41
errno = EACCES;
/* indicate failure to run */
42
return
-1;
43
}
44
}
45
/* keep track of how many open file handles use this cog */
46
++users;
47
return
0;
48
}
49
50
/*
51
* close a TV file
52
* when there are no more TV files open, shut down the associated cog
53
*/
54
int
55
Tv_fclose(FILE *fp)
56
{
57
if
(users > 0)
58
{
59
--users;
60
if
(users == 0)
61
tvText_stop();
62
}
63
return
0;
64
}
65
66
int
67
Tv_write(FILE *fp,
unsigned
char
*buf,
int
count)
68
{
69
int
i;
70
int
c;
71
for
(i = 0; i < count; i++)
72
{
73
c = buf[i];
74
tvText_outchar(c);
75
}
76
return
count;
77
}
78
79
_Driver TvDriver =
80
{
81
TvPrefix,
82
Tv_fopen,
83
Tv_fclose,
84
_null_read,
85
Tv_write,
86
NULL,
/* seek; not applicable */
87
NULL,
/* remove; not applicable */
88
};
89
90
/*
91
+--------------------------------------------------------------------
92
¦ TERMS OF USE: MIT License
93
+--------------------------------------------------------------------
94
Permission is hereby granted, free of charge, to any person obtaining
95
a copy of this software and associated documentation files
96
(the "Software"), to deal in the Software without restriction,
97
including without limitation the rights to use, copy, modify, merge,
98
publish, distribute, sublicense, and/or sell copies of the Software,
99
and to permit persons to whom the Software is furnished to do so,
100
subject to the following conditions:
101
102
The above copyright notice and this permission notice shall be
103
included in all copies or substantial portions of the Software.
104
105
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
106
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
107
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
108
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
109
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
110
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
111
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
112
+------------------------------------------------------------------
113
*/
Generated on Sat Aug 27 2016 00:58:10 for PropWare by
1.8.12