Subversion Repositories HomeAutomation

Rev

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

  1.  
  2. #include "act_ks0108.h"
  3.  
  4. static unsigned char Splash_left[] PROGMEM = {
  5. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf,0xe7,0x3,0xf1,0xfa,0xab,0x73,0xb5,0x35,0x36,0x6e,0xfe,0xfe,0xfe,0x6e,0xb4,0x35,0x35,0x71,0xab,0xfb,0xf2,0xf0,0x3,0xf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0x7,0xff,//Line 1
  6. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0xfc,0xe3,0x1f,0xbf,0x7f,0xfe,0xfe,0xff,0xbf,0x77,0x77,0x77,0xbf,0xff,0xfe,0xfe,0xff,0x7f,0x3f,0xdf,0xe3,0xfc,0xfc,0x81,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,//Line 2
  7. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0x1f,0x87,0xd9,0xdc,0xdf,0x7,0x1,0xc,0x2f,0x2f,0x76,0x76,0x79,0x7d,0xfb,0xfb,0xfb,0xfb,0x7d,0x79,0x76,0x36,0xf,0xc,0x9,0x7,0xf,0xdf,0xdf,0xd8,0xa7,0x8f,0x3f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,//Line 3
  8. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xf,0xf0,0xfe,0xff,0xff,0xff,0x7,0x3,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x3,0x7,0xff,0xff,0xff,0xff,0xf0,0xf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,//Line 4
  9. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0x83,0xfc,0xff,0xff,0xff,0xff,0x9f,0xe0,0xf8,0xf0,0xf0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xf0,0xf0,0xf8,0xe0,0x1f,0xff,0xff,0xff,0xff,0xfc,0x83,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,//Line 5
  10. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xff,0xff,0xff,0x1f,0xe1,0xfe,0xff,0xff,0x7f,0x1f,0x7,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x7,0x1f,0x7f,0xff,0xff,0xfe,0xe1,0x1f,0xff,0xff,0xff,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xfc,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0x3,0xb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xb,0x3,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfb,0xfc,0xff,//Line 6
  11. 0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7,0xf8,0xff,0xff,0xf,0xf0,0xff,0xff,0xf,0x13,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x1c,0x13,0xf,0xff,0xff,0xf0,0xf,0xff,0xff,0xf8,0x7,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x0,0xfe,0xff,0xff,0xff,0xff,0xff,0xff,0xfe,0x0,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,//Line 7
  12. 0xff,0xbf,0x5f,0x5f,0x6f,0x77,0x79,0x7e,0x9f,0x7f,0x87,0xf8,0xff,0xff,0xff,0x80,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0xf8,0xf8,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x80,0xff,0xff,0xff,0xf8,0x87,0x7f,0x9f,0x7e,0x79,0x77,0x6f,0x5f,0x5f,0xbf,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0x7f,0x0,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x3f,0x0,0x7f,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff//Line 7
  13. };
  14. #define SOLID   0
  15. #define TRANSPARENT 1
  16. uint8_t color=GLCD_COLOR_BLACK;
  17. uint8_t Transparent=SOLID;
  18.  
  19. void numtoascii( int16_t num, char **str );
  20. void signedtoascii(int16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals);
  21. void unsignedtoascii(uint16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals);
  22.  
  23. void act_ks0108_Init(void)
  24. {
  25.     ///TODO: Initialize hardware etc here
  26.     DDRC |= (1<<PC0);
  27.     PORTC |= (1<<PC0);
  28.  
  29.     glcdPowerOn();
  30.  
  31.     uint16_t ixa = 0;
  32.     uint8_t jxa = 0;
  33.     for (jxa = 0; jxa< 8; jxa++){
  34.         glcdSetXY(0,jxa*8);
  35.         for (ixa = 0; ixa < 128; ixa++){
  36.             glcdWriteData((uint8_t)pgm_read_byte((uint16_t)&Splash_left+ixa+jxa*128), GLCD_COLOR_CLEAR);
  37.         }
  38.     }
  39.     glcdSetXY(0,0);
  40.     glcdPutStrTransparent("=_-[]_-=",GLCD_COLOR_SET);
  41.     glcdSetXY(0,8);
  42.     glcdPutStrTransparent("--------",GLCD_COLOR_SET);
  43.     glcdSetXY(0,16);
  44.     glcdPutStr("-_=[]=-_",GLCD_COLOR_SET);
  45.     glcdDrawRect(32, 32, 40, 16, GLCD_COLOR_SET);
  46.     glcdDrawLine(10, 10, 100, 60, GLCD_COLOR_SET);
  47.     glcdFillRect(90, 10, 20, 20, GLCD_COLOR_SET);
  48.     glcdInvertRect(28, 10, 20, 20);
  49.     glcdInvert();
  50.     glcdDrawRoundRect(85, 5, 30, 30, 5, GLCD_COLOR_SET);
  51.     glcdDrawCircle(64, 32, 10, 1);
  52.     glcdSetXY(12,40);
  53.     glcdPutStrTransparent("Hejsan",GLCD_COLOR_CLEAR);
  54.     glcdDrawLine(10, 62, 50, 5, GLCD_COLOR_CLEAR);
  55.    
  56. }
  57.  
  58. void act_ks0108_Process(void)
  59. {
  60.     ///TODO: Stuff that needs doing is done here
  61. }
  62.  
  63. void act_ks0108_HandleMessage(StdCan_Msg_t *rxMsg)
  64. {
  65.     StdCan_Msg_t txMsg;
  66.     uint8_t n = 0;
  67.  
  68.     if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT &&
  69.         StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
  70.         rxMsg->Header.ModuleType == CAN_MODULE_TYPE_ACT_KS0108 &&
  71.         rxMsg->Header.ModuleId == act_ks0108_ID)
  72.     {
  73.     switch (rxMsg->Header.Command)
  74.     {
  75.         case CAN_MODULE_CMD_KS0108_LCD_CLEAR:
  76.           if (rxMsg->Length == 1) {
  77.             glcdSetColor((0x80&rxMsg->Data[0])>>7);
  78.           }
  79.           glcdClear();
  80.           rxMsg->Data[0] = glcdGetColor()<<7;
  81.           StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER);
  82.           rxMsg->Length = 1;
  83.           while (StdCan_Put(rxMsg) != StdCan_Ret_OK);
  84.           break;
  85.         case CAN_MODULE_CMD_KS0108_LCD_INVERT:
  86.           if (rxMsg->Length == 1) {
  87.             if ((0x80&rxMsg->Data[0])>>7 != glcdGetColor())
  88.                 glcdInvert();
  89.           } else
  90.             glcdInvert();
  91.           rxMsg->Data[0] = glcdGetColor()<<7;
  92.           StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER);
  93.           rxMsg->Length = 1;
  94.           while (StdCan_Put(rxMsg) != StdCan_Ret_OK);
  95.           break;
  96.         case CAN_MODULE_CMD_KS0108_LCD_CURSOR:
  97.           if (rxMsg->Length == 2) {
  98.             glcdSetXY((0x3f&rxMsg->Data[0])*6, rxMsg->Data[1]*8);
  99.             color = ((0x80&rxMsg->Data[2])>>7);
  100.             Transparent = ((0x40&rxMsg->Data[2])>>6);
  101.           }
  102.           rxMsg->Data[0] = glcdGetColor()<<7;
  103.           rxMsg->Data[0] = Transparent<<6;
  104.           rxMsg->Data[0] |= (0x3f & (glcdGetX()/6));
  105.           rxMsg->Data[1] |= ((glcdGetY()/8));
  106.           StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER);
  107.           rxMsg->Length = 2;
  108.           while (StdCan_Put(rxMsg) != StdCan_Ret_OK);
  109.  
  110.           break;
  111.  
  112.         case CAN_MODULE_CMD_KS0108_LCD_TEXTAT:
  113.           glcdSetXY((0x3f&rxMsg->Data[0])*6, rxMsg->Data[1]*8);
  114.           for (n = 2; n < rxMsg->Length; n++)
  115.           {
  116.               if (((0x40&rxMsg->Data[0])>>6)== TRANSPARENT)
  117.                 glcdWriteCharTransparent((char)rxMsg->Data[n], (0x80&rxMsg->Data[0])>>7);
  118.               else
  119.                 glcdWriteChar((char)rxMsg->Data[n], (0x80&rxMsg->Data[0])>>7);
  120.           }
  121.         break;
  122.  
  123.         case CAN_MODULE_CMD_KS0108_LCD_TEXT:
  124.         for (n = 0; n < rxMsg->Length; n++)
  125.         {
  126.             if (Transparent == TRANSPARENT)
  127.                 glcdWriteCharTransparent((char)rxMsg->Data[n], color);
  128.             else
  129.                 glcdWriteChar((char)rxMsg->Data[n], color);
  130.         }
  131.         break;
  132.  
  133.         case CAN_MODULE_CMD_KS0108_LCD_BACKLIGHT:
  134.         if (rxMsg->Length > 0) {
  135.           if (rxMsg->Data[0] > 127)
  136.             PORTC |= (1<<PC0);
  137.           else
  138.             PORTC &= ~(1<<PC0);
  139. /*
  140. #if (act_hd44780_TYPE==0)
  141.             OCR1AL = rxMsg->Data[0];
  142. #else
  143.             OCR0B = rxMsg->Data[0];
  144. #endif
  145. */
  146.         }
  147.         StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
  148.         StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  149.         txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_KS0108;
  150.         txMsg.Header.ModuleId = act_ks0108_ID;
  151.         txMsg.Header.Command = CAN_MODULE_CMD_KS0108_LCD_BACKLIGHT;
  152.         txMsg.Length = 1;
  153.        
  154.         txMsg.Data[0] = PORTC & (1<<PC0);
  155. /*
  156. #if (act_hd44780_TYPE==0)
  157.             txMsg.Data[0] = OCR1AL;
  158. #else
  159.             txMsg.Data[0] = OCR0B;
  160. #endif
  161. */
  162.  
  163.         while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  164.         break;
  165.        
  166.         case CAN_MODULE_CMD_KS0108_LCD_DRAWRECT:
  167.           if ((0x40&rxMsg->Data[0])>>6)
  168.             glcdFillRect(rxMsg->Data[1], rxMsg->Data[2], rxMsg->Data[3], rxMsg->Data[4], (0x80&rxMsg->Data[0])>>7);
  169.           else
  170.             if (rxMsg->Data[5] == 0)
  171.                 glcdDrawRect(rxMsg->Data[1], rxMsg->Data[2], rxMsg->Data[3], rxMsg->Data[4], (0x80&rxMsg->Data[0])>>7);
  172.             else
  173.                 glcdDrawRoundRect(rxMsg->Data[1], rxMsg->Data[2], rxMsg->Data[3], rxMsg->Data[4], rxMsg->Data[5],(0x80&rxMsg->Data[0])>>7);
  174.           break;
  175.        
  176.         case CAN_MODULE_CMD_KS0108_LCD_DRAWLINE:
  177.           glcdDrawLine(rxMsg->Data[1], rxMsg->Data[2], rxMsg->Data[3], rxMsg->Data[4], (0x80&rxMsg->Data[0])>>7);
  178.           break;
  179.  
  180.         case CAN_MODULE_CMD_KS0108_LCD_DRAWCIRCLE:
  181.           glcdDrawCircle(rxMsg->Data[1], rxMsg->Data[2], rxMsg->Data[3], (0x80&rxMsg->Data[0])>>7);
  182.           break;
  183.    
  184.         case CAN_MODULE_CMD_KS0108_LCD_INVERTRECT:
  185.           glcdInvertRect(rxMsg->Data[0], rxMsg->Data[1], rxMsg->Data[2], rxMsg->Data[3]);
  186.           break;
  187.  
  188.         }
  189.     }
  190. /*
  191.     static uint8_t saer=0;
  192.     static uint8_t saer2=0;
  193.     saer++;
  194.     if (saer>10) {
  195.         saer2++;
  196.         uint8_t ixa = 0;
  197.         uint8_t jxa = 0;
  198.         for (jxa = 0; jxa< 8; jxa++){
  199.             glcdSetXY(0,jxa);
  200.             for (ixa = 0; ixa < 128; ixa++){
  201.                 glcdWriteData((uint8_t)pgm_read_byte((uint16_t)&Splash_left+ixa+jxa*128));
  202.             }
  203.         }
  204.         saer=0;
  205.         glcdSetXY(83,1);
  206.         glcdPutStr("Tycker ");
  207.         glcdSetXY(83,2);
  208.         glcdPutStr(" detta ");
  209.         glcdSetXY(83,3);
  210.         glcdPutStr("funkar!");
  211.         glcdSetXY(83,4);
  212.         char buffer[20];   
  213.         //numtoascii((int16_t)saer2 ,*buffer);
  214.         unsignedtoascii((int16_t)saer2,0,buffer,1);
  215.         glcdPutStr(buffer);
  216.     }
  217. */
  218. }
  219.  
  220. void act_ks0108_List(uint8_t ModuleSequenceNumber)
  221. {
  222.     StdCan_Msg_t txMsg;
  223.  
  224.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
  225.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  226.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_KS0108;
  227.     txMsg.Header.ModuleId = act_ks0108_ID;
  228.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  229.     txMsg.Length = 6;
  230.  
  231.     txMsg.Data[0] = NODE_HW_ID_BYTE0;
  232.     txMsg.Data[1] = NODE_HW_ID_BYTE1;
  233.     txMsg.Data[2] = NODE_HW_ID_BYTE2;
  234.     txMsg.Data[3] = NODE_HW_ID_BYTE3;
  235.  
  236.     txMsg.Data[4] = NUMBER_OF_MODULES;
  237.     txMsg.Data[5] = ModuleSequenceNumber;
  238.  
  239.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  240. }
  241.  
  242. //� la pengi. Skall libbifieras.
  243.     void numtoascii( int16_t num, char **str ) {
  244.         if( num==0 ) return;
  245.         numtoascii( num/10, str );
  246.         **str = '0' + (num%10);
  247.         (*str)++;
  248.     }
  249.  
  250.     void signedtoascii(int16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals){ //decimalplace is number of decimals
  251.         uint8_t i;
  252.  
  253.         if( num<0 ) {
  254.             *(string++) = '-';
  255.             num = -num;
  256.         }
  257.         numtoascii(num>>decimalplace, &string );
  258.         if(numberofdecimals!=0) *(string++) = '.';
  259.         for(i=0;i<numberofdecimals;i++) {
  260.             num %= 1<<decimalplace;
  261.             num *= 10;
  262.             *(string++) = '0' + (num>>decimalplace);
  263.         }
  264.         *(string++) = 0;
  265.     }
  266.  
  267.     void unsignedtoascii(uint16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals){ //decimalplace is number of decimals
  268.         uint8_t i;
  269.         numtoascii(num>>decimalplace, &string );
  270.         if(numberofdecimals!=0) *(string++) = '.';
  271.         for(i=0;i<numberofdecimals;i++) {
  272.             num %= 1<<decimalplace;
  273.             num *= 10;
  274.             *(string++) = '0' + (num>>decimalplace);
  275.         }
  276.         *(string++) = 0;
  277.     }
  278.