极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 33309|回复: 21

电视助手(android+arduino+webserver)

[复制链接]
发表于 2013-2-7 10:53:19 | 显示全部楼层 |阅读模式
本帖最后由 瘦网虫 于 2013-2-8 10:48 编辑

对家里的有线电视的遥控进行了下周边的改造。

现在改为直接通过手机控制有线电视机顶盒。手机端附加了功能:读取、显示节目单。

实现原理:

web服务器从网上抓取一周所有的电视节目表,根据手机端发送的请求发送。
手机端显示本地的有线电视台列表(从服务器端取来)和对应的台的节目表,根据个人喜好进行台的切换。
切换台使用arduino+enc28j60网络模块监听网络udp消息,收到手机发来的换台、调音量等消息时,通过红外发送给有线电视机顶盒。





程序为简陋原型,后期闲的话,可以增加额外功能,例如预订节目等。

不知道有没有共同爱好者对此感兴趣。

先发截图,后发程序,再后发使用视频,最后发布可以使用的源代码。

2楼更新了android手机端程序。
3楼更新了arduino代码。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

 楼主| 发表于 2013-2-7 10:54:55 | 显示全部楼层
本帖最后由 瘦网虫 于 2013-2-8 14:57 编辑

手机端截图,由于资源限制,只做了本地的有线电视台对应频道列表。
如果爱好者多的话,更新数据库就可以了。


频道列表以及该频道当前节目


当前所有台的节目列表



点击上面链接下载android手机客户端。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-2-7 11:02:00 | 显示全部楼层
本帖最后由 瘦网虫 于 2013-2-19 17:03 编辑




