Hubo Library

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
SFKS2B1.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <string>
3 #include <unistd.h>
4
5 #include "../hubolib.h"
6
7 using namespace HuboLib;
8 using namespace BCM2835;
9
10
11 /*
12 Compile and link:
13 g++ SFKS2B1.cpp -L../ -lhubo -lpthread -lrt -o SFKS2B1.out
14 Run:
15 sudo ./SFKS2B1.out
16 Purpose:
17 The demo rings the SilverCrest SFKS2B1 433MHz door bell.
18 */
19
20
21 const char* g_pCode = "ADCBADADADCBCBCBADADADADADADCBCBCBCBADADCEADCE";
22
23 class CCode
24 {
25 public :
26 CCode (unsigned short time, unsigned char signal)
27 {
28 m_time = time;
29 m_signal = signal;
30 }
31
32 public :
33 unsigned short m_time;
34 unsigned char m_signal;
35 };
36
37
38 CCode A( 365, 1);
39 CCode B( 385, 0);
40 CCode C(1095, 1);
41 CCode D(1120, 0);
42 CCode E(4405, 0);
43
44
45 void SendDatagram (unsigned short pin);
46 void BoostThreadPriority();
47
48
49 int main(int argc, char *argv[])
50 {
51 if (!BCM2835::IsGPIOInitialized ())
52 {
53 printf ("GPIO not properly initialized. Are you running the program as sudoer?\n");
54 return -1;
55 }
56
57 // Define the pin we will use for bit banging as output.
58 unsigned short transmit_pin = 17; // BCM GPIO=17 = GPIO0 = Raspi pinheader 11
59 FunctionSelectPin(transmit_pin, Output);
60
61 // Lift the priority of the thread in order to allow for a precise time keeping during bit banging.
62 BoostThreadPriority();
63
64 // The minimum of datagrams to repeat is around 2.
65 // Let's send it 10 times to be on the save side.
66 // The transmitter of the bell sends it around 100 times.
67 for (int i=0; i<10; i++)
68 {
69 SendDatagram(transmit_pin);
70 }
71
72 return 0;
73 }
74
75
76 void SendDatagram (unsigned short pin)
77 {
78 const char* pBuffer = g_pCode;
79 while (*pBuffer)
80 {
81 switch (*pBuffer)
82 {
83 case 'A' : WritePin (pin, A.m_signal);
84 Delay_MicroSeconds((unsigned long) A.m_time);
85 break;
86 case 'B' : WritePin (pin, B.m_signal);
87 Delay_MicroSeconds((unsigned long) B.m_time);
88 break;
89 case 'C' : WritePin (pin, C.m_signal);
90 Delay_MicroSeconds((unsigned long) C.m_time);
91 break;
92 case 'D' : WritePin (pin, D.m_signal);
93 Delay_MicroSeconds((unsigned long) D.m_time);
94 break;
95 case 'E' : WritePin (pin, E.m_signal);
96 Delay_MicroSeconds((unsigned long) E.m_time);
97 break;
98 default:
99 printf ("Error - unknown code\n");
100 return;
101 }
102 pBuffer++;
103 }
104 }
105
106 #include <pthread.h>
107 #include <assert.h>
108 void BoostThreadPriority()
109 {
110 // Scheduling params.
111 sched_param param;
112 int policy;
113 int ret;
114 pthread_t threadHandle = pthread_self();
115
116 // Get current scheduling parameters of thread.
117 ret = pthread_getschedparam (threadHandle, &policy, &param);
118 assert (ret == 0);
119
120 // Set scheduling parameters of thread to real time values (FIFO scheduling type and max prio).
121 policy = SCHED_FIFO; // SCHED_RR;
122 param.sched_priority = sched_get_priority_max(policy); // New max priority for new scheduling concept.
123 ret = pthread_setschedparam(threadHandle, policy, &param);
124 assert (ret == 0);
125 }
126
127
BCM2835::Output
Definition: hubolib.h:918
A
CCode A(365, 1)
HuboLib::Delay_MicroSeconds
void Delay_MicroSeconds(unsigned long delay_micros)
delays the execution of the calling thread for the given number of micro seconds. ...
BCM2835::IsGPIOInitialized
bool IsGPIOInitialized()
Returns the status of the initialisation of the GPIO part of the library.
BoostThreadPriority
void BoostThreadPriority()
Definition: SFKS2B1.cpp:108
E
CCode E(4405, 0)
B
CCode B(385, 0)
C
CCode C(1095, 1)
main
int main(int argc, char *argv[])
Definition: SFKS2B1.cpp:49
CCode
Definition: MD17177.cpp:23
BCM2835::FunctionSelectPin
void FunctionSelectPin(unsigned char pin, FunctionSelectType mode)
Use FunctionSelect() to configure the mode of a BCM2835 pin.
SendDatagram
void SendDatagram(unsigned short pin)
Definition: SFKS2B1.cpp:76
CCode::m_time
unsigned short m_time
Definition: MD17177.cpp:33
CCode::m_signal
unsigned char m_signal
Definition: MD17177.cpp:34
BCM2835::WritePin
void WritePin(unsigned char pin, unsigned char value)
Sets or clears a pin configured to be an output.
D
CCode D(1120, 0)
BCM2835
Definition: hubocfg.h:71
g_pCode
const char * g_pCode
Definition: SFKS2B1.cpp:21
CCode::CCode
CCode(unsigned short time, unsigned char signal)
Definition: SFKS2B1.cpp:26
HuboLib
Definition: hubocfg.h:10