Subversion Repositories HomeAutomation

Rev

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

  1.  
  2. #include "act_hd44780.h"
  3.  
  4. uint8_t Command = 0;
  5. #if act_hd44780_USE_AUTO_BL == 1
  6. uint8_t autoMode = CAN_MODULE_ENUM_HD44789_LCD_BACKLIGHT_AUTOLIGHT_ON;
  7. #endif
  8. void act_hd44780_Init(void)
  9. {
  10.     ///FIXME: What is this, this needs to be more clear by far....
  11.  
  12.     // Contrast (brightness on an oled display)
  13.     TCCR0A |= (1<<COM0B1)|(1<<WGM01)|(1<<WGM00);
  14.     TCCR0B |= (1<<CS00);
  15.     OCR0B = act_hd44780_INITIAL_CONTRAST;
  16.     DDRD |= (1<<PD5);
  17.  
  18. #if (act_hd44780_TYPE==0)
  19.     // Backlight
  20.     TCCR0A |= (1<<COM0A1)|(1<<WGM01)|(1<<WGM00);
  21.     TCCR0B |= (1<<CS00);
  22.     OCR0A = act_hd44780_INITIAL_BACKLIGHT;
  23.     DDRD |= (1<<PD6);
  24. #endif
  25.  
  26.     lcd_init(LCD_DISP_ON);
  27.     lcd_clrscr();
  28.     lcd_puts("HomeAutomation\n");
  29.     lcd_puts("HD44780-module\n");
  30. }
  31.  
  32. void act_hd44780_Process(void)
  33. {
  34.   #if act_hd44780_USE_AUTO_BL == 1
  35.     if (autoMode == CAN_MODULE_ENUM_HD44789_LCD_BACKLIGHT_AUTOLIGHT_ON) {
  36. #if (act_hd44780_TYPE==0)
  37.         if ( OCR0A == 0) {
  38. #else
  39.         if ( OCR0B == 0) {
  40. #endif
  41.  
  42.         } else {
  43.             uint16_t Voltage = (0x3ff & ADC_Get(act_hd44780_LIGHTSENSOR_AD));
  44. #if (act_hd44780_TYPE==0)
  45.             OCR0A = Voltage/4;
  46.             if (OCR0A == 0) {
  47.                 OCR0A = 1;
  48.             }
  49. #else
  50.             OCR0B = Voltage/4;
  51.             if (OCR0B == 0) {
  52.                 OCR0B = 1;
  53.             }
  54. #endif
  55.         }
  56.     }
  57.     #endif
  58. }
  59.  
  60. void act_hd44780_HandleMessage(StdCan_Msg_t *rxMsg)
  61. {
  62.     StdCan_Msg_t txMsg;
  63.     uint8_t n = 0;
  64.  
  65.     if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT &&
  66.         StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
  67.         rxMsg->Header.ModuleType == CAN_MODULE_TYPE_ACT_HD44789 &&
  68.         rxMsg->Header.ModuleId == act_hd44780_ID)
  69.     {
  70.         switch (rxMsg->Header.Command)
  71.         {
  72.         case CAN_MODULE_CMD_HD44789_LCD_CLEAR:
  73.         lcd_clrscr();
  74.         break;
  75.  
  76.         case CAN_MODULE_CMD_HD44789_LCD_CURSOR:
  77.         lcd_gotoxy(rxMsg->Data[0], rxMsg->Data[1]);
  78.         break;
  79.  
  80.         case CAN_MODULE_CMD_HD44789_LCD_TEXTAT:
  81.         lcd_gotoxy(rxMsg->Data[0], rxMsg->Data[1]);
  82.         for (n = 2; n < rxMsg->Length; n++)
  83.         {
  84.             lcd_putc((char)rxMsg->Data[n]);
  85.         }
  86.         break;
  87. /*
  88.         case CAN_MODULE_CMD_HD44789_LCD_CLEARROW:
  89.         lcd_gotoxy(0, rxMsg->Data[0]);
  90.         for (n = 0; n < act_hd44780_WIDTH; n++)
  91.         {
  92.             lcd_putc(' ');
  93.         }
  94.         break;
  95. */
  96.         case CAN_MODULE_CMD_HD44789_LCD_TEXT:
  97.         for (n = 0; n < rxMsg->Length; n++)
  98.         {
  99.             lcd_putc((char)rxMsg->Data[n]);
  100.         }
  101.         break;
  102.  
  103.         case CAN_MODULE_CMD_HD44789_LCD_SIZE:
  104.         StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
  105.         StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  106.         txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_HD44789;
  107.         txMsg.Header.ModuleId = act_hd44780_ID;
  108.         txMsg.Header.Command = CAN_MODULE_CMD_HD44789_LCD_SIZE;
  109.         txMsg.Length = 2;
  110.  
  111.         txMsg.Data[0] = act_hd44780_WIDTH;
  112.         txMsg.Data[1] = act_hd44780_HEIGHT;
  113.  
  114.         while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  115.         break;
  116.  
  117.         case CAN_MODULE_CMD_HD44789_LCD_BACKLIGHT:
  118.         if (rxMsg->Length > 0) {
  119. #if (act_hd44780_TYPE==0)
  120.             OCR0A = rxMsg->Data[0];
  121. #else
  122.             OCR0B = rxMsg->Data[0];
  123. #endif
  124. #if act_hd44780_USE_AUTO_BL == 1
  125.             if (rxMsg->Length == 2) {
  126.                 autoMode = rxMsg->Data[0];
  127.             }
  128. #endif
  129.         }
  130.  
  131.         StdCan_Msg_t txMsg;
  132.  
  133.         StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
  134.         StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  135.         txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_HD44789;
  136.         txMsg.Header.ModuleId = act_hd44780_ID;
  137.         txMsg.Header.Command = CAN_MODULE_CMD_HD44789_LCD_BACKLIGHT;
  138.         txMsg.Length = 1;
  139.  
  140. #if (act_hd44780_TYPE==0)
  141.             txMsg.Data[0] = OCR0A;
  142. #else
  143.             txMsg.Data[0] = OCR0B;
  144. #endif
  145. #if act_hd44780_USE_AUTO_BL == 1
  146.         txMsg.Data[1] = autoMode;
  147.         txMsg.Length = 2;
  148. #endif
  149.         while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  150.         break;
  151.         }
  152.     }
  153. }
  154.  
  155. void act_hd44780_List(uint8_t ModuleSequenceNumber)
  156. {
  157.     StdCan_Msg_t txMsg;
  158.  
  159.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
  160.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  161.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_HD44789;
  162.     txMsg.Header.ModuleId = act_hd44780_ID;
  163.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  164.     txMsg.Length = 6;
  165.  
  166.     txMsg.Data[0] = NODE_HW_ID_BYTE0;
  167.     txMsg.Data[1] = NODE_HW_ID_BYTE1;
  168.     txMsg.Data[2] = NODE_HW_ID_BYTE2;
  169.     txMsg.Data[3] = NODE_HW_ID_BYTE3;
  170.  
  171.     txMsg.Data[4] = NUMBER_OF_MODULES;
  172.     txMsg.Data[5] = ModuleSequenceNumber;
  173.  
  174.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  175. }
  176.