Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.99 KB | None | 0 0
  1. /*
  2. * This function handles the message, and set it up on the screen. This function also handles swedish characters such as
  3. * å, ä, ö, Å, Ä, Ö which need some extra consideration.
  4. */
  5. void message_handler() {
  6. String message_string; // A string to hold the message
  7. boolean special=false; // If special true a special chracter is present
  8. char c; // Chars to hold temporary characters from the message
  9. int c_temp;
  10. char s[2] = " "; // A char array to deal with special characters
  11. unsigned char xpos=0; // x and y position to handle the position of the text.
  12. unsigned char ypos=19;
  13.  
  14. message_string=current_notif->message;
  15. Serial.begin(9600);
  16. Serial.println( current_notif->title); // Draws the title and a line
  17. u8g.drawLine(0,9,127,9);
  18.  
  19. // Iterate through the whole message, chech if special character, and put character on screen.
  20. for(int i=0; i<message_string.length();i++){
  21.  
  22. c=message_string[i];
  23. c_temp=c;
  24. if(c_temp==-61){
  25. i++;
  26. special=true;
  27. c_temp=message_string[i];
  28.  
  29. switch(c_temp){
  30. case -123: //Å
  31. s[0] =197;
  32. break;
  33. case -124: //Ä
  34. s[0] =196;
  35. break;
  36. case -106: //Ö
  37. s[0] =214;
  38. break;
  39. case -91: //å
  40. s[0] =229;
  41. break;
  42. case -92: //ä
  43. s[0] =228;
  44. break;
  45. case -74: //ö
  46. s[0] =246;
  47. break;
  48. }
  49. }
  50.  
  51. if(xpos<=121 && ypos==19 && i<37){
  52. if(special){
  53. u8g.drawStr(xpos,ypos,s);
  54. }
  55. else{
  56. u8g.setPrintPos(xpos,ypos);
  57. u8g.print(c);
  58. }
  59. }
  60. else if(i<37){
  61. if(xpos>121){
  62. xpos=0;
  63. }
  64. ypos=30;
  65.  
  66. if(special){
  67. u8g.drawStr(xpos,ypos,s);
  68. }
  69. else{
  70. u8g.setPrintPos(xpos,ypos);
  71. u8g.print(c);
  72. }
  73. }
  74. else{
  75. u8g.drawStr(xpos,ypos,".");
  76. }
  77. special=false;
  78. xpos=xpos+6;
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement