Merge branch 'hardware' into beta-0.4

This commit is contained in:
Robert Bendun 2023-01-13 10:58:39 +01:00
commit d6b0f39dc7
6 changed files with 19 additions and 12 deletions

BIN
hardware/MusiqueBox.fzz Normal file

Binary file not shown.

BIN
hardware/MusiqueBox_bb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 379 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 197 KiB

View File

@ -167,7 +167,8 @@ struct Runner
Interpreter interpreter;
std::shared_ptr<serialport::State> serial_state;
std::optional<std::jthread> serial_event_loop;
std::thread serial_event_loop;
std::atomic<bool> serial_event_loop_stop = false;
/// Setup interpreter and midi connection with given port
explicit Runner(std::optional<unsigned> output_port)
@ -183,8 +184,8 @@ struct Runner
interpreter.serialport = serial_state;
serialport::initialize();
serial_event_loop = std::jthread([this](std::stop_token token) mutable{
serialport::event_loop(token, *serial_state);
serial_event_loop = std::thread([this]() mutable {
serialport::event_loop(serial_event_loop_stop, *serial_state);
});
Env::global->force_define("say", +[](Interpreter &interpreter, std::vector<Value> args) -> Result<Value> {
@ -207,6 +208,13 @@ struct Runner
Runner& operator=(Runner const&) = delete;
Runner& operator=(Runner &&) = delete;
~Runner() {
serial_event_loop_stop = true;
if (serial_event_loop.joinable()) {
serial_event_loop.join();
}
}
/// Consider given input file as new definition of parametless function
///
/// Useful for deffering execution of files to the point when all configuration of midi devices

View File

@ -38,9 +38,9 @@ namespace serialport{
return 8;
}
void event_loop(std::stop_token token, State &state)
void event_loop(std::atomic<bool> &stop, State &state)
{
while(!token.stop_requested()){
while(!stop){
try {
/// Search for the right device
auto const ports = serial::list_ports();
@ -61,18 +61,18 @@ namespace serialport{
}
}
}
/// Start connection
serial::Serial serial_conn(connection_port, 115200, serial::Timeout::simpleTimeout(1000));
/*if(serial_conn.isOpen())
std::cout << "[SERIAL] Serial open\n";
else
std::cout << "[SERIAL] Serial not open\n";
std::cout << "[SERIAL] commence serial communication\n";
*/

View File

@ -3,7 +3,6 @@
#include <string>
#include <serial/serial.h>
#include <stop_token>
#include <memory>
#include <array>
#include <atomic>
@ -24,10 +23,10 @@ namespace serialport{
void send(uint8_t message_type, uint8_t note_number);
void set(unsigned position, std::uint32_t value);
};
void initialize();
void event_loop(std::stop_token token, State &state);
void event_loop(std::atomic<bool> &stop, State &state);
std::uint8_t get_byte();
}
#endif //MUSIQUE_SERIALPORT_SERIALPORT_HH
#endif //MUSIQUE_SERIALPORT_SERIALPORT_HH