RumPi 1.0
A self-assembling C++ sensor & actuator library for the Raspberry Pi 5
PiCamera.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdio.h>
4#include <stdlib.h>
5#include <thread>
6#include <string>
7#include "BaseComponent.h"
8
9namespace RumPi
10{
17 class PiCamera : public BaseComponent
18 {
19 private:
20 std::thread myConvertThread;
21
43 int SendCameraCommand(const char* programName, const char* fileName, unsigned int timeInSeconds, unsigned int width = 0U, unsigned int height = 0U, unsigned int fps = 0U, unsigned long bitRate = 0UL);
44
58 static void ConvertH264ToMP4(std::string fileName);
59 public:
70 PiCamera();
71
83 ~PiCamera();
84
95 virtual void TurnOn() override;
96
107 virtual void TurnOff() override;
108
119 virtual void ProcessRawValues() override;
120
133 virtual std::string ToString() const override;
134
148 void RecordVideo(const char* fileName, unsigned int durationInSeconds = 5U);
149
168 void RecordVideo(const char* fileName, unsigned int durationInSeconds, unsigned int width, unsigned int height, unsigned int fps, unsigned long bitRate);
169
183 void TakePicture(const char* fileName, unsigned int delayInSeconds = 1U);
184 };
185} // namespace RumPi
Abstract base class for every component (sensor, actuator, etc.) the library manages.
Definition: BaseComponent.h:60
Raspberry Pi camera, recording video (raw .h264 converted to .mp4 on a background thread) and taking ...
Definition: PiCamera.h:18
virtual std::string ToString() const override
Serializes the camera to a string.
Definition: PiCamera.cpp:100
virtual void TurnOff() override
No-op: the camera holds no persistent hardware state that needs releasing when turned off.
Definition: PiCamera.cpp:68
void TakePicture(const char *fileName, unsigned int delayInSeconds=1U)
Takes a picture and saves it to the given file after a short delay.
Definition: PiCamera.cpp:190
std::thread myConvertThread
The background thread that converts recorded .h264 video to .mp4.
Definition: PiCamera.h:20
void RecordVideo(const char *fileName, unsigned int durationInSeconds=5U)
Records video to the given file for a duration, then converts the raw .h264 to .mp4 on a background t...
Definition: PiCamera.cpp:123
virtual void ProcessRawValues() override
No-op: the camera produces media files on demand, so there are no raw values to process.
Definition: PiCamera.cpp:83
~PiCamera()
Destroys the camera, joining any in-progress video-conversion thread and turning off first.
Definition: PiCamera.cpp:32
static void ConvertH264ToMP4(std::string fileName)
Converts a raw .h264 video file to .mp4 (via MP4Box) and removes the original .h264 on success.
Definition: PiCamera.cpp:271
PiCamera()
Builds a Pi camera component.
Definition: PiCamera.cpp:16
int SendCameraCommand(const char *programName, const char *fileName, unsigned int timeInSeconds, unsigned int width=0U, unsigned int height=0U, unsigned int fps=0U, unsigned long bitRate=0UL)
Builds and runs a raspivid/raspistill OS command for the given program, output file,...
Definition: PiCamera.cpp:217
virtual void TurnOn() override
No-op: the camera is driven on demand via RecordVideo/TakePicture, so there is nothing to turn on.
Definition: PiCamera.cpp:53
RumPi is the library's top-level facade.
Definition: AlertManager.h:6