Subversion Repositories HomeAutomation

Rev

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