Subversion Repositories HomeAutomation

Rev

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

  1. #ifndef ACT_DIMMER230
  2. #define ACT_DIMMER230
  3.  
  4. /*-----------------------------------------------------------------------------
  5.  * Includes
  6.  *---------------------------------------------------------------------------*/
  7. /* system files */
  8. #include <avr/io.h>
  9. #include <avr/interrupt.h>
  10. #include <avr/pgmspace.h>
  11. #include <stdio.h>
  12. /* lib files */
  13. #include <config.h>
  14. #include <bios.h>
  15. #include <drivers/can/stdcan.h>
  16. #include <drivers/timer/timer.h>
  17. #include <drivers/mcu/gpio.h>
  18.  
  19. #define ACT_DIMMMER230_STATE_IDLE           0
  20. #define ACT_DIMMMER230_STATE_TIMER_ON       1
  21. #define ACT_DIMMMER230_STATE_xyz            2
  22.  
  23. #define ACT_DIMMMER230_DEMO_STATE_NOT_RUNNING   0
  24. #define ACT_DIMMMER230_DEMO_STATE_DECREASE      1
  25. #define ACT_DIMMMER230_DEMO_STATE_INCREASE      2
  26. #define ACT_DIMMMER230_DEMO_STATE_GOBACK        3
  27.  
  28. #define ACT_DIMMMER230_PERIOD_TIME          10000
  29.  
  30. #define ACT_DIMMMER230_MAX_DIM              255
  31. #define ACT_DIMMMER230_MIN_DIM              0
  32.  
  33. #define ACT_DIMMMER230_50HZ_PERIOD_TIME     10000
  34. #define ACT_DIMMMER230_60HZ_PERIOD_TIME     8000
  35.  
  36. #if act_dimmer230_ZC_PCINT<8
  37. #define act_dimmer230_ZC_PCINT_vect PCINT0_vect     //interrupt vector
  38. #define act_dimmer230_ZC_PCIE       PCIE0           //interrupt enable
  39. #define act_dimmer230_ZC_PCIF       PCIF0           //interrupt flag
  40. #define act_dimmer230_ZC_PCMSK      PCMSK0          //mask register
  41. #define act_dimmer230_ZC_PCINT_BIT  act_dimmer230_ZC_PCINT      //interrupt bit
  42. #endif
  43.  
  44. #if act_dimmer230_ZC_PCINT>=8 && act_dimmer230_ZC_PCINT<16
  45. #define act_dimmer230_ZC_PCINT_vect PCINT1_vect     //interrupt vector
  46. #define act_dimmer230_ZC_PCIE       PCIE1           //interrupt enable
  47. #define act_dimmer230_ZC_PCIF       PCIF1           //interrupt flag
  48. #define act_dimmer230_ZC_PCMSK      PCMSK1          //mask register
  49. #define act_dimmer230_ZC_PCINT_BIT  act_dimmer230_ZC_PCINT-8    //interrupt bit
  50. #endif
  51.  
  52. #if act_dimmer230_ZC_PCINT>=16 && act_dimmer230_ZC_PCINT<24
  53. #define act_dimmer230_ZC_PCINT_vect PCINT2_vect     //interrupt vector
  54. #define act_dimmer230_ZC_PCIE       PCIE2           //interrupt enable
  55. #define act_dimmer230_ZC_PCIF       PCIF2           //interrupt flag
  56. #define act_dimmer230_ZC_PCMSK      PCMSK2          //mask register
  57. #define act_dimmer230_ZC_PCINT_BIT  act_dimmer230_ZC_PCINT-16   //interrupt bit
  58. #endif
  59.  
  60. void act_dimmer230_Init(void);
  61. void act_dimmer230_Process(void);
  62. void act_dimmer230_HandleMessage(StdCan_Msg_t *rxMsg);
  63. void act_dimmer230_List(uint8_t ModuleSequenceNumber);
  64.  
  65. #ifdef act_dimmer230_USEEEPROM
  66.     struct act_dimmer230_Data{
  67.         // the dimmer will store its current value in eeprom, to use when starting
  68.         uint8_t eeDimmerValue;
  69.     }; 
  70.  
  71. // Do not change anything below this line.
  72. // ----------------------------------------------------------------
  73.  
  74.     #include <drivers/misc/eeprom_crc8.h>
  75.     #include <avr/eeprom.h>
  76.     #define EEDATA          (uint8_t*)&eeprom_act_dimmer230.Data
  77.     #define EEDATA16        (uint16_t*)&eeprom_act_dimmer230.Data
  78.     #define EEDATA_CALC_CRC     eeprom_crc8((uint8_t*)&eeprom_act_dimmer230.Data,sizeof(struct act_dimmer230_Data))
  79.     #define EEDATA_UPDATE_CRC   eeprom_write_byte((uint8_t*)&eeprom_act_dimmer230.crc,eeprom_crc8((uint8_t*)&eeprom_act_dimmer230.Data,sizeof(struct act_dimmer230_Data)))
  80.     #define EEDATA_OK       EEDATA_CALC_CRC == EEDATA_STORED_CRC
  81.     #define EEDATA_STORED_CRC   eeprom_read_byte((uint8_t*)&eeprom_act_dimmer230.crc)
  82.    
  83.     struct eeprom_act_dimmer230{
  84.         struct act_dimmer230_Data Data;
  85.         uint8_t crc;
  86.     };
  87.     extern struct eeprom_act_dimmer230 EEMEM eeprom_act_dimmer230;
  88.    
  89.     #define WITH_CRC    1
  90.     #define WITHOUT_CRC 0
  91.     static __inline__ void eeprom_write_byte_crc(uint8_t *__p, uint8_t __value, uint8_t crc) {
  92.       if (__value != eeprom_read_byte(__p))
  93.       {
  94.         eeprom_write_byte(__p, __value);
  95.         if (crc == WITH_CRC)
  96.         {
  97.           EEDATA_UPDATE_CRC;
  98.         }
  99.       }
  100.     }
  101.     static __inline__ void eeprom_write_word_crc(uint16_t *__p, uint16_t __value, uint8_t crc) {
  102.       if (__value != eeprom_read_word(__p))
  103.       {
  104.         eeprom_write_word(__p, __value);
  105.         if (crc == WITH_CRC)
  106.         {
  107.           EEDATA_UPDATE_CRC;
  108.         }
  109.       }
  110.     }
  111. #endif
  112.  
  113. #endif // ACT_DIMMER230
  114.