SPIKE-RT C++ API Reference
Loading...
Searching...
No Matches
ColorSensor.h
1//
2// ColorSensor.h
3//
4// Copyright (c) 2025 Embedded Technology Software Design Robot Contest
5//
6
7#ifndef SPIKE_CPP_API_COLOR_SENSOR_H_
8#define SPIKE_CPP_API_COLOR_SENSOR_H_
9
10#include <stdint.h>
11extern "C" {
12#include <pup/colorsensor.h>
13}
14
15#include "Port.h"
16
17namespace spikeapi {
22{
23public:
24
25 struct RGB {
26 uint16_t r;
27 uint16_t g;
28 uint16_t b;
29 };
30
31 struct HSV {
32 uint16_t h;
33 uint8_t s;
34 uint8_t v;
35 };
36
41 ColorSensor(EPort port) {
42 mDevice = pup_color_sensor_get_device(static_cast<pbio_port_id_t>(port));
43 }
44
50 void getRGB(RGB& rgb) const {
51 pup_color_rgb_t pup_rgb = pup_color_sensor_rgb(mDevice);
52 rgb.r = pup_rgb.r;
53 rgb.g = pup_rgb.g;
54 rgb.b = pup_rgb.b;
55 }
56
62 void getColor(HSV& hsv, bool surface = true) const {
63 pup_color_hsv_t pup_hsv = pup_color_sensor_color(mDevice, surface);
64 hsv.h = pup_hsv.h;
65 hsv.s = pup_hsv.s;
66 hsv.v = pup_hsv.v;
67 }
68
74 void getHSV(HSV& hsv, bool surface = true ) const {
75 pup_color_hsv_t pup_hsv = pup_color_sensor_hsv(mDevice, surface);
76 hsv.h = pup_hsv.h;
77 hsv.s = pup_hsv.s;
78 hsv.v = pup_hsv.v;
79 }
80
85 int32_t getReflection() const {
86 return pup_color_sensor_reflection(mDevice);
87 }
88
93 int32_t getAmbient() const {
94 return pup_color_sensor_ambient(mDevice);
95 }
96
104 void setLight(int32_t bv1, int32_t bv2, int32_t bv3) const {
105 pup_color_sensor_light_set(mDevice, bv1, bv2, bv3);
106 }
107
113 void lightOn() const {
114 pup_color_sensor_light_on(mDevice);
115 }
116
122 void lightOff() const {
123 pup_color_sensor_light_off(mDevice);
124 }
125
132 void setDetectableColors(int32_t size, pup_color_hsv_t *colors) const {
133 pup_color_sensor_detectable_colors(size, colors);
134 }
135
140 bool hasError() { return mDevice == 0; }
141
142
143private:
144 pup_device_t *mDevice;
145}; // class ColorSensor
146} // namespace spikeapi
147
148#endif // !SPIKE_CPP_API_COLOR_SENSOR_H_
void setDetectableColors(int32_t size, pup_color_hsv_t *colors) const
Definition ColorSensor.h:132
bool hasError()
Definition ColorSensor.h:140
void getRGB(RGB &rgb) const
Definition ColorSensor.h:50
void setLight(int32_t bv1, int32_t bv2, int32_t bv3) const
Definition ColorSensor.h:104
void lightOff() const
Definition ColorSensor.h:122
ColorSensor(EPort port)
Definition ColorSensor.h:41
void getColor(HSV &hsv, bool surface=true) const
Definition ColorSensor.h:62
int32_t getReflection() const
Definition ColorSensor.h:85
void getHSV(HSV &hsv, bool surface=true) const
Definition ColorSensor.h:74
void lightOn() const
Definition ColorSensor.h:113
int32_t getAmbient() const
Definition ColorSensor.h:93
Definition ColorSensor.h:31
Definition ColorSensor.h:25