Subversion Repositories HomeAutomation

Rev

Rev 1725 | Blame | Compare with Previous | Last modification | View Log | SVN | RSS feed

  1.  
  2. #include "act_sigmadelta_dimmer.h"
  3.  
  4. #ifdef CHN_LOADED
  5. #include "../chn_ChnMaster/chn_ChnMaster.h"
  6.  
  7. void act_sigmadelta_dimmer_update( uint16_t channel_id, uint16_t value );
  8. #endif
  9.  
  10. #define GPIO_STRUCT_TO_ARGS(_VAR) (_VAR).port, (_VAR).pin, (_VAR).ddr, (_VAR).nr, (_VAR).pcint
  11. struct gpio_t {
  12.     volatile uint8_t* port;
  13.     volatile uint8_t* pin;
  14.     volatile uint8_t* ddr;
  15.     uint8_t nr;
  16.     uint8_t pcint;
  17. };
  18.  
  19.  
  20. uint8_t stepper = 0;
  21.  
  22. uint16_t inval = 0;
  23. int32_t dim_level[act_sigmadelta_dimmer_channel_count];
  24. int32_t dim_sigma[act_sigmadelta_dimmer_channel_count];
  25. const struct gpio_t dim_pins[act_sigmadelta_dimmer_channel_count] = {
  26.     act_sigmadelta_dimmer_pins
  27. };
  28.  
  29. void act_sigmadelta_dimmer_chn_update( uint16_t channel_id, uint16_t value ) {
  30.     channel_id -= act_sigmadelta_dimmer_base_channel; // Overflows for lower id
  31.     if( channel_id < act_sigmadelta_dimmer_channel_count ) { // filters all channels due to overflow before.
  32.         dim_level[channel_id] = value;
  33.     }
  34. }
  35.  
  36. void act_sigmadelta_dimmer_Init(void) {
  37.     uint8_t i;
  38. //    Timer_SetTimeout( act_sigmadelta_dimmer_SYS_TIMER, 1 , TimerTypeFreeRunning, 0);
  39.  
  40. // CDEA GFIH JKLM
  41.  
  42.     // FIXME: port constants, as a list?
  43. /*    gpio_set_out( EXP_C );
  44.     gpio_set_out( EXP_D );
  45.     gpio_set_out( EXP_E );
  46.  
  47.     gpio_set_out( EXP_A );
  48.     gpio_set_out( EXP_G );
  49.     gpio_set_out( EXP_F );
  50.  
  51.     gpio_set_out( EXP_I );
  52.     gpio_set_out( EXP_H );
  53.     gpio_set_out( EXP_N );//J );
  54.  
  55.     gpio_set_out( EXP_B );//K );
  56.     gpio_set_out( EXP_L );
  57.     gpio_set_out( EXP_M );*/
  58.  
  59.  
  60.     for( i=0; i<act_sigmadelta_dimmer_channel_count; i++ ) {
  61.         gpio_set_out( GPIO_STRUCT_TO_ARGS( dim_pins[i] ) );
  62.     }
  63.  
  64. #ifdef CHN_LOADED
  65.     for( i=0; i<act_sigmadelta_dimmer_channel_count; i++ ) {
  66.         dim_level[i] = 0;
  67.         dim_sigma[i] = 0;
  68.         chn_ChnMaster_RegisterListener( act_sigmadelta_dimmer_base_channel + i, act_sigmadelta_dimmer_chn_update );
  69.     }
  70. #endif
  71. }
  72.  
  73. void act_sigmadelta_dimmer_Process(void) {
  74.     int32_t delta;
  75.     uint32_t level;
  76.     uint8_t i;
  77.  
  78. //    if( Timer_Expired( act_sigmadelta_dimmer_SYS_TIMER ) ) {
  79. //    }
  80.  
  81.     for( i = 0; i<act_sigmadelta_dimmer_channel_count; i++) {
  82.         level = dim_level[i]*dim_level[i];
  83.         level >>= 16;
  84.         delta = level - ((dim_sigma[i] >= 0) ? 0xfffeL : 0L); // 0xfffe = (0xffff ** 2) >> 16
  85.         dim_sigma[i] += delta;
  86.         if( dim_sigma[i] >  655360 ) dim_sigma[i] = 655360;
  87.         if( dim_sigma[i] < -655360 ) dim_sigma[i] = -655360;
  88.  
  89.         gpio_set_statement( dim_sigma[i]>=0, GPIO_STRUCT_TO_ARGS( dim_pins[i] ) );
  90.     }
  91.  
  92. /*    // FIXME: port constants, as a list?
  93.     gpio_set_statement( dim_sigma[ 0]>=0, EXP_C );
  94.     gpio_set_statement( dim_sigma[ 1]>=0, EXP_D );
  95.     gpio_set_statement( dim_sigma[ 2]>=0, EXP_E );
  96.  
  97.     gpio_set_statement( dim_sigma[ 3]>=0, EXP_A );
  98.     gpio_set_statement( dim_sigma[ 4]>=0, EXP_G );
  99.     gpio_set_statement( dim_sigma[ 5]>=0, EXP_F );
  100.  
  101.     gpio_set_statement( dim_sigma[ 6]>=0, EXP_I );
  102.     gpio_set_statement( dim_sigma[ 7]>=0, EXP_H );
  103.     gpio_set_statement( dim_sigma[ 8]>=0, EXP_N ); //J );
  104.  
  105.     gpio_set_statement( dim_sigma[ 9]>=0, EXP_B ); //K );
  106.     gpio_set_statement( dim_sigma[10]>=0, EXP_L );
  107.     gpio_set_statement( dim_sigma[11]>=0, EXP_M );*/
  108. }
  109.  
  110. void act_sigmadelta_dimmer_HandleMessage(StdCan_Msg_t *rxMsg) {
  111. }
  112.  
  113. void act_sigmadelta_dimmer_List(uint8_t ModuleSequenceNumber) {
  114.     StdCan_Msg_t txMsg;
  115.  
  116.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT); ///TODO: Change this to the actual class type
  117.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  118.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_SIGMADELTA_DIMMER; ///TODO: Change this to the actual module type
  119.     txMsg.Header.ModuleId = act_sigmadelta_dimmer_ID;
  120.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  121.     txMsg.Length = 6;
  122.  
  123.     uint32_t HwId=BIOS_GetHwId();
  124.     txMsg.Data[0] = HwId&0xff;
  125.     txMsg.Data[1] = (HwId>>8)&0xff;
  126.     txMsg.Data[2] = (HwId>>16)&0xff;
  127.     txMsg.Data[3] = (HwId>>24)&0xff;
  128.  
  129.     txMsg.Data[4] = NUMBER_OF_MODULES;
  130.     txMsg.Data[5] = ModuleSequenceNumber;
  131.  
  132.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  133. }
  134.