net_radio_jap.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pigpio.h>
#include <unistd.h>
int inPin = 27;//Physical 13
int level;
int p_count = 1;
int flag = 0;
char i_c = '0';
char stringCom[12] = "mpc play 1";
char stringComStop[10] = "mpc stop";
int stringDat[9];
int stringDatCount[52];
int i = 0;
uint32_t tick;
uint32_t startTick;
uint32_t endTick;
uint32_t diffTick;
int count = 0;
int start = 0;
int last = 0;
int res = 0;
int ad1 = 0;
int ad2 = 0;
int da1 = 0;
int da2 = 0;
int resU = 0;
int decode (int da1)
{
flag = 1;
switch (da1)
{
case 5 : {//AUX
p_count = 1;
}
break;
case 6 : {//A.TAPE
p_count = 1;
}
break;
case 10 : {//PLAY
p_count = 1;
flag = 1;
}
break;
case 0 : {//STOP
system (stringComStop);
flag = 0;
}
break;
case 61 : {//OFF
system (stringComStop);
flag = 0;
}
break;
case 52 : p_count ++;//RIGHT ARROW
break;
case 53 : p_count --;//LEFT ARROW
break;
case 16: {//1
p_count = 1;
}
break;
case 17: {//2
p_count = 2;
}
break;
case 18: {//3
p_count = 3;
}
break;
case 19: {//4
p_count = 4;
}
break;
case 20: {//5
p_count = 5;
}
break;
case 21: {//6
p_count = 6;
}
break;
case 22: {//7
p_count = 7;
}
break;
case 23: {//8
p_count = 8;
}
break;
case 24: {//9
p_count = 9;
}
break;
default: {
flag = 0;
return 0;
}
}
if (flag == 1)
{
if (p_count > 9)
{
p_count = 1;
}
if (p_count < 1)
{
p_count = 9;
}
i_c = p_count + 48;//int to char max 9
stringCom[9] = i_c;
system (stringCom);
}
return 0;
}
void func (int gpio, int level, uint32_t tick;)
{
endTick = gpioTick();
diffTick = endTick - startTick;
// printf ("GPIO %d became %d at %d \n ", inPin, level, diffTick);
if (count > 0 && diffTick > 50000)//test for bad reception
{
count = 0;
}
startTick = gpioTick();
if (diffTick > 4000 && diffTick < 5000)
count = 0;
if (diffTick < 2000)
count ++;
if (diffTick > 1250)
{
stringDatCount[count] = 1;
}
else
{
stringDatCount[count] = 0;
}
if (count > 47)
{
// printf ("count 48 %d \n ",count);
// for (i = 1; i < 49; i++ )
// printf (" bit %d \n ", stringDatCount[i]);
count = 0;
res = 0;
for (i = 1; i < 49; i++)
{
switch (i)
{
case 17 : res = stringDatCount[i] * 0;
break;
case 18 : res = res + (stringDatCount[i] * 0);
break;
case 19 : res = res + (stringDatCount[i] * 0);
break;
case 20 : res = res + (stringDatCount[i] * 0);
break;
case 21 : res = res + (stringDatCount[i] * 1);
break;
case 22 : res = res + (stringDatCount[i] * 2);
break;
case 23 : res = res + (stringDatCount[i] * 4);
break;
case 24 : {res = res + (stringDatCount[i] * 8);
ad1 = res;}
break;
case 25 : res = stringDatCount[i] * 1;
break;
case 26 : res = res + (stringDatCount[i] * 2);
break;
case 27 : res = res + (stringDatCount[i] * 4);
break;
case 28 : res = res + (stringDatCount[i] * 8);
break;
case 29 : res = res + (stringDatCount[i] * 16);
break;
case 30 : res = res + (stringDatCount[i] * 32);
break;
case 31 : res = res + (stringDatCount[i] * 64);
break;
case 32 : {res = res + (stringDatCount[i] * 128);
ad2 = res; res = 0;}
break;
case 33 : res = stringDatCount[i] * 1;
break;
case 34 : res = res + (stringDatCount[i] * 2);
break;
case 35 : res = res + (stringDatCount[i] * 4);
break;
case 36 : res = res + (stringDatCount[i] * 8);
break;
case 37 : res = res + (stringDatCount[i] * 16);
break;
case 38 : res = res + (stringDatCount[i] * 32);
break;
case 39 : res = res + (stringDatCount[i] * 64);
break;
case 40 : {res = res + (stringDatCount[i] * 128);
da1 = res; res = 0;}
break;
case 41 : res = stringDatCount[i] * 1;
break;
case 42 : res = res + (stringDatCount[i] * 2);
break;
case 43 : res = res + (stringDatCount[i] * 4);
break;
case 44 : res = res + (stringDatCount[i] * 8);
break;
case 45 : res = res + (stringDatCount[i] * 16);
break;
case 46 : res = res + (stringDatCount[i] * 32);
break;
case 47 : res = res + (stringDatCount[i] * 64);
break;
case 48 : {res = res + (stringDatCount[i] * 128);
da2 = res;}
break;
}
resU = (da1 + (128 - ad2) + (ad1 - 8) * 16) - da2;
}
// printf ("Resultat %d %d %d %d %d\n ", ad1, ad2, da1, da2, resU);
if (resU == 0)//test for bad reception
decode (da1);
}
}
void main (void)
{
count = 0;
int cfg = gpioCfgGetInternals();
cfg |= PI_CFG_NOSIGHANDLER; // (1<<10)
gpioCfgSetInternals(cfg);
int status = gpioInitialise();
if (gpioInitialise() < 0)
startTick = gpioTick();
gpioSetMode (inPin, PI_INPUT);
gpioSetISRFunc (inPin, FALLING_EDGE, 0, func);
while (1){
sleep (0.01);
}
gpioTerminate();
}
Compile med: gcc -o net_radio_jap net_radio_jap.c -lpigpio
, pigpio se http://abyz.me.uk/rpi/pigpio/download.html
Bemærk:
dette er ekspermentel software der er ingen garanti for brugbarhed, det
kan derimod sandsynligvis være skadeligt, kun til brug i Danmark.