pirblaster
0.01
Use the pi as a remote control for your TV, DVD player etc.
Main Page
Files
File List
Globals
Blast
InitCarrier_main.c
Go to the documentation of this file.
1
/********************************************************************************/
2
/* Use a raspberry pi with a IR led as remote control for your Tv, Dvd etc. */
3
/* Copyright (C) 2016 Ed Kapitein */
4
/* */
5
/* This program is free software: you can redistribute it and/or modify */
6
/* it under the terms of the GNU General Public License as published by */
7
/* the Free Software Foundation, either version 3 of the License, or */
8
/* (at your option) any later version. */
9
/* */
10
/* This program is distributed in the hope that it will be useful, */
11
/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
12
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
13
/* GNU General Public License for more details. */
14
/* */
15
/* You should have received a copy of the GNU General Public License */
16
/* along with this program. If not, see <http://www.gnu.org/licenses/>. */
17
/********************************************************************************/
18
#include "../Common/Common.h"
19
#include "../Blast/Blast.h"
20
#include "../Kmod/Kmod.h"
21
#include <stdio.h>
22
#include <stdlib.h>
23
31
int
main
(
int
argc,
char
*argv[])
32
{
33
int
DutyCycle;
34
int
Divisor=4096;
35
int
Range=1024;
36
int
x;
37
int
y;
38
float
HwClock=
HwClockFreq
;
39
float
Delta;
40
float
BestMatch;
41
float
SollFreq;
42
float
IstFreq;
43
44
if
( argc != 3 )
45
{
46
fprintf( stderr,
"201608202109 Please provide me with 2 parameters:\n"
);
47
fprintf( stderr,
"201608202109 Freq and DutyCycle -eq 56 30\n"
);
48
return
(-1);
49
}
50
51
if
( atoi(argv[1]) < 10 || atoi(argv[1]) > 90 )
52
{
53
fprintf( stderr,
"201608202110 The frequency should be between 10 and 90.\n"
);
54
fprintf( stderr,
"201608202110 Change this file if that is not true\n"
);
55
return
(-1);
56
}
57
58
if
( atoi(argv[2]) < 10 || atoi(argv[2]) > 90 )
59
{
60
fprintf( stderr,
"201608202110 The DutyCycle should be between 10 and 90.\n"
);
61
fprintf( stderr,
"201608202110 Change this file if that is not true\n"
);
62
return
(-1);
63
}
64
65
SollFreq=atoi(argv[1]);
66
DutyCycle=atoi(argv[2]);
67
68
BestMatch= 256 * HwClock;
/* to make sure the first Match is better than this one */
69
for
(x=10; x < 4095; x++)
/* Divisor, not starting at 0 to stay clear of the min and max values */
70
{
71
y=1024;
72
IstFreq = 256 * HwClock / x / y;
/* TODO since y is fixed, x can be calculated, no need for the for loop */
73
Delta=SollFreq - IstFreq;
74
75
if
( Delta < 0)
/* abs for a uint32_t */
76
{
77
Delta=Delta * -1;
78
}
79
80
if
( Delta < BestMatch )
/* Save the values if the resulting frequency is closer to the desired */
81
{
82
Divisor=x;
83
Range=y;
84
BestMatch=Delta;
85
}
86
}
87
88
InitCarrier
( Range, Divisor, DutyCycle );
89
90
return
(0);
91
}
InitCarrier
int InitCarrier(int Range, int Divisor, int DutyCycle)
Wrapper to ioctl.
Definition:
InitCarrier.c:33
HwClockFreq
#define HwClockFreq
Definition:
Kmod.h:27
main
int main(int argc, char *argv[])
Routine to set Frequency and DutyCycle.
Definition:
InitCarrier_main.c:31
Generated on Sun Oct 2 2016 22:23:06 for pirblaster by
1.8.10