Subversion Repositories HomeAutomation

Rev

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

  1.  
  2. #include "sns_Touch.h"
  3.  
  4. #ifdef sns_Touch_USEEEPROM
  5. #include "sns_Touch_eeprom.h"
  6. struct eeprom_sns_Touch EEMEM eeprom_sns_Touch =
  7. {
  8.     {
  9.         ///TODO: Define initialization values on the EEPROM variables here, this will generate a *.eep file that can be used to store this values to the node, can in future be done with a EEPROM module and the make-scrips. Write the values in the exact same order as the struct is defined in the *.h file.
  10.         0xAB,   // x
  11.         0x1234  // y
  12.     },
  13.     0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
  14. };
  15. #endif
  16.  
  17. void sns_Touch_Init(void)
  18. {
  19. #ifdef sns_Touch_USEEEPROM
  20.     if (EEDATA_OK)
  21.     {
  22.       ///TODO: Use stored data to set initial values for the module
  23.       blablaX = eeprom_read_byte(EEDATA.x);
  24.       blablaY = eeprom_read_word(EEDATA.y);
  25.     } else
  26.     {   //The CRC of the EEPROM is not correct, store default values and update CRC
  27.       eeprom_write_byte_crc(EEDATA.x, 0xAB, WITHOUT_CRC);
  28.       eeprom_write_word_crc(EEDATA.y, 0x1234, WITHOUT_CRC);
  29.       EEDATA_UPDATE_CRC;
  30.     }
  31. #endif  
  32.     ///TODO: Initialize hardware etc here
  33.  
  34.     // to use PCINt lib, call this function: (the callback function look as a timer callback function)
  35.     // Pcint_SetCallbackPin(sns_Touch_PCINT, EXP_C , &sns_Touch_pcint_callback);
  36.  
  37.     ADC_Init();
  38.     Timer_SetTimeout(sns_Touch_POLL_TIMER, sns_Touch_SEND_PERIOD , TimerTypeFreeRunning, 0);
  39.  
  40. }
  41.  
  42. void sns_Touch_Process(void)
  43. {
  44.    
  45.     if (Timer_Expired(sns_Touch_POLL_TIMER)) {
  46.         //StdCan_Msg_t txMsg;
  47.         gpio_set_in(sns_Touch_XPLUS);
  48.         gpio_set_pullup(sns_Touch_XPLUS);   //turn on pullup for x+
  49.         gpio_set_out(sns_Touch_YPLUS);
  50.         gpio_set_pin(sns_Touch_YPLUS);      //turn on 1 on y+
  51.         gpio_set_out(sns_Touch_YMINUS);
  52.         gpio_clr_pin(sns_Touch_YMINUS);     //turn on 0 on y-
  53.         uint8_t adxval = ADC_Get(sns_Touch_TOUCHXAD)>>2;    //read x-
  54.         gpio_set_in(sns_Touch_YPLUS);
  55.         gpio_clr_pullup(sns_Touch_YPLUS);   //turn off pullup for y+
  56.         gpio_set_in(sns_Touch_YMINUS);
  57.         gpio_clr_pullup(sns_Touch_YMINUS);  //turn off pullup for y-
  58.         gpio_set_in(sns_Touch_XPLUS);
  59.         gpio_clr_pullup(sns_Touch_XPLUS);   //turn off pullup for x+
  60.        
  61.         gpio_set_in(sns_Touch_YPLUS);
  62.         gpio_set_pullup(sns_Touch_YPLUS);   //turn on pullup for y+
  63.         gpio_set_out(sns_Touch_XPLUS);
  64.         gpio_set_pin(sns_Touch_XPLUS);      //turn on 1 on x+
  65.         gpio_set_out(sns_Touch_XMINUS);
  66.         gpio_clr_pin(sns_Touch_XMINUS);     //turn on 0 on x-
  67.         uint8_t adyval = ADC_Get(sns_Touch_TOUCHYAD)>>2;    //read y-
  68.         gpio_set_in(sns_Touch_XPLUS);
  69.         gpio_clr_pullup(sns_Touch_XPLUS);   //turn off pullup for x+
  70.         gpio_set_in(sns_Touch_XMINUS);
  71.         gpio_clr_pullup(sns_Touch_XMINUS);  //turn off pullup for x-
  72.         gpio_set_in(sns_Touch_YPLUS);
  73.         gpio_clr_pullup(sns_Touch_YPLUS);   //turn off pullup for y+
  74.        
  75.         if (adyval < 0xf0 && adxval < 0xf0 ) {
  76.             printf("Y: %d X: %d\n", adyval, adxval);
  77.         }
  78.  
  79.     }
  80. }
  81.  
  82. void sns_Touch_HandleMessage(StdCan_Msg_t *rxMsg)
  83. {
  84.     /*if (  StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_xyz && ///TODO: Change this to the actual class type
  85.         StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_FROM_OWNER &&
  86.         rxMsg->Header.ModuleType == CAN_MODULE_TYPE_xyz && ///TODO: Change this to the actual module type
  87.         rxMsg->Header.ModuleId == sns_Touch_ID)
  88.     {
  89.         switch (rxMsg->Header.Command)
  90.         {
  91.         case CAN_CMD_MODULE_DUMMY:
  92.         ///TODO: Do something dummy
  93.         break;
  94.         }
  95.     }*/
  96. }
  97.  
  98. void sns_Touch_List(uint8_t ModuleSequenceNumber)
  99. {
  100.     StdCan_Msg_t txMsg;
  101.    
  102.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
  103.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  104.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_TST_DEBUG;
  105.     txMsg.Header.ModuleId = sns_Touch_ID;
  106.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  107.     txMsg.Length = 6;
  108.  
  109.     txMsg.Data[0] = NODE_HW_ID_BYTE0;
  110.     txMsg.Data[1] = NODE_HW_ID_BYTE1;
  111.     txMsg.Data[2] = NODE_HW_ID_BYTE2;
  112.     txMsg.Data[3] = NODE_HW_ID_BYTE3;
  113.    
  114.     txMsg.Data[4] = NUMBER_OF_MODULES;
  115.     txMsg.Data[5] = ModuleSequenceNumber;
  116.    
  117.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  118. }
  119.