Skip to content

Adding a new layout for schedulingGetImage

Johnathan Andersen edited this page Dec 17, 2018 · 8 revisions

At some point, it may be desirable to add a new layout for schedulingGetImage. This will need to happen mainly in cplusplussource/layouts.cpp. The easiest way to add a layout is to copy a different layout (such as drawImage7), then modify it. Some useful information on this follows:

Useful functions

uint32_t setSleepTime(uint32_t increment)

This function sets the sleep time for the device based off of the increment submitted. Increment is a positive integer in seconds. It will try to make all of your Wall-Ink devices refresh at the same time. If you set your increment to 1800 (30 minutes), it will tell them to refresh 2 minutes before the next half-hour mark. For example, setSleepTime(1800);. It returns the time until the device will next check in, in seconds.

void canvas->setFont(const GFXfont *f)

This function is taken from the Adafruit GFX library. Use this to set the font used by drawFancyString. For example, canvas->setFont(&FreeSansBold18pt7b);. A list of usable fonts can be found in cplusplussource/fonts.h.

void canvas->setTextColor(uint16_t c)

This function is taken from the Adafruit GFX library. Sets the text color. Should work with 1 or 0. For example, canvas->setTextColor(1);

void canvas->setTextWrap(bool w)

This function is taken from the Adafruit GFX library. Sets whether text drawn by drawFancyString will wrap around the edge of the screen. For example, ```canvas->setTextWrap(false);``

void drawFancyString(std::string str, int16_t x, int16_t y);

Draws a string with the settings set by the above functions. The coordinate it takes in corresponds with the upper-left corner of the text. For example, drawFancyString(currentTitle, 8, 140);

std::vector<reservation> parseReservations(std::string* reservations)

Takes in the reservations array and returns a vector with the information organized into a more usable format. For example, std::vector<reservation> reservs = parseReservations(reservations);

void drawRect(int x, int y, int width, int height, unsigned char color)

Draws a rectangle of the specified size & color at the specified spot. For example, ```drawRect(xOffset, yOffset, 48, 23, 1);

uint16_t getTextWidth(std::string str)

Returns the width the text would be, were it to be drawn. For example, getTextWidth("foo");

uint16_t putQrCode(uint16_t x, uint16_t y, std::string str, uint16_t scale)

Draws a QR code onto the screen at (x,y). The QR code is generated with str and scale, where scale is a multiplier for pixel width & height. It returns the size of the QR code image. For example, putQrCode(333,10,websiteUrl,2);

std::string reservationBlockToTime(int block)

Takes in an integer index to the reservation array and returns the human-readable 24hr time that the index corresponds with. For example, std::string time = reservationBlockToTime(5);

std::string militaryTimeToNormalPersonTime(std::string military)

Takes in a string from the reservationBlockToTime function, and returns a string formatted in a 12-hour format. For example, std::string time = militaryTimeToNormalPersonTime(reservationBlockToTime(5));

Important variables

std::string reservations[32]

An array of reservation titles at various times of day. Each string is initialized to "Available". Each string corresponds with a 30-minute time block (in chronological order). The first block corresponds with 6:00am-6:30am.

GFXcanvas1* canvas

This is the canvas that is being drawn on. The pixel buffer is also pointed to by the uint8_t* image variable.

After editing layouts.cpp

Edit layouts.h

Edit the layouts.h header to contain a declaration for your function.

Edit image.cpp

There's a big, long if statement in image.cpp's main function that defines the screen resolution based off of the device type. Make sure to define a screen resolution for the device type corresponding with your layout.

There's another big, long if statement that looks at the device type and calls a corresponding drawImage function. Make sure that your function can get called here.

Edit web/plugin_dependencies/general_scheduling/schedulingGetDeviceType.php

Edit web/plugin_dependencies/general_scheduling/schedulingGetDeviceType.php so that the device type corresponding with your layout is an option.