Subversion Repositories HomeAutomation

Rev

Blame | Last modification | View Log | SVN | RSS feed

  1.  
  2. #include "sns_qtouch.h"
  3.  
  4. #include "src/QTouch/touch_api.h"
  5. #include "touch.h"
  6. #define GET_SENSOR_STATE(SENSOR_NUMBER) qt_measure_data.qt_touch_status.sensor_states[(SENSOR_NUMBER/8)] & (1 << (SENSOR_NUMBER % 8))
  7. #define GET_ROTOR_SLIDER_POSITION(ROTOR_SLIDER_NUMBER) qt_measure_data.qt_touch_status.rotor_slider_values[ROTOR_SLIDER_NUMBER]
  8.  
  9. extern void touch_measure(void);
  10. extern void touch_init( void );
  11.  
  12. /* Timer period in msec. */
  13. uint16_t time_ms_inc=0;
  14.  
  15. /* flag set by timer ISR when it's time to measure touch */
  16. volatile uint8_t time_to_measure_touch = 0u;
  17.  
  18. /* current time, set by timer ISR */
  19. volatile uint16_t current_time_ms_touch = 0u;
  20.  
  21. #ifdef sns_qtouch_USEEEPROM
  22. #include "sns_qtouch_eeprom.h"
  23.  
  24. struct eeprom_sns_qtouch EEMEM eeprom_sns_qtouch =
  25. {
  26.     {
  27.         ///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.
  28.         0xAB,       // x
  29.         0x1234      // y
  30.         0x12345678  // z
  31.     },
  32.     0   // crc, must be a correct value, but this will also be handled by the EEPROM module or make scripts
  33. };
  34. #endif
  35.  
  36. void sns_qtouch_timer_callback(uint8_t timer)
  37.   {
  38.     time_to_measure_touch = 1u;  
  39.   }
  40.  
  41. void sns_qtouch_Init(void)
  42. {
  43. #ifdef sns_qtouch_USEEEPROM
  44.     if (EEDATA_OK)
  45.     {
  46.       ///TODO: Use stored data to set initial values for the module
  47.       blablaX = eeprom_read_byte(EEDATA.x);
  48.       blablaY = eeprom_read_word(EEDATA16.y);
  49.       blablaZ = eeprom_read_dword(EEDATA32.y);
  50.     } else
  51.     {   //The CRC of the EEPROM is not correct, store default values and update CRC
  52.       eeprom_write_byte_crc(EEDATA.x, 0xAB, WITHOUT_CRC);
  53.       eeprom_write_word_crc(EEDATA16.y, 0x1234, WITHOUT_CRC);
  54.       eeprom_write_dword_crc(EEDATA32.y, 0x12345678, WITHOUT_CRC);
  55.       EEDATA_UPDATE_CRC;
  56.     }
  57. #endif
  58.     ///TODO: Initialize hardware etc here
  59.  
  60.     // to use PCINt lib, call this function: (the callback function look as a timer callback function)
  61.     // Pcint_SetCallbackPin(sns_qtouch_PCINT, EXP_C , &sns_qtouch_pcint_callback);
  62.  
  63.  
  64.  
  65.     /* configure timer to fire regularly */
  66.     Timer_SetTimeout(sns_qtouch_TIMER, QT_MEASUREMENT_PERIOD_MS , TimerTypeFreeRunning, &sns_qtouch_timer_callback);
  67.  
  68.  
  69.     /* Initialize Touch sensors */
  70.     touch_init();
  71.  
  72.  
  73.  
  74. }
  75.  
  76. void sns_qtouch_Process(void)
  77. {
  78.     /*  update the current time */
  79.     current_time_ms_touch = (uint16_t)(Timer_GetTicks() & 0xFFFFu);
  80.         touch_measure();
  81.  
  82. }
  83.  
  84. void sns_qtouch_HandleMessage(StdCan_Msg_t *rxMsg)
  85. {
  86.     if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_SNS &&
  87.         StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_FROM_OWNER &&
  88.         rxMsg->Header.ModuleType == CAN_MODULE_TYPE_SNS_QTOUCH &&
  89.         rxMsg->Header.ModuleId == sns_qtouch_ID)
  90.     {
  91. /*
  92.         switch (rxMsg->Header.Command)
  93.         {
  94.         case CAN_CMD_MODULE_...:
  95.             ///TODO: Do something dummy
  96.         break;
  97.         }
  98. */
  99.     }
  100. }
  101.  
  102. void sns_qtouch_List(uint8_t ModuleSequenceNumber)
  103. {
  104.     StdCan_Msg_t txMsg;
  105.  
  106.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_SNS);
  107.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  108.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_SNS_QTOUCH;
  109.     txMsg.Header.ModuleId = sns_qtouch_ID;
  110.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  111.     txMsg.Length = 6;
  112.  
  113.     txMsg.Data[0] = NODE_HW_ID_BYTE0;
  114.     txMsg.Data[1] = NODE_HW_ID_BYTE1;
  115.     txMsg.Data[2] = NODE_HW_ID_BYTE2;
  116.     txMsg.Data[3] = NODE_HW_ID_BYTE3;
  117.  
  118.     txMsg.Data[4] = NUMBER_OF_MODULES;
  119.     txMsg.Data[5] = ModuleSequenceNumber;
  120.  
  121.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  122. }
  123.