SPIKE-RT C API Reference [Japanese]
An RTOS-based software platform for LEGO® Education SPIKE™.
読み取り中…
検索中…
一致する文字列を見つけられません
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 <cstdint>
11extern "C" {
13}
14
15#include <libcpp/spike/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 {
115 }
116
122 void lightOff() const {
124 }
125
132 void setDetectableColors(int32_t size, pup_color_hsv_t *colors) const {
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_
Definition ColorSensor.h:22
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
API for color sensors
int32_t pup_color_sensor_ambient(pup_device_t *pdev)
周囲の光の強度を測定する。
Definition colorsensor.c:244
pbio_error_t pup_color_sensor_light_on(pup_device_t *pdev)
カラーセンサのライトを点灯する。
Definition colorsensor.c:266
pup_color_hsv_t pup_color_sensor_hsv(pup_device_t *pdev, bool surface)
カラーセンサで色を測定する。
Definition colorsensor.c:195
pbio_error_t pup_color_sensor_light_off(pup_device_t *pdev)
カラーセンサのライトを消灯する。
Definition colorsensor.c:270
pbio_color_hsv_t pup_color_hsv_t
カラーセンサで色を測定する。
Definition colorsensor.h:91
pup_device_t * pup_color_sensor_get_device(pbio_port_id_t port)
ポートIDで指定されたカラーセンサへのPUPデバイスポインタを取得する。
Definition colorsensor.c:177
pup_color_hsv_t * pup_color_sensor_detectable_colors(int32_t size, pup_color_hsv_t *colors)
カラーセンサが検知する色を設定する。
Definition colorsensor.c:274
pbio_error_t pup_color_sensor_light_set(pup_device_t *pdev, int32_t bv1, int32_t bv2, int32_t bv3)
カラーセンサのライトを設定する。
Definition colorsensor.c:258
int32_t pup_color_sensor_reflection(pup_device_t *pdev)
センサーの発する光を表面がどの程度反射するかを測定する。
Definition colorsensor.c:232
Definition pup_device.c:21
カラーセンサのRGB値を返す.
Definition colorsensor.h:70
Definition ColorSensor.h:31
Definition ColorSensor.h:25