Rev 1177 | Go to most recent revision | Details | Last modification | View Log | SVN | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1156 | linlun | 1 | |
| 2 | #include "act_softPWM.h" |
||
| 3 | |||
| 4 | #ifdef act_softPWM_USEEEPROM |
||
| 5 | #include "act_softPWM_eeprom.h" |
||
| 6 | struct eeprom_act_softPWM EEMEM eeprom_act_softPWM = |
||
| 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 | |||
| 14 | }; |
||
| 15 | #endif |
||
| 16 | |||
| 17 | void act_softPWM_Init(void) |
||
| 18 | { |
||
| 19 | #ifdef act_softPWM_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 | gpio_set_out(PIN_RED); |
||
| 34 | gpio_set_out(PIN_GREEN); |
||
| 35 | gpio_set_out(PIN_BLUE); |
||
| 36 | gpio_clr_pin(PIN_RED); |
||
| 37 | gpio_clr_pin(PIN_GREEN); |
||
| 38 | gpio_clr_pin(PIN_BLUE); |
||
| 39 | |||
| 40 | Timer_SetTimeout(act_softPWM_TIMER, 1, TimerTypeFreeRunning, NULL); |
||
| 41 | // to use PCINt lib, call this function: (the callback function look as a timer callback function) |
||
| 42 | // Pcint_SetCallbackPin(act_softPWM_PCINT, EXP_C , &act_softPWM_pcint_callback); |
||
| 43 | |||
| 44 | } |
||
| 45 | uint8_t redTimer = 0; |
||
| 46 | uint8_t greenTimer = 0; |
||
| 47 | uint8_t blueTimer = 0; |
||
| 48 | uint8_t currentTimer = 0; |
||
| 49 | |||
| 50 | void act_softPWM_Process(void) |
||
| 51 | { |
||
| 52 | if (Timer_Expired(act_softPWM_TIMER)) { |
||
| 53 | currentTimer++; |
||
| 54 | if (currentTimer == 10) { |
||
| 55 | currentTimer=0; |
||
| 56 | gpio_set_pin(PIN_RED); |
||
| 57 | gpio_set_pin(PIN_GREEN); |
||
| 58 | gpio_set_pin(PIN_BLUE); |
||
| 59 | } |
||
| 60 | |||
| 61 | if (currentTimer == redTimer) { |
||
| 62 | gpio_clr_pin(PIN_RED); |
||
| 63 | } |
||
| 64 | if (currentTimer == greenTimer) { |
||
| 65 | gpio_clr_pin(PIN_GREEN); |
||
| 66 | } |
||
| 67 | if (currentTimer == blueTimer) { |
||
| 68 | gpio_clr_pin(PIN_BLUE); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 73 | void act_softPWM_HandleMessage(StdCan_Msg_t *rxMsg) |
||
| 74 | { |
||
| 75 | if ( StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT && |
||
| 76 | StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER && |
||
| 77 | rxMsg->Header.ModuleType == CAN_MODULE_TYPE_ACT_SOFTPWM && |
||
| 78 | rxMsg->Header.ModuleId == act_softPWM_ID) |
||
| 79 | { |
||
| 80 | switch (rxMsg->Header.Command) |
||
| 81 | { |
||
| 82 | case CAN_MODULE_CMD_SOFTPWM_RGB_VALUE: |
||
| 83 | redTimer = rxMsg->Data[0]; |
||
| 84 | greenTimer = rxMsg->Data[1]; |
||
| 85 | blueTimer = rxMsg->Data[2]; |
||
| 86 | break; |
||
| 87 | } |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 91 | void act_softPWM_List(uint8_t ModuleSequenceNumber) |
||
| 92 | { |
||
| 93 | StdCan_Msg_t txMsg; |
||
| 94 | |||
| 95 | StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT); ///TODO: Change this to the actual class type |
||
| 96 | StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER); |
||
| 97 | txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_SOFTPWM; ///TODO: Change this to the actual module type |
||
| 98 | txMsg.Header.ModuleId = act_softPWM_ID; |
||
| 99 | txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST; |
||
| 100 | txMsg.Length = 6; |
||
| 101 | |||
| 102 | txMsg.Data[0] = NODE_HW_ID_BYTE0; |
||
| 103 | txMsg.Data[1] = NODE_HW_ID_BYTE1; |
||
| 104 | txMsg.Data[2] = NODE_HW_ID_BYTE2; |
||
| 105 | txMsg.Data[3] = NODE_HW_ID_BYTE3; |
||
| 106 | |||
| 107 | txMsg.Data[4] = NUMBER_OF_MODULES; |
||
| 108 | txMsg.Data[5] = ModuleSequenceNumber; |
||
| 109 | |||
| 110 | while (StdCan_Put(&txMsg) != StdCan_Ret_OK); |
||
| 111 | } |