Skip to content

Commit 4a9bf5e

Browse files
committed
feat: 🚧 create outline for screen
1 parent 9fc820a commit 4a9bf5e

File tree

3 files changed

+117
-0
lines changed

3 files changed

+117
-0
lines changed

include/pros/devices/brain.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#pragma once
22

33
#include "pros/devices/adi_expander.hpp"
4+
#include "pros/devices/screen.hpp"
45
#include "pros/rtos.hpp"
56

67
namespace zest {
@@ -68,6 +69,8 @@ class Brain {
6869
*/
6970
static void smart_port_mutex_unlock_all();
7071

72+
using Screen = zest::Screen;
73+
7174
private:
7275
static constinit std::array<pros::RecursiveMutex, 33> m_mutexes;
7376
};

include/pros/devices/screen.hpp

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#pragma once
2+
3+
#include "stdint.h"
4+
5+
#include <functional>
6+
7+
namespace zest {
8+
9+
struct Screen {
10+
/** Vertical height taken up by the user program in pixels. */
11+
static constexpr int16_t HEADER_HEIGHT = 32;
12+
/** The width of the screen in pixels. */
13+
static constexpr int16_t WIDTH = 480;
14+
/** The height of the screen in pixels, excludes the header. */
15+
static constexpr int16_t HEIGHT = 240;
16+
/** The framerate of the Brain is 60fps. */
17+
static constexpr int16_t FRAMERATE = 60;
18+
19+
/** A touch event on the screen. */
20+
struct TouchEvent {
21+
enum class State {
22+
/** The screen has been released. */
23+
Release,
24+
/** The screen has been touched. */
25+
Press,
26+
/** The screen has been touched and is still being held. */
27+
Held
28+
};
29+
30+
/** The y coordinate of the touch. */
31+
State state;
32+
/** The x coordinate of the touch. */
33+
int16_t x;
34+
/** The y coordinate of the touch. */
35+
int16_t y;
36+
37+
// TODO: Determine when it starts counting
38+
/** The number of times the screen has been pressed. */
39+
int32_t pressCount;
40+
/** The number of times the screen has been released. */
41+
int32_t releaseCount;
42+
};
43+
44+
/**
45+
* @brief Gets the most recent touch event.
46+
*
47+
* TODO: Determine the starting return value (Before the screen is touched).
48+
*
49+
* @return The most recent touch event.
50+
*/
51+
static TouchEvent get_last_touch();
52+
53+
/**
54+
* @brief Subscribes the listener to be called when the screen begins to be pressed.
55+
*
56+
* Spawn a new task to check for events if it is not already running.
57+
* All listeners are called from this task.
58+
*
59+
* @warning If you have multiple listeners, avoid using delays, which can delay other callbacks
60+
* from being called, and result in lost information.
61+
* For this reason, it is recommended library developers use get_last_touch() instead of this
62+
* function.
63+
*
64+
* @param listener_cb The function to call when the screen is pressed.
65+
*/
66+
static void on_pressed(std::function<void(const TouchEvent&)> listener_cb);
67+
68+
/**
69+
* @brief Subscribes the listener to be called when the screen begins to be released.
70+
*
71+
* Spawn a new task to check for events if it is not already running.
72+
* All listeners are called from this task.
73+
*
74+
* @warning If you have multiple listeners, avoid using delays, which can delay other callbacks
75+
* from being called, and result in lost information.
76+
* For this reason, it is recommended library developers use get_last_touch() instead of this
77+
* function.
78+
*
79+
* @param listener_cb The function to call when the screen is pressed.
80+
*/
81+
static void on_released(std::function<void(const TouchEvent&)> listener_cb);
82+
83+
// TODO: Should there be a on_held() function?
84+
85+
static void set_render_mode();
86+
static void get_render_mode();
87+
static void render();
88+
static void scroll();
89+
static void scroll_region();
90+
91+
// TODO: Should these be a single function? see:
92+
// https://docs.rs/vexide/latest/vexide/devices/display/struct.Display.html#method.fill
93+
static void draw_rect();
94+
static void draw_circle();
95+
static void draw_line();
96+
static void draw_pixel();
97+
98+
static void fill_rect();
99+
static void fill_circle();
100+
101+
// Should likely use a text object, like vexide does:
102+
// https://docs.rs/vexide/latest/vexide/devices/display/struct.Text.html
103+
static void draw_text();
104+
105+
static void clear(auto color /* = TODO*/);
106+
107+
static void draw_buffer();
108+
};
109+
110+
} // namespace zest

src/devices/screen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include "pros/devices/screen.hpp"
2+
3+
#include "v5_api_patched.h"
4+
#include "v5_apitypes_patched.h"

0 commit comments

Comments
 (0)