arduino端部分代码,自我觉得代码中有价值的部分就是发送有线电视控制信号部分。
发送 类型为unkown,长度为100的红外编码。



  1. #include <EtherCard.h>
  2. #include <IRremote.h>




  3. static byte mymac[] = {
  4.   0x74,0x69,0x69,0x2D,0x30,0x31};
  5. static byte myip[] = {
  6.   192,168,2,10};
  7. // gateway ip address
  8. static byte gwip[] = {
  9.   192,168,2,1 };
  10. static byte dnsip[] = {
  11.   192,168,2,1 };
  12. byte Ethernet::buffer[700];

  13. static uint32_t timer;
  14. #define gPB ether.buffer
  15. #define UDP_DP_HIGH 36
  16. #define UDP_DP_LOW 37
  17. #define DSTPORT_HIHG 0x26
  18. #define DSTPORT_LOW 0xe7
  19. Stash stash;

  20. const int CHANGE_CHANNEL = 1;
  21. const int CHANGE_VOLUME = 2;

  22. int cmd =0;
  23. int cmdValue =-32768;

  24. const int irReceiverPin = 7;
  25. int STATUS_PIN = 13;


  26. IRrecv irrecv(irReceiverPin); // 设置irReceiverPin定义的端口为红外信号接收端口
  27. decode_results results;    // 定义results变量为红外结果存放位置
  28. IRsend irsend;


  29. const int ledPin = 13;
  30. boolean ledStatus;

  31. char* on = "1";
  32. char* off = "0";
  33. char* statusLabel;
  34. char* buttonLabel;

  35. // Storage for the recorded code
  36. int codeType = -1; // The type of code
  37. unsigned long codeValue; // The code value if not raw
  38. unsigned int rawCodes[RAWBUF]; // The durations if raw
  39. unsigned int rawCodes_voldown[100] = {
  40.   3550 ,1850 ,300 ,400 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,1400 ,300 ,450 ,300 ,400 ,350 ,400 ,350 ,1400 ,300 ,400 ,350 ,1400 ,300 ,450 ,300 ,400 ,350 ,1400 ,300 ,1400 ,300 ,450 ,300 ,1400 ,300 ,450 ,300 ,450 ,300 ,450 ,300 ,400 ,350 ,1400 ,300 ,1400 ,300 ,450 ,300 ,1400 ,300 ,450 ,300 ,450 ,300 ,450 ,300 ,1400 ,350 ,1350 ,300 ,450 ,300 ,450 ,300 ,1400 ,300 ,450 ,300 ,1400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,1350 ,300 ,450 ,300
  41. };//checked
  42. unsigned int rawCodes_volup[100] = {
  43.   3600 ,1800 ,300 ,450 ,300 ,450 ,300 ,400 ,350 ,1400 ,300 ,450 ,300 ,400 ,350 ,1400 ,300 ,450 ,300 ,400 ,350 ,1400 ,300 ,1400 ,350 ,350 ,350 ,400 ,350 ,400 ,350 ,1400 ,300 ,450 ,300 ,1400 ,300 ,450 ,300 ,450 ,300 ,1400 ,300 ,1400 ,300 ,450 ,300 ,1400 ,300 ,450 ,300 ,450 ,300 ,450 ,300 ,450 ,300 ,1400 ,300 ,1400 ,300 ,450 ,300 ,1400 ,350 ,400 ,300 ,450 ,300 ,1400 ,350 ,400 ,300 ,450 ,300 ,1400 ,350 ,400 ,300 ,1400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,300 ,1400 ,350 ,400 ,350 ,400 ,300 ,1400 ,350 ,400 ,350
  44. };//checked
  45. unsigned int rawCodes_channelup[100] = {
  46.   3500 ,1850 ,300 ,450 ,250 ,500 ,250 ,500 ,250 ,1450 ,250 ,500 ,250 ,500 ,250 ,1450 ,250 ,500 ,250 ,500 ,250 ,1450 ,250 ,1450 ,300 ,450 ,300 ,450 ,250 ,500 ,250 ,1450 ,300 ,450 ,250 ,1450 ,300 ,450 ,300 ,450 ,250 ,1450 ,300 ,1450 ,250 ,450 ,300 ,1450 ,250 ,500 ,250 ,450 ,300 ,450 ,300 ,450 ,250 ,1450 ,300 ,1450 ,250 ,500 ,250 ,1450 ,250 ,500 ,250 ,1450 ,250 ,500 ,250 ,1450 ,250 ,500 ,250 ,1450 ,250 ,500 ,250 ,1450 ,250 ,500 ,250 ,500 ,250 ,500 ,250 ,500 ,250 ,500 ,250 ,1450 ,250 ,500 ,250 ,1450 ,250 ,500 ,250
  47. };//checked
  48. unsigned int rawCodes_channeldown[100] = {
  49.   3550 ,1850 ,300 ,450 ,300 ,400 ,350 ,400 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,1400 ,300 ,1400 ,300 ,450 ,300 ,450 ,300 ,400 ,350 ,1400 ,300 ,450 ,300 ,1400 ,300 ,450 ,300 ,450 ,300 ,1400 ,300 ,1400 ,300 ,450 ,300 ,1400 ,300 ,450 ,300 ,450 ,300 ,450 ,300 ,450 ,300 ,1400 ,300 ,1400 ,300 ,450 ,300 ,1400 ,300 ,450 ,300 ,450 ,300 ,450 ,300 ,1400 ,300 ,450 ,300 ,450 ,300 ,450 ,300 ,1400 ,300 ,450 ,300 ,1400 ,300 ,1400 ,300 ,1400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350
  50. };//checked
  51. unsigned int rawCodes_ok[100] = {
  52.   3500 ,1900 ,250 ,500 ,250 ,450 ,300 ,450 ,300 ,1450 ,250 ,450 ,300 ,450 ,300 ,1450 ,250 ,450 ,300 ,450 ,300 ,1450 ,250 ,1450 ,250 ,500 ,250 ,500 ,250 ,450 ,300 ,1450 ,250 ,500 ,250 ,1450 ,250 ,500 ,250 ,500 ,250 ,1450 ,250 ,1450 ,250 ,500 ,250 ,1450 ,250 ,500 ,250 ,500 ,250 ,500 ,250 ,500 ,250 ,1450 ,250 ,1450 ,250 ,500 ,250 ,1450 ,250 ,500 ,250 ,1450 ,250 ,500 ,250 ,1450 ,250 ,500 ,250 ,500 ,250 ,500 ,250 ,1450 ,250 ,500 ,250 ,500 ,250 ,1450 ,250 ,1450 ,300 ,1400 ,300 ,450 ,300 ,450 ,300 ,1400 ,300 ,450 ,300
  53. };//checked
  54. unsigned int rawCodes_num1[100] = {
  55.   3550 ,1800 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,1350 ,350 ,400 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,1400 ,300 ,400 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,1400 ,300 ,400 ,350 ,400 ,350
  56. };
  57. unsigned int rawCodes_num2[100] = {
  58.   3550 ,1850 ,300 ,400 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,1400 ,350 ,350 ,350 ,400 ,350 ,400 ,350 ,1400 ,300 ,400 ,350 ,1400 ,350 ,350 ,350 ,400 ,350 ,1400 ,350 ,1350 ,350 ,350 ,400 ,1350 ,350 ,350 ,400 ,350 ,400 ,350 ,350 ,400 ,350 ,1400 ,350 ,1350 ,350 ,350 ,400 ,1350 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,350 ,400 ,350 ,1400 ,350 ,1350 ,350 ,350 ,400 ,350 ,400 ,350 ,350 ,1400 ,350 ,350 ,400 ,350 ,350 ,1400 ,350 ,1350 ,350 ,350 ,400 ,350 ,400
  59. };
  60. unsigned int rawCodes_num3[100] = {
  61.   3600 ,1800 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,1350 ,350 ,350 ,400 ,350 ,400 ,1350 ,350 ,350 ,400 ,350 ,400 ,1350 ,350 ,1350 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,1350 ,350 ,350 ,400 ,1350 ,350 ,350 ,400 ,350 ,400 ,1350 ,350 ,1350 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,1350 ,350 ,1350 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,1350 ,350 ,1350 ,350 ,400 ,350 ,350 ,400 ,1350 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,1400 ,300 ,400 ,350 ,400 ,350
  62. };
  63. unsigned int rawCodes_num4[100] = {
  64.   3600 ,1800 ,350 ,350 ,350 ,400 ,350 ,400 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,1400 ,300 ,1400 ,350 ,350 ,400 ,350 ,350 ,400 ,350 ,1400 ,350 ,350 ,350 ,1400 ,350 ,350 ,400 ,350 ,350 ,1400 ,350 ,1350 ,350 ,350 ,400 ,1350 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,400 ,1350 ,350 ,1350 ,350 ,350 ,400 ,1350 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,350 ,1400 ,350 ,1350 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,350 ,1400 ,350 ,350 ,400 ,1350 ,350 ,1350 ,350 ,350 ,400 ,350 ,400
  65. };
  66. unsigned int rawCodes_num5[100] = {
  67.   3600 ,1800 ,350 ,350 ,400 ,350 ,400 ,350 ,350 ,1400 ,350 ,350 ,400 ,350 ,350 ,1400 ,350 ,350 ,400 ,350 ,350 ,1400 ,350 ,1350 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,1350 ,350 ,350 ,400 ,1350 ,350 ,350 ,400 ,350 ,400 ,1350 ,350 ,1350 ,350 ,350 ,400 ,1350 ,350 ,400 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,1350 ,350 ,1350 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,1350 ,350 ,1350 ,350 ,400 ,350 ,350 ,400 ,1350 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,1350 ,350 ,1400 ,300 ,400 ,350 ,400 ,350
  68. };
  69. unsigned int rawCodes_num6[100] = {
  70.   3600 ,1800 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,1350 ,350 ,350 ,400 ,350 ,350 ,1400 ,350 ,350 ,400 ,350 ,350 ,1400 ,350 ,1350 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,1350 ,350 ,350 ,400 ,1350 ,350 ,350 ,400 ,350 ,400 ,1350 ,350 ,1350 ,350 ,350 ,400 ,1350 ,350 ,400 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,1350 ,350 ,1350 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,1350 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,350 ,400 ,1350 ,350 ,1350 ,350 ,400 ,350 ,1350 ,350 ,1400 ,300 ,400 ,350 ,400 ,350
  71. };
  72. unsigned int rawCodes_num7[100] = {
  73.   3600 ,1800 ,350 ,350 ,350 ,400 ,350 ,400 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,1400 ,300 ,1400 ,350 ,350 ,400 ,350 ,350 ,400 ,350 ,1400 ,350 ,350 ,350 ,1400 ,350 ,350 ,400 ,350 ,350 ,1400 ,350 ,1350 ,350 ,350 ,400 ,1350 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,400 ,1350 ,350 ,1350 ,350 ,350 ,400 ,1350 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,350 ,1400 ,350 ,1350 ,350 ,350 ,400 ,350 ,400 ,1350 ,350 ,1350 ,350 ,1350 ,350 ,400 ,350 ,1350 ,350 ,1400 ,300 ,400 ,350 ,400 ,350
  74. };
  75. unsigned int rawCodes_num8[100] = {
  76.   3550 ,1850 ,300 ,400 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,1400 ,300 ,1400 ,350 ,350 ,400 ,1350 ,350 ,350 ,400 ,350 ,400 ,350 ,350 ,400 ,350 ,1400 ,350 ,1350 ,350 ,350 ,400 ,1350 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,350 ,400 ,350 ,1400 ,350 ,1350 ,350 ,350 ,400 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,1400 ,300 ,1400 ,350 ,1350 ,350 ,350 ,400 ,350 ,400
  77. };
  78. unsigned int rawCodes_num9[100] = {
  79.   3550 ,1800 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,1400 ,300 ,1400 ,350 ,350 ,350 ,1400 ,350 ,350 ,400 ,350 ,350 ,400 ,350 ,400 ,350 ,1400 ,300 ,1400 ,350 ,350 ,400 ,1350 ,350 ,350 ,400 ,350 ,400 ,350 ,350 ,400 ,350 ,400 ,350 ,1400 ,300 ,1400 ,350 ,350 ,400 ,350 ,350 ,1400 ,350 ,350 ,400 ,350 ,350 ,1400 ,350 ,1350 ,350 ,1350 ,350 ,350 ,400 ,350 ,400
  80. };
  81. unsigned int rawCodes_num0[100] = {
  82.   3550 ,1800 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,350 ,350 ,1400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,400 ,300 ,1400 ,350 ,400 ,350 ,1350 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,1350 ,350 ,400 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,1350 ,350 ,1400 ,300 ,400 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,400 ,300 ,1400 ,350 ,1400 ,300 ,400 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,350 ,400 ,1350 ,350 ,1350 ,350 ,400 ,350 ,400 ,350
  83. };unsigned int rawCodes_invalid[100] = {
  84.   3550 ,1800 ,350 ,350 ,350 ,350 ,350 ,400 ,350 ,1350 ,350 ,350 ,350 ,350 ,350 ,1350 ,350 ,350 ,350 ,350 ,350 ,1400 ,350 ,1350 ,350 ,350 ,350 ,400 ,350 ,400 ,300 ,1400 ,350 ,400 ,350 ,1350 ,350 ,350 ,350 ,400 ,350 ,1350 ,350 ,1350 ,350 ,400 ,350 ,1400 ,300 ,400 ,350 ,350 ,350 ,350 ,350 ,350 ,350 ,1350 ,350 ,1400 ,300 ,400 ,350 ,1400 ,300 ,400 ,350 ,350 ,350 ,350 ,350 ,400 ,350 ,400 ,300 ,1400 ,350 ,1400 ,300 ,400 ,350 ,350 ,350 ,400 ,350 ,400 ,350 ,400 ,350 ,350 ,400 ,1350 ,350 ,1350 ,350 ,400 ,350 ,400 ,350
  85. };

  86. //assign IR code in the map
  87. unsigned int* codeMap[50] =
  88. {
  89.   //codeMap0-9
  90.   rawCodes_num0,rawCodes_num1,rawCodes_num2,rawCodes_num3,rawCodes_num4,rawCodes_num5,rawCodes_num6,rawCodes_num7,rawCodes_num8,rawCodes_num9,
  91.   rawCodes_channelup,//codeMap[10]
  92.   rawCodes_channeldown,//codeMap[11]
  93.   rawCodes_volup,//codeMap[12]
  94.   rawCodes_voldown,//codeMap[13]
  95.   rawCodes_ok,//codeMap[14]
  96.   rawCodes_invalid//codeMap[15]
  97. };
  98. //unsigned int* (*codeMap)[5]={rawCodes_num0,rawCodes_num1};

  99. int codeLen; // The length of the code
  100. int toggle = 0; // The RC5/6 toggle state
  101. boolean dnsStatus = false;

  102. int lastButtonState;
  103. String cmdUrl;



  104. void setup () {

  105.   Serial.begin(9600);   // 开启串口,波特率为9600
  106.   irrecv.enableIRIn();   // 启动红外解码

  107.   pinMode(STATUS_PIN, OUTPUT);
  108. //  attachInterrupt(INT_NUM,handleCommand,CHANGE);

  109.   if (!ether.begin(sizeof Ethernet::buffer, mymac, 53))
  110.     Serial.println( "Failed to access Ethernet controller");
  111.   else
  112.     Serial.println("Ethernet controller initialized");


  113.   if (!ether.staticSetup(myip, gwip,dnsip))
  114.     Serial.println("Failed to set IP address");

  115.   //  if (!ether.dhcpSetup())
  116.   //    Serial.println("DHCP failed");

  117.   ether.printIp("IP:  ", ether.myip);
  118.   ether.printIp("GW:  ", ether.gwip);  
  119.   ether.printIp("DNS: ", ether.dnsip);  
  120.   Serial.println();

  121.   pinMode(ledPin, OUTPUT);
  122.   digitalWrite(ledPin, LOW);
  123.   ledStatus = false;
  124. }





  125. void loop() {


  126.   if(!dnsStatus)
  127.   {
  128.     if (!ether.dnsLookup(website))
  129.       Serial.println("DNS failed");
  130.     else dnsStatus = true;
  131.     ether.printIp("SRV: ", ether.hisip);
  132.   }

  133.   word len = ether.packetReceive();
  134.   word pos = ether.packetLoop(len);


  135.   if (millis() > timer) {
  136.     timer = millis() + 10000;
  137.     Serial.println();




  138.   if(len)
  139.   {
  140.     if(gPB[IP_PROTO_P]==IP_PROTO_UDP_V)
  141.     {
  142.       if((gPB[UDP_DP_HIGH]==DSTPORT_HIHG)&&(gPB[UDP_DP_LOW]==DSTPORT_LOW))
  143.       {
  144.         Serial.println("---Received an udp 9959 packet---");
  145.         Serial.println((char *)gPB+42);
  146.         String cmdUrl =(char *)gPB+42;
  147.         cmd = getCmdValue(cmdUrl,"cmd");
  148.         cmdValue = getCmdValue(cmdUrl,"value");
  149.         if(cmd > 0)
  150.         {
  151.           handleCommand(cmd);
  152.         }
  153.         
  154.       }
  155.     }
  156.   }


  157.   if (irrecv.decode(&results)) {   // 解码成功,把数据放入results变量中
  158.     // 把数据输入到串口
  159.     Serial.print("irCode: ");            
  160.     Serial.print(results.value, HEX); // 显示红外编码
  161.     Serial.print(",  bits: ");           
  162.     Serial.println(results.bits); // 显示红外编码位数

  163.     //    digitalWrite(ledPin,HIGH);//LED点亮
  164.     //    delay(10);
  165.     //    digitalWrite(ledPin,LOW);//LED熄灭

  166.     irrecv.resume();    // 继续等待接收下一组信号
  167.     //    irsend.sendRC6(0x30D0000A, 32);
  168.     //    delay(10);
  169.     //    irsend.sendRC6(0x30D0000A, 32);
  170.   }  

  171. }


  172. void changeChannel(int chnId)
  173. {
  174. int chnDigi = 0;
  175. for(int i = 100;i>0.1;i=i/10)
  176. {
  177. chnDigi = chnId/i;   
  178. remoterKeyPress(chnDigi,2);
  179. //send invalid code between each key press  
  180. irsend.sendNEC(0xFFFFFFFF, 32);

  181.   chnId = chnId % i;
  182. }
  183. remoterKeyPress(14,1);
  184. }


  185. void remoterKeyPress(int mapId,int times)
  186. {
  187.   for (int i = 0;i<times;i++)
  188.   {
  189.     irsend.sendRaw(codeMap[mapId], 100, 38);
  190.     delay(40);
  191.     Serial.println("Key Pressed");
  192.     Serial.println(mapId);
  193.   }
  194. }

  195. int getCmdValue(String str,char* cmd)
  196. {
  197.   if(str.indexOf(cmd) == -1)
  198.   {
  199.     return cmdValue;
  200.   }
  201.   String temp = str.substring(str.indexOf(cmd)+strlen(cmd)+1);
  202.   if(temp.indexOf("&") > 0 )
  203.   {
  204.     cmdValue = temp.substring(0,temp.indexOf("&")).toInt();
  205.   }
  206.   else
  207.   {
  208.     cmdValue = temp.toInt();
  209.   }
  210.   return cmdValue;
  211. }

  212. void handleCommand(int cmd)
  213. {
  214.   Serial.println("\n command requested..!");
  215.     switch (cmd)
  216.     {
  217.     case CHANGE_CHANNEL:
  218.       if(cmdValue > 0 )
  219.       {
  220.         changeChannel(cmdValue);
  221.       }
  222.       break;
  223.     case CHANGE_VOLUME:
  224.       if(cmdValue> 0 )
  225.       {
  226.         irsend.sendRaw(rawCodes_volup, 100, 38);
  227.         Serial.println("-------volume up---------");
  228.       }
  229.       else
  230.       {
  231.         irsend.sendRaw(rawCodes_voldown, 100, 38);
  232.         Serial.println("-------volume down---------");
  233.       }
  234.       break;
  235.     }
  236.     cmd = 0;
  237. }


  238. void sendCode(int repeat) {
  239.   if (codeType == NEC) {
  240.     if (repeat) {
  241.       irsend.sendNEC(REPEAT, codeLen);
  242.       Serial.println("Sent NEC repeat");
  243.     }
  244.     else {
  245.       irsend.sendNEC(codeValue, codeLen);
  246.       Serial.print("Sent NEC ");
  247.       Serial.println(codeValue, HEX);
  248.     }
  249.   }
  250.   else if (codeType == SONY) {
  251.     irsend.sendSony(codeValue, codeLen);
  252.     Serial.print("Sent Sony ");
  253.     Serial.println(codeValue, HEX);
  254.   }
  255.   else if (codeType == RC5 || codeType == RC6) {
  256.     if (!repeat) {
  257.       // Flip the toggle bit for a new button press
  258.       toggle = 1 - toggle;
  259.     }
  260.     // Put the toggle bit into the code to send
  261.     codeValue = codeValue & ~(1 << (codeLen - 1));
  262.     codeValue = codeValue | (toggle << (codeLen - 1));
  263.     if (codeType == RC5) {
  264.       Serial.print("Sent RC5 ");
  265.       Serial.println(codeValue, HEX);
  266.       irsend.sendRC5(codeValue, codeLen);
  267.     }
  268.     else {
  269.       irsend.sendRC6(codeValue, codeLen);
  270.       Serial.print("Sent RC6 ");
  271.       Serial.println(codeValue, HEX);
  272.     }
  273.   }
  274.   else if (codeType == UNKNOWN /* i.e. raw */) {
  275.     // Assume 38 KHz
  276.     //    irsend.sendRaw(rawCodes, codeLen, 38);
  277.     irsend.sendRaw(rawCodes_volup, 100, 38);
  278.     Serial.println("Sent raw");
  279.   }
  280. }


复制代码

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

评分

参与人数 1 +3 收起 理由
幻生幻灭 + 3 加油!

查看全部评分

回复 支持 反对

使用道具 举报

发表于 2013-2-7 11:15:05 | 显示全部楼层
好东西,感谢楼主分享。
回复 支持 反对

使用道具 举报

发表于 2013-2-7 14:45:24 | 显示全部楼层
这个有意思,红外能控制空调我感兴趣,或者直接控制继电器,带一些东西。
回复 支持 反对

使用道具 举报

发表于 2013-2-7 14:46:59 | 显示全部楼层
感觉智能手机还是不应该取消红外这个外设,有没有直接usb的红外发射器,接到手机上面直接用更方便。
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-2-7 14:49:02 | 显示全部楼层
laoliu1982 发表于 2013-2-7 14:46
感觉智能手机还是不应该取消红外这个外设,有没有直接usb的红外发射器,接到手机上面直接用更方便。

按照我的猜想,手机的耳机插孔直接接红外发射应该有可能实现。
等有空来做个测试。
回复 支持 反对

使用道具 举报

发表于 2013-2-7 17:14:16 | 显示全部楼层
瘦网虫 发表于 2013-2-7 14:49
按照我的猜想,手机的耳机插孔直接接红外发射应该有可能实现。
等有空来做个测试。

这个有成功案例,只是自己测试老不成功,毕竟红外式工作在40kzh ,而音频最高为20kzh
回复 支持 反对

使用道具 举报

发表于 2013-2-7 17:23:55 | 显示全部楼层
最近也在玩红外,刚开始入门

楼主思路很好,要是能将数据保存在姜工的服务器上就好了。
回复 支持 反对

使用道具 举报

发表于 2013-2-8 02:09:13 | 显示全部楼层
yyy_zc 发表于 2013-2-7 17:14
这个有成功案例,只是自己测试老不成功,毕竟红外式工作在40kzh ,而音频最高为20kzh

。。红外的东西不都是开关信号吗。。什么频率的都不是重点吧
回复 支持 反对

使用道具 举报

 楼主| 发表于 2013-2-8 10:53:09 | 显示全部楼层
幻生幻灭 发表于 2013-2-7 17:23
最近也在玩红外,刚开始入门

楼主思路很好,要是能将数据保存在姜工的服务器上就好了。

数据是公开的(数据来源:搜视网http://epg.tvsou.com/),现在还是程序原型阶段,放服务器担心把它拖死了,自己在互联网上临时架设了个服务器,呵呵。

另,姜工服务器是什么?
回复 支持 反对

使用道具 举报

发表于 2013-2-8 20:13:24 | 显示全部楼层
http://www.yeelink.net/

据姜工说可以,但我没弄过
回复 支持 反对

使用道具 举报

发表于 2013-2-8 22:46:31 | 显示全部楼层
好东西。万恶的广电部把机顶盒弄成了封闭系统,不能联网。
回复 支持 反对

使用道具 举报

发表于 2013-2-10 12:55:01 | 显示全部楼层
这个太屌了 我得mark一下
回复 支持 反对

使用道具 举报

发表于 2013-2-10 13:31:23 | 显示全部楼层
我用的机顶盒都是安卓系统
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-14 03:22 , Processed in 0.054565 second(s), 27 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表