bareMinimumDerivedClass.cpp 5.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #include "bareMinimumDerivedClass.h"
  2. // Constructor: at minimum pass in the size of the display
  3. /*
  4. xSize: number of pixels in the x direction of the display
  5. ySize: number of pixels in the y direction of the display
  6. *Note:
  7. This notation allows you to explicitly state what variables are passed to the parent class's constructor when the derived class' constructor is called.
  8. Additional direct or virtual base classes can also be initialized by a comma separated list with the same syntax - the 'deepest' base class is listed first.
  9. */
  10. bareMinDerived::bareMinDerived(uint16_t xSize, uint16_t ySize /* Additional Parameters */) : hyperdisplay(xSize, ySize) /* , anotherVirtualBaseClass(params), aDirectBaseClass(moreParams) */
  11. {
  12. // Perform setup of the derived class with any additional parameters here.
  13. }
  14. // getoffsetColor: allows hyperdisplay to use your custom color type
  15. /*
  16. base: the pointer to the first byte of the array that holds the color data
  17. numPixels: the number of pixels away from the beginning that the function should return the pointer to
  18. */
  19. color_t bareMinDerived::getOffsetColor(color_t base, uint32_t numPixels)
  20. {
  21. // This method is requried so that your color type can be totally flexible - be it an enumeration of three colors for an E-ink
  22. // display or a structure of bytes for 24-bit color it is totally up to you and how your display works.
  23. // This implementation will depend on how you choose to store colors, however one decent way to do it is provided as a reference:
  24. // This function returns an offset pointer according to the number of pixels and the _colorMode of the object
  25. // color_t pret = NULL;
  26. // your_color_type * ptemp = (your_color_type *)base; // Here's the magic. Cast the base pointer to a pointer of your color type to allow pointer arithmetic
  27. // pret = (color_t)(ptemp + numPixels); // The offset by the number of pixels. This will account for the number of bytes that your color type occupies
  28. // return pret; // And return the offset pointer
  29. }
  30. // hwPixel: the method by which hyperdisplay actually changes your screen
  31. /*
  32. x0, y0: the x and y coordinates at which to place the pixel. 0,0 is the upper-left corner of the screen, x is horizontal and y is vertical
  33. data: the pointer to where the color data is stored
  34. colorCycleLength: this indicates how many pixels worth of valid color data exist contiguously after the memory location pointed to by color.
  35. startColorOffset: this indicates how many pixels to offset by from the color pointer to arrive at the actual color to display
  36. */
  37. void bareMinDerived::hwpixel(uint16_t x0, uint16_t y0, color_t data, uint16_t colorCycleLength, uint16_t startColorOffset)
  38. {
  39. // Here you write the code that sets a pixel. It is up to you what to do with that data. Here are two basic options:
  40. // 1) Write directly to display ram: if you choose this option and your display supports it then this is all you need to show an image
  41. // 2) Write to a scratch space: you might use this option to compose a whole image and then show it all on the screen at once.
  42. // In that case you would need your own function that actually gets all that information to the display when the time is right.
  43. }
  44. // Additional hardware drawing functions
  45. /*
  46. There are additional hardware drawing functions beyond hwpixel. They are already implemented by default using
  47. hwpixel so they are not required in order to start drawing. However implementing them with more efficient
  48. methods for your particular hardware can reduce overhead and speed up the drawing process.
  49. In these functions the coordiantes x0, x1, y0, and y1 are always with respect to the hardware screen. (0,0) is the upper-left pixel
  50. The variables pertaining to color sequences (data, colorCycleLength, and startColorOffset) always have the same meaning as in hwpixel
  51. Additional variables will be described in the function prototype in bareMinimumDerivedClass.cpp
  52. */
  53. // void bareMinDerived::hwxline(uint16_t x0, uint16_t y0, uint16_t len, color_t data, uint16_t colorCycleLength = 1, uint16_t startColorOffset = 0, bool goLeft = false)
  54. // void bareMinDerived::hwyline(uint16_t x0, uint16_t y0, uint16_t len, color_t data, uint16_t colorCycleLength = 1, uint16_t startColorOffset = 0, bool goUp = false);
  55. // void bareMinDerived::hwrectangle(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, color_t data, bool filled = false, uint16_t colorCycleLength = 1, uint16_t startColorOffset = 0, bool gradientVertical = false, bool reverseGradient = false);
  56. // void bareMinDerived::hwfillFromArray(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint32_t numPixels, color_t data);
  57. // Additional optional implementations by the user:
  58. // ================================================
  59. // getCharInfo: you can create custom fonts without changing how printing functions work
  60. /*
  61. character: the byte-sized character to show on screen
  62. pchar: a pointer to a valid char_info_t object that needs to be filled out peroperly for the given character
  63. */
  64. // void getCharInfo(uint8_t character, char_info_t * pchar);
  65. // write: you decide what happens when someone calls bareMinDerived.print or bareMinDerived.println
  66. /*
  67. val: the byte-sized character value to display
  68. */
  69. // size_t write(uint8_t val);