Subversion Repositories HomeAutomation

Rev

Rev 1514 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. #include "sns_input.h"
  3. uint8_t pinStatus[8];
  4. #define HIGH    1
  5. #define LOW 2
  6. #define NOCHANGE 0 
  7. void sns_input_pcint_callback(uint8_t id, uint8_t status)
  8. {
  9. #ifdef  sns_input_CH0
  10.     if (id == sns_input_PCINT_CH0) {
  11.       if (0 != status) {
  12.         pinStatus[0] = HIGH;
  13.       } else {
  14.         pinStatus[0] = LOW;
  15.       }
  16.     }
  17. #endif
  18. #ifdef  sns_input_CH1
  19.     if (id == sns_input_PCINT_CH1) {
  20.       if (0 != status) {
  21.         pinStatus[1] = HIGH;
  22.       } else {
  23.         pinStatus[1] = LOW;
  24.       }
  25.     }
  26. #endif
  27. #ifdef  sns_input_CH2
  28.     if (id == sns_input_PCINT_CH2) {
  29.       if (0 != status) {
  30.         pinStatus[2] = HIGH;
  31.       } else {
  32.         pinStatus[2] = LOW;
  33.       }
  34.     }
  35. #endif
  36. #ifdef  sns_input_CH3
  37.     if (id == sns_input_PCINT_CH3) {
  38.       if (0 != status) {
  39.         pinStatus[3] = HIGH;
  40.       } else {
  41.         pinStatus[3] = LOW;
  42.       }
  43.     }
  44. #endif
  45. #ifdef  sns_input_CH4
  46.     if (id == sns_input_PCINT_CH4) {
  47.       if (0 != status) {
  48.         pinStatus[4] = HIGH;
  49.       } else {
  50.         pinStatus[4] = LOW;
  51.       }
  52.     }
  53. #endif
  54. #ifdef  sns_input_CH5
  55.     if (id == sns_input_PCINT_CH5) {
  56.       if (0 != status) {
  57.         pinStatus[5] = HIGH;
  58.       } else {
  59.         pinStatus[5] = LOW;
  60.       }
  61.     }
  62. #endif
  63. #ifdef  sns_input_CH6
  64.     if (id == sns_input_PCINT_CH6) {
  65.       if (0 != status) {
  66.         pinStatus[6] = HIGH;
  67.       } else {
  68.         pinStatus[6] = LOW;
  69.       }
  70.     }
  71. #endif
  72. #ifdef  sns_input_CH7
  73.     if (id == sns_input_PCINT_CH7) {
  74.       if (0 != status) {
  75.         pinStatus[7] = HIGH;
  76.       } else {
  77.         pinStatus[7] = LOW;
  78.       }
  79.     }
  80. #endif
  81. }
  82.  
  83. void sns_input_Init(void)
  84. {
  85.     pinStatus[0] = NOCHANGE;
  86.     pinStatus[1] = NOCHANGE;
  87.     pinStatus[2] = NOCHANGE;
  88.     pinStatus[3] = NOCHANGE;
  89.     pinStatus[4] = NOCHANGE;
  90.     pinStatus[5] = NOCHANGE;
  91.     pinStatus[6] = NOCHANGE;
  92.     pinStatus[7] = NOCHANGE;
  93.     uint8_t index = 0;
  94. #ifdef  sns_input_CH0
  95.     #if (sns_input_CH0_pullup == 1)
  96.         gpio_set_pullup(sns_input_CH0);
  97.     #else
  98.         gpio_clr_pullup(sns_input_CH0);
  99.     #endif
  100.         gpio_set_in(sns_input_CH0);
  101.         Pcint_SetCallbackPin(sns_input_PCINT_CH0, sns_input_CH0, &sns_input_pcint_callback);
  102.         index++;
  103. #endif
  104. #ifdef  sns_input_CH1
  105.     #if (sns_input_CH1_pullup == 1)
  106.         gpio_set_pullup(sns_input_CH1);
  107.     #else
  108.         gpio_clr_pullup(sns_input_CH1);
  109.     #endif     
  110.         gpio_set_in(sns_input_CH1);
  111.         Pcint_SetCallbackPin(sns_input_PCINT_CH1, sns_input_CH1, &sns_input_pcint_callback);
  112.         index++;
  113. #endif
  114. #ifdef  sns_input_CH2
  115.     #if (sns_input_CH2_pullup == 1)
  116.         gpio_set_pullup(sns_input_CH2);
  117.     #else
  118.         gpio_clr_pullup(sns_input_CH2);
  119.     #endif     
  120.         gpio_set_in(sns_input_CH2);
  121.         Pcint_SetCallbackPin(sns_input_PCINT_CH2, sns_input_CH2, &sns_input_pcint_callback);
  122.         index++;
  123. #endif
  124. #ifdef  sns_input_CH3
  125.     #if (sns_input_CH3_pullup == 1)
  126.         gpio_set_pullup(sns_input_CH3);
  127.     #else
  128.         gpio_clr_pullup(sns_input_CH3);
  129.     #endif     
  130.         gpio_set_in(sns_input_CH3);
  131.         Pcint_SetCallbackPin(sns_input_PCINT_CH3, sns_input_CH3, &sns_input_pcint_callback);
  132.         index++;
  133. #endif
  134. #ifdef  sns_input_CH4
  135.     #if (sns_input_CH4_pullup == 1)
  136.         gpio_set_pullup(sns_input_CH4);
  137.     #else
  138.         gpio_clr_pullup(sns_input_CH4);
  139.     #endif     
  140.         gpio_set_in(sns_input_CH4);
  141.         Pcint_SetCallbackPin(sns_input_PCINT_CH4, sns_input_CH4, &sns_input_pcint_callback);
  142.         index++;
  143. #endif
  144. #ifdef  sns_input_CH5
  145.     #if (sns_input_CH5_pullup == 1)
  146.         gpio_set_pullup(sns_input_CH5);
  147.     #else
  148.         gpio_clr_pullup(sns_input_CH5);
  149.     #endif     
  150.         gpio_set_in(sns_input_CH5);
  151.         Pcint_SetCallbackPin(sns_input_PCINT_CH5, sns_input_CH5, &sns_input_pcint_callback);
  152.         index++;
  153. #endif
  154. #ifdef  sns_input_CH6
  155.     #if (sns_input_CH6_pullup == 1)
  156.         gpio_set_pullup(sns_input_CH6);
  157.     #else
  158.         gpio_clr_pullup(sns_input_CH6);
  159.     #endif         
  160.         gpio_set_in(sns_input_CH6);
  161.         Pcint_SetCallbackPin(sns_input_PCINT_CH6, sns_input_CH6, &sns_input_pcint_callback);
  162.         index++;
  163. #endif
  164. #ifdef  sns_input_CH7
  165.     #if (sns_input_CH7_pullup == 1)
  166.         gpio_set_pullup(sns_input_CH7);
  167.     #else
  168.         gpio_clr_pullup(sns_input_CH7);
  169.     #endif     
  170.         gpio_set_in(sns_input_CH7);
  171.         Pcint_SetCallbackPin(sns_input_PCINT_CH7, sns_input_CH7, &sns_input_pcint_callback);
  172.         index++;
  173. #endif
  174.     // to use PCINt lib, call this function: (the callback function look as a timer callback function)
  175.     // Pcint_SetCallbackPin(sns_input_PCINT, EXP_C , &sns_input_pcint_callback);
  176.  
  177. }
  178.  
  179. void sns_input_Process(void)
  180. {
  181.     ///TODO: IMPLEMENT DEBOUNCE
  182.     uint8_t index = 0;
  183.     for (index = 0; index < 8; index++) {
  184.         if (pinStatus[index]!= NOCHANGE) {
  185.             StdCan_Msg_t txMsg;
  186.             StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
  187.             StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  188.             txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_INPUT;
  189.             txMsg.Header.ModuleId = sns_input_ID;
  190.             txMsg.Header.Command = CAN_MODULE_CMD_PHYSICAL_PINSTATUS;
  191.             txMsg.Length = 2;
  192.             txMsg.Data[0] = index;
  193.             if (pinStatus[index] == HIGH) {
  194.                 txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_HIGH;
  195.             } else {
  196.                 txMsg.Data[1] = CAN_MODULE_ENUM_PHYSICAL_PINSTATUS_STATUS_LOW;
  197.             }
  198.             while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  199.         }
  200.     }
  201. }
  202.  
  203. void sns_input_HandleMessage(StdCan_Msg_t *rxMsg)
  204. {
  205.    
  206. }
  207.  
  208. void sns_input_List(uint8_t ModuleSequenceNumber)
  209. {
  210.     StdCan_Msg_t txMsg;
  211.    
  212.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
  213.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  214.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_INPUT;
  215.     txMsg.Header.ModuleId = sns_input_ID;
  216.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  217.     txMsg.Length = 6;
  218.  
  219.     txMsg.Data[0] = NODE_HW_ID_BYTE0;
  220.     txMsg.Data[1] = NODE_HW_ID_BYTE1;
  221.     txMsg.Data[2] = NODE_HW_ID_BYTE2;
  222.     txMsg.Data[3] = NODE_HW_ID_BYTE3;
  223.    
  224.     txMsg.Data[4] = NUMBER_OF_MODULES;
  225.     txMsg.Data[5] = ModuleSequenceNumber;
  226.    
  227.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  228. }
  229.