Subversion Repositories HomeAutomation

Rev

Rev 1200 | 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.     // Backlight
  27.     TCCR0A |= (1<<COM0A1)|(1<<WGM01)|(1<<WGM00);
  28.     TCCR0B |= (1<<CS00);
  29.     OCR0A = act_ks0108_INITIAL_BACKLIGHT;
  30.     DDRD |= (1<<PD6);
  31.  
  32.     glcdPowerOn();
  33.  
  34.     uint16_t ixa = 0;
  35.     uint8_t jxa = 0;
  36.     for (jxa = 0; jxa< 8; jxa++){
  37.         glcdSetXY(0,jxa*8);
  38.         for (ixa = 0; ixa < 128; ixa++){
  39.             glcdWriteData((uint8_t)pgm_read_byte((uint16_t)&Splash_left+ixa+jxa*128), GLCD_COLOR_CLEAR);
  40.         }
  41.     }
  42.     //glcdSetXY(0,0);
  43.     //glcdPutStrTransparent("=_-[]_-=",GLCD_COLOR_SET);
  44.     //glcdSetXY(0,8);
  45.     //glcdPutStrTransparent("--------",GLCD_COLOR_SET);
  46.     //glcdSetXY(0,16);
  47.     //glcdPutStr("-_=[]=-_",GLCD_COLOR_SET);
  48.     //glcdDrawRect(32, 32, 40, 16, GLCD_COLOR_SET);
  49.     //glcdDrawLine(10, 10, 100, 60, GLCD_COLOR_SET);
  50.     //glcdFillRect(90, 10, 20, 20, GLCD_COLOR_SET);
  51.     //glcdInvertRect(28, 10, 20, 20);
  52.     //glcdInvert();
  53.     //glcdDrawRoundRect(85, 5, 30, 30, 5, GLCD_COLOR_SET);
  54.     //glcdDrawCircle(64, 32, 10, 1);
  55.     glcdSetXY(87,8);
  56.     glcdPutStrTransparent("Home-",GLCD_COLOR_SET);
  57.     glcdSetXY(80,16);
  58.     glcdPutStrTransparent("Automa-",GLCD_COLOR_SET);
  59.     glcdSetXY(91,24);
  60.     glcdPutStrTransparent("ion",GLCD_COLOR_SET);
  61.     //glcdDrawLine(10, 62, 50, 5, GLCD_COLOR_CLEAR);
  62.    
  63. }
  64.  
  65. void act_ks0108_Process(void)
  66. {
  67.     ///TODO: Stuff that needs doing is done here
  68. }
  69.  
  70. void act_ks0108_HandleMessage(StdCan_Msg_t *rxMsg)
  71. {
  72.     StdCan_Msg_t txMsg;
  73.     uint8_t n = 0;
  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_KS0108 &&
  78.         rxMsg->Header.ModuleId == act_ks0108_ID)
  79.     {
  80.     switch (rxMsg->Header.Command)
  81.     {
  82.         case CAN_MODULE_CMD_KS0108_LCD_CLEAR:
  83.           if (rxMsg->Length == 1) {
  84.             glcdSetColor((0x80&rxMsg->Data[0])>>7);
  85.           }
  86.           glcdClear();
  87.           rxMsg->Data[0] = glcdGetColor()<<7;
  88.           StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER);
  89.           rxMsg->Length = 1;
  90.           while (StdCan_Put(rxMsg) != StdCan_Ret_OK);
  91.           break;
  92.         case CAN_MODULE_CMD_KS0108_LCD_INVERT:
  93.           if (rxMsg->Length == 1) {
  94.             if ((0x80&rxMsg->Data[0])>>7 != glcdGetColor())
  95.                 glcdInvert();
  96.           } else
  97.             glcdInvert();
  98.           rxMsg->Data[0] = glcdGetColor()<<7;
  99.           StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER);
  100.           rxMsg->Length = 1;
  101.           while (StdCan_Put(rxMsg) != StdCan_Ret_OK);
  102.           break;
  103.         case CAN_MODULE_CMD_KS0108_LCD_CURSOR:
  104.           if (rxMsg->Length == 2) {
  105.             glcdSetXY((0x3f&rxMsg->Data[0])*6, rxMsg->Data[1]*8);
  106.             color = ((0x80&rxMsg->Data[2])>>7);
  107.             Transparent = ((0x40&rxMsg->Data[2])>>6);
  108.           }
  109.           rxMsg->Data[0] = glcdGetColor()<<7;
  110.           rxMsg->Data[0] = Transparent<<6;
  111.           rxMsg->Data[0] |= (0x3f & (glcdGetX()/6));
  112.           rxMsg->Data[1] |= ((glcdGetY()/8));
  113.           StdCan_Set_direction(rxMsg->Header, DIRECTIONFLAG_FROM_OWNER);
  114.           rxMsg->Length = 2;
  115.           while (StdCan_Put(rxMsg) != StdCan_Ret_OK);
  116.  
  117.           break;
  118.  
  119.         case CAN_MODULE_CMD_KS0108_LCD_TEXTAT:
  120.           glcdSetXY((0x3f&rxMsg->Data[0])*6, rxMsg->Data[1]*8);
  121.           for (n = 2; n < rxMsg->Length; n++)
  122.           {
  123.               if (((0x40&rxMsg->Data[0])>>6)== TRANSPARENT)
  124.                 glcdWriteCharTransparent((char)rxMsg->Data[n], (0x80&rxMsg->Data[0])>>7);
  125.               else
  126.                 glcdWriteChar((char)rxMsg->Data[n], (0x80&rxMsg->Data[0])>>7);
  127.           }
  128.         break;
  129.  
  130.         case CAN_MODULE_CMD_KS0108_LCD_TEXT:
  131.         for (n = 0; n < rxMsg->Length; n++)
  132.         {
  133.             if (Transparent == TRANSPARENT)
  134.                 glcdWriteCharTransparent((char)rxMsg->Data[n], color);
  135.             else
  136.                 glcdWriteChar((char)rxMsg->Data[n], color);
  137.         }
  138.         break;
  139.  
  140.         case CAN_MODULE_CMD_KS0108_LCD_BACKLIGHT:
  141.             if (rxMsg->Length > 0) {
  142.                 OCR0A = rxMsg->Data[0];
  143.             }
  144.             StdCan_Msg_t txMsg;
  145.             StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
  146.             StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  147.             txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_KS0108;
  148.             txMsg.Header.ModuleId = act_ks0108_ID;
  149.             txMsg.Header.Command = CAN_MODULE_CMD_KS0108_LCD_BACKLIGHT;
  150.             txMsg.Length = 1;
  151.             txMsg.Data[0] = OCR0A;
  152.             while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  153.         break;
  154.        
  155.         case CAN_MODULE_CMD_KS0108_LCD_DRAWRECT:
  156.           if ((0x40&rxMsg->Data[0])>>6)
  157.             glcdFillRect(rxMsg->Data[1], rxMsg->Data[2], rxMsg->Data[3], rxMsg->Data[4], (0x80&rxMsg->Data[0])>>7);
  158.           else
  159.             if (rxMsg->Data[5] == 0)
  160.                 glcdDrawRect(rxMsg->Data[1], rxMsg->Data[2], rxMsg->Data[3], rxMsg->Data[4], (0x80&rxMsg->Data[0])>>7);
  161.             else
  162.                 glcdDrawRoundRect(rxMsg->Data[1], rxMsg->Data[2], rxMsg->Data[3], rxMsg->Data[4], rxMsg->Data[5],(0x80&rxMsg->Data[0])>>7);
  163.           break;
  164.        
  165.         case CAN_MODULE_CMD_KS0108_LCD_DRAWLINE:
  166.           glcdDrawLine(rxMsg->Data[1], rxMsg->Data[2], rxMsg->Data[3], rxMsg->Data[4], (0x80&rxMsg->Data[0])>>7);
  167.           break;
  168.  
  169.         case CAN_MODULE_CMD_KS0108_LCD_DRAWCIRCLE:
  170.           glcdDrawCircle(rxMsg->Data[1], rxMsg->Data[2], rxMsg->Data[3], (0x80&rxMsg->Data[0])>>7);
  171.           break;
  172.    
  173.         case CAN_MODULE_CMD_KS0108_LCD_INVERTRECT:
  174.           glcdInvertRect(rxMsg->Data[0], rxMsg->Data[1], rxMsg->Data[2], rxMsg->Data[3]);
  175.           break;
  176.  
  177.         }
  178.     }
  179. /*
  180.     static uint8_t saer=0;
  181.     static uint8_t saer2=0;
  182.     saer++;
  183.     if (saer>10) {
  184.         saer2++;
  185.         uint8_t ixa = 0;
  186.         uint8_t jxa = 0;
  187.         for (jxa = 0; jxa< 8; jxa++){
  188.             glcdSetXY(0,jxa);
  189.             for (ixa = 0; ixa < 128; ixa++){
  190.                 glcdWriteData((uint8_t)pgm_read_byte((uint16_t)&Splash_left+ixa+jxa*128));
  191.             }
  192.         }
  193.         saer=0;
  194.         glcdSetXY(83,1);
  195.         glcdPutStr("Tycker ");
  196.         glcdSetXY(83,2);
  197.         glcdPutStr(" detta ");
  198.         glcdSetXY(83,3);
  199.         glcdPutStr("funkar!");
  200.         glcdSetXY(83,4);
  201.         char buffer[20];   
  202.         //numtoascii((int16_t)saer2 ,*buffer);
  203.         unsignedtoascii((int16_t)saer2,0,buffer,1);
  204.         glcdPutStr(buffer);
  205.     }
  206. */
  207. }
  208.  
  209. void act_ks0108_List(uint8_t ModuleSequenceNumber)
  210. {
  211.     StdCan_Msg_t txMsg;
  212.  
  213.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
  214.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  215.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_KS0108;
  216.     txMsg.Header.ModuleId = act_ks0108_ID;
  217.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  218.     txMsg.Length = 6;
  219.  
  220.     txMsg.Data[0] = NODE_HW_ID_BYTE0;
  221.     txMsg.Data[1] = NODE_HW_ID_BYTE1;
  222.     txMsg.Data[2] = NODE_HW_ID_BYTE2;
  223.     txMsg.Data[3] = NODE_HW_ID_BYTE3;
  224.  
  225.     txMsg.Data[4] = NUMBER_OF_MODULES;
  226.     txMsg.Data[5] = ModuleSequenceNumber;
  227.  
  228.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  229. }
  230.  
  231. //� la pengi. Skall libbifieras.
  232.     void numtoascii( int16_t num, char **str ) {
  233.         if( num==0 ) return;
  234.         numtoascii( num/10, str );
  235.         **str = '0' + (num%10);
  236.         (*str)++;
  237.     }
  238.  
  239.     void signedtoascii(int16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals){ //decimalplace is number of decimals
  240.         uint8_t i;
  241.  
  242.         if( num<0 ) {
  243.             *(string++) = '-';
  244.             num = -num;
  245.         }
  246.         numtoascii(num>>decimalplace, &string );
  247.         if(numberofdecimals!=0) *(string++) = '.';
  248.         for(i=0;i<numberofdecimals;i++) {
  249.             num %= 1<<decimalplace;
  250.             num *= 10;
  251.             *(string++) = '0' + (num>>decimalplace);
  252.         }
  253.         *(string++) = 0;
  254.     }
  255.  
  256.     void unsignedtoascii(uint16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals){ //decimalplace is number of decimals
  257.         uint8_t i;
  258.         numtoascii(num>>decimalplace, &string );
  259.         if(numberofdecimals!=0) *(string++) = '.';
  260.         for(i=0;i<numberofdecimals;i++) {
  261.             num %= 1<<decimalplace;
  262.             num *= 10;
  263.             *(string++) = '0' + (num>>decimalplace);
  264.         }
  265.         *(string++) = 0;
  266.     }
  267.