Subversion Repositories HomeAutomation

Rev

Rev 1006 | Rev 1031 | 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.  
  15. void numtoascii( int16_t num, char **str );
  16. void signedtoascii(int16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals);
  17. void unsignedtoascii(uint16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals);
  18.  
  19. void act_ks0108_Init(void)
  20. {
  21.     ///TODO: Initialize hardware etc here
  22.     DDRC |= (1<<PC0);
  23.     PORTC |= (1<<PC0);
  24.  
  25.     glcdPowerOn();
  26.  
  27.     uint16_t ixa = 0;
  28.     uint8_t jxa = 0;
  29.     for (jxa = 0; jxa< 8; jxa++){
  30.         glcdSetXY(0,jxa*8);
  31.         for (ixa = 0; ixa < 128; ixa++){
  32.             glcdWriteData((uint8_t)pgm_read_byte((uint16_t)&Splash_left+ixa+jxa*128), GLCD_COLOR_CLEAR);
  33.         }
  34.     }
  35.     glcdSetXY(0,0);
  36.     glcdPutStrTransparent("=_-[]_-=",GLCD_COLOR_SET);
  37.     glcdSetXY(0,8);
  38.     glcdPutStrTransparent("--------",GLCD_COLOR_SET);
  39.     glcdSetXY(0,16);
  40.     glcdPutStr("-_=[]=-_",GLCD_COLOR_SET);
  41.     glcdDrawRect(32, 32, 40, 16, GLCD_COLOR_SET);
  42.     glcdDrawLine(10, 10, 100, 60, GLCD_COLOR_SET);
  43.     glcdFillRect(90, 10, 20, 20, GLCD_COLOR_SET);
  44.     glcdInvertRect(28, 10, 20, 20);
  45.     glcdInvert();
  46.     glcdDrawRoundRect(85, 5, 30, 30, 5, GLCD_COLOR_SET);
  47.     glcdDrawCircle(64, 32, 10, 1);
  48.     glcdSetXY(12,40);
  49.     glcdPutStrTransparent("Hejsan",GLCD_COLOR_CLEAR);
  50.     glcdDrawLine(10, 62, 50, 5, GLCD_COLOR_CLEAR);
  51.    
  52. }
  53.  
  54. void act_ks0108_Process(void)
  55. {
  56.     ///TODO: Stuff that needs doing is done here
  57. }
  58.  
  59. void act_ks0108_HandleMessage(StdCan_Msg_t *rxMsg)
  60. {
  61.     StdCan_Msg_t txMsg;
  62.     uint8_t n = 0;
  63.  
  64.     if (    StdCan_Ret_class(rxMsg->Header) == CAN_MODULE_CLASS_ACT &&
  65.         StdCan_Ret_direction(rxMsg->Header) == DIRECTIONFLAG_TO_OWNER &&
  66.         rxMsg->Header.ModuleType == CAN_MODULE_TYPE_ACT_KS0108 &&
  67.         rxMsg->Header.ModuleId == act_ks0108_ID)
  68.     {
  69.     switch (rxMsg->Header.Command)
  70.     {
  71.         case CAN_MODULE_CMD_KS0108_LCD_CLEAR:
  72.           glcdSetColor((0x7f&rxMsg->Data[0])>>7);
  73.           glcdClear();
  74.           break;
  75.  
  76.         case CAN_MODULE_CMD_KS0108_LCD_CURSOR:
  77.           glcdSetXY(rxMsg->Data[0], rxMsg->Data[1]);
  78.           break;
  79.  
  80.         case CAN_MODULE_CMD_KS0108_LCD_TEXTAT:
  81.           glcdSetXY((0x3f&rxMsg->Data[0])*6, rxMsg->Data[1]*8);
  82.           for (n = 2; n < rxMsg->Length; n++)
  83.           {
  84.               glcdWriteChar((char)rxMsg->Data[n], (0x7f&rxMsg->Data[0])>>7);
  85.           }
  86.         break;
  87.  
  88.         case CAN_MODULE_CMD_KS0108_LCD_TEXT:
  89.         for (n = 0; n < rxMsg->Length; n++)
  90.         {
  91.             glcdWriteChar((char)rxMsg->Data[n], GLCD_COLOR_SET);
  92.         }
  93.         break;
  94.  
  95.         case CAN_MODULE_CMD_KS0108_LCD_BACKLIGHT:
  96.         if (rxMsg->Length > 0) {
  97.           if (rxMsg->Data[0] > 127)
  98.             PORTC |= (1<<PC0);
  99.           else
  100.             PORTC &= ~(1<<PC0);
  101. /*
  102. #if (act_hd44780_TYPE==0)
  103.             OCR1AL = rxMsg->Data[0];
  104. #else
  105.             OCR0B = rxMsg->Data[0];
  106. #endif
  107. */
  108.         }
  109.         StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
  110.         StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  111.         txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_KS0108;
  112.         txMsg.Header.ModuleId = act_ks0108_ID;
  113.         txMsg.Header.Command = CAN_MODULE_CMD_KS0108_LCD_BACKLIGHT;
  114.         txMsg.Length = 1;
  115.        
  116.         txMsg.Data[0] = PORTC & (1<<PC0);
  117. /*
  118. #if (act_hd44780_TYPE==0)
  119.             txMsg.Data[0] = OCR1AL;
  120. #else
  121.             txMsg.Data[0] = OCR0B;
  122. #endif
  123. */
  124.  
  125.         while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  126.         break;
  127.         }
  128.     }
  129. /*
  130.     static uint8_t saer=0;
  131.     static uint8_t saer2=0;
  132.     saer++;
  133.     if (saer>10) {
  134.         saer2++;
  135.         uint8_t ixa = 0;
  136.         uint8_t jxa = 0;
  137.         for (jxa = 0; jxa< 8; jxa++){
  138.             glcdSetXY(0,jxa);
  139.             for (ixa = 0; ixa < 128; ixa++){
  140.                 glcdWriteData((uint8_t)pgm_read_byte((uint16_t)&Splash_left+ixa+jxa*128));
  141.             }
  142.         }
  143.         saer=0;
  144.         glcdSetXY(83,1);
  145.         glcdPutStr("Tycker ");
  146.         glcdSetXY(83,2);
  147.         glcdPutStr(" detta ");
  148.         glcdSetXY(83,3);
  149.         glcdPutStr("funkar!");
  150.         glcdSetXY(83,4);
  151.         char buffer[20];   
  152.         //numtoascii((int16_t)saer2 ,*buffer);
  153.         unsignedtoascii((int16_t)saer2,0,buffer,1);
  154.         glcdPutStr(buffer);
  155.     }
  156. */
  157. }
  158.  
  159. void act_ks0108_List(uint8_t ModuleSequenceNumber)
  160. {
  161.     StdCan_Msg_t txMsg;
  162.  
  163.     StdCan_Set_class(txMsg.Header, CAN_MODULE_CLASS_ACT);
  164.     StdCan_Set_direction(txMsg.Header, DIRECTIONFLAG_FROM_OWNER);
  165.     txMsg.Header.ModuleType = CAN_MODULE_TYPE_ACT_KS0108;
  166.     txMsg.Header.ModuleId = act_ks0108_ID;
  167.     txMsg.Header.Command = CAN_MODULE_CMD_GLOBAL_LIST;
  168.     txMsg.Length = 6;
  169.  
  170.     txMsg.Data[0] = NODE_HW_ID_BYTE0;
  171.     txMsg.Data[1] = NODE_HW_ID_BYTE1;
  172.     txMsg.Data[2] = NODE_HW_ID_BYTE2;
  173.     txMsg.Data[3] = NODE_HW_ID_BYTE3;
  174.  
  175.     txMsg.Data[4] = NUMBER_OF_MODULES;
  176.     txMsg.Data[5] = ModuleSequenceNumber;
  177.  
  178.     while (StdCan_Put(&txMsg) != StdCan_Ret_OK);
  179. }
  180.  
  181. //� la pengi. Skall libbifieras.
  182.     void numtoascii( int16_t num, char **str ) {
  183.         if( num==0 ) return;
  184.         numtoascii( num/10, str );
  185.         **str = '0' + (num%10);
  186.         (*str)++;
  187.     }
  188.  
  189.     void signedtoascii(int16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals){ //decimalplace is number of decimals
  190.         uint8_t i;
  191.  
  192.         if( num<0 ) {
  193.             *(string++) = '-';
  194.             num = -num;
  195.         }
  196.         numtoascii(num>>decimalplace, &string );
  197.         if(numberofdecimals!=0) *(string++) = '.';
  198.         for(i=0;i<numberofdecimals;i++) {
  199.             num %= 1<<decimalplace;
  200.             num *= 10;
  201.             *(string++) = '0' + (num>>decimalplace);
  202.         }
  203.         *(string++) = 0;
  204.     }
  205.  
  206.     void unsignedtoascii(uint16_t num, uint8_t decimalplace, char *string, uint8_t numberofdecimals){ //decimalplace is number of decimals
  207.         uint8_t i;
  208.         numtoascii(num>>decimalplace, &string );
  209.         if(numberofdecimals!=0) *(string++) = '.';
  210.         for(i=0;i<numberofdecimals;i++) {
  211.             num %= 1<<decimalplace;
  212.             num *= 10;
  213.             *(string++) = '0' + (num>>decimalplace);
  214.         }
  215.         *(string++) = 0;
  216.     }
  217.