Skip to content

Commit 33a49a8

Browse files
committed
CMCS_Oscilloscope WIP
1 parent 5c4891a commit 33a49a8

File tree

24 files changed

+440
-427
lines changed

24 files changed

+440
-427
lines changed

Diff for: CMakeLists.txt

+8-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.23)
2-
project(Projet_KMC_simul)
2+
project(C51MicroControllerSimulator)
33

44
include(FetchContent)
55

@@ -71,6 +71,11 @@ add_custom_command(TARGET ${CMAKE_PROJECT_NAME} PRE_BUILD
7171
"${PROJECT_SOURCE_DIR}/extensions/CMCS_GUI/data"
7272
$<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>/data)
7373

74+
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} PRE_BUILD
75+
COMMAND ${CMAKE_COMMAND} -E copy_directory
76+
"${PROJECT_SOURCE_DIR}/extensions/CMCS_Oscilloscope/data"
77+
$<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>/data)
78+
7479
add_custom_command(TARGET ${CMAKE_PROJECT_NAME} PRE_BUILD
7580
COMMAND ${CMAKE_COMMAND} -E copy_directory
7681
"${PROJECT_SOURCE_DIR}/data"
@@ -98,5 +103,5 @@ add_custom_command(TARGET ${CMAKE_PROJECT_NAME} PRE_BUILD
98103
$<TARGET_FILE_DIR:${CMAKE_PROJECT_NAME}>)
99104

100105
#Extensions
101-
102-
add_subdirectory(extensions/CMCS_GUI)
106+
add_subdirectory(extensions/CMCS_GUI)
107+
add_subdirectory(extensions/CMCS_Oscilloscope)

Diff for: extensions/CMCS_GUI/C_pin.cpp

+15-1
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ Pin::Pin(const SDL_FPoint& pos, uint8_t* dataStat, std::size_t posStat,
1313
this->setPosition(pos);
1414
}
1515

16-
void Pin::update(const SDL_Event& event)
16+
bool Pin::update(const SDL_Event& event)
1717
{
18+
bool returnTrueIfPressed = false;
19+
1820
if (event.type == SDL_MOUSEMOTION)
1921
{
2022
SDL_FPoint mousePos = {(float)event.motion.x, (float)event.motion.y};
@@ -42,6 +44,7 @@ void Pin::update(const SDL_Event& event)
4244
this->g_stat = !this->g_stat;
4345
}
4446
}
47+
returnTrueIfPressed = true;
4548
}
4649
}
4750
else if (event.type == SDL_MOUSEBUTTONUP)
@@ -60,6 +63,8 @@ void Pin::update(const SDL_Event& event)
6063
{
6164
this->g_sprite.setColorMod({255, 255, 255, 255});
6265
}
66+
67+
return returnTrueIfPressed;
6368
}
6469
void Pin::draw(SDL_Renderer* renderer) const
6570
{
@@ -104,6 +109,15 @@ bool Pin::getStat() const
104109
return this->g_stat;
105110
}
106111

112+
cmcs::Bits<uint8_t>& Pin::getBitsStat()
113+
{
114+
return this->g_stat;
115+
}
116+
cmcs::Bits<uint8_t>& Pin::getBitsOutputMod()
117+
{
118+
return this->g_outputMod;
119+
}
120+
107121
void Pin::setOutputMod(bool mod)
108122
{
109123
this->g_outputMod = mod;

Diff for: extensions/CMCS_GUI/C_pin.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Pin
1212
Pin(const SDL_FPoint& pos, uint8_t* dataStat, std::size_t posStat,
1313
uint8_t* dataOutputMod, std::size_t posOutputMod);
1414

15-
void update(const SDL_Event& event);
15+
bool update(const SDL_Event& event);
1616
void draw(SDL_Renderer* renderer) const;
1717

1818
void setPosition(const SDL_FPoint& pos);
@@ -24,6 +24,9 @@ class Pin
2424
void setStat(bool stat);
2525
bool getStat() const;
2626

27+
cmcs::Bits<uint8_t>& getBitsStat();
28+
cmcs::Bits<uint8_t>& getBitsOutputMod();
29+
2730
void setOutputMod(bool mod);
2831

2932
private:

Diff for: extensions/CMCS_GUI/main.cpp

+25-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <string>
99
#include <vector>
1010
#include <thread>
11+
#include <functional>
1112

1213
#define NUM_OF_PORTS 3
1314

@@ -16,6 +17,8 @@ using namespace cmcs;
1617
ShareableData* gCoreData;
1718
std::thread* gThread;
1819
bool gRunning;
20+
std::shared_ptr<SharedData> gPinPressedCallbacks;
21+
using gPinPressedCallbacks_t = std::vector<std::function<void(uint8_t*, std::size_t, uint8_t*, std::size_t)> >;
1922

2023
void ThreadUpdate()
2124
{
@@ -94,10 +97,10 @@ void ThreadUpdate()
9497
float posx=0.0f;
9598
float posy=20.0f;
9699
pins.resize(NUM_OF_PORTS);
97-
for (unsigned int i=0; i<NUM_OF_PORTS; ++i)
100+
for (std::size_t i=0; i<NUM_OF_PORTS; ++i)
98101
{
99102
pins[i].reserve(8);
100-
for (unsigned int a=0; a<8; ++a)
103+
for (std::size_t a=0; a<8; ++a)
101104
{
102105
pins[i].emplace_back(SDL_FPoint{posx, posy}, dataPorts[i], 7-a, dataPortOutputModes[i], 7-a);
103106
pins[i].back().setLedTextures(textureLedOn, textureLedOff);
@@ -122,11 +125,20 @@ void ThreadUpdate()
122125
{
123126
gRunning=false;
124127
}
125-
for (unsigned int i=0; i<NUM_OF_PORTS; ++i)
128+
for (std::size_t i=0; i<pins.size(); ++i)
126129
{
127-
for (unsigned int a=0; a<8; ++a)
130+
for (std::size_t a=0; a<pins[i].size(); ++a)
128131
{
129-
pins[i][a].update(event);
132+
if ( pins[i][a].update(event) )
133+
{//The button has been pressed
134+
auto callbacks = gPinPressedCallbacks->acquirePointer<gPinPressedCallbacks_t>();
135+
for (auto& callback : *callbacks.second)
136+
{
137+
auto& stat = pins[i][a].getBitsStat();
138+
auto& outputMod = pins[i][a].getBitsOutputMod();
139+
callback(stat.getData(), stat.getPos(), outputMod.getData(), outputMod.getPos());
140+
}
141+
}
130142
}
131143
}
132144
}
@@ -138,9 +150,9 @@ void ThreadUpdate()
138150

139151
SDL_RenderClear(renderer);
140152

141-
for (unsigned int i=0; i<pins.size(); ++i)
153+
for (std::size_t i=0; i<pins.size(); ++i)
142154
{
143-
for (unsigned int a=0; a<pins[i].size(); ++a)
155+
for (std::size_t a=0; a<pins[i].size(); ++a)
144156
{
145157
pins[i][a].draw(renderer);
146158
}
@@ -163,6 +175,10 @@ void ThreadUpdate()
163175

164176
CMCS_API void CMCSlib_Init(ShareableData& data)
165177
{
178+
//Shared data with others extensions
179+
static gPinPressedCallbacks_t pinPressedCallbacks;
180+
gPinPressedCallbacks = data.add(&pinPressedCallbacks, "CMCS_GUI:pinPressedCallbacks");
181+
166182
gRunning = true;
167183
gCoreData = &data;
168184
gThread = new std::thread(ThreadUpdate);
@@ -180,6 +196,8 @@ CMCS_API bool CMCSlib_Update()
180196

181197
CMCS_API void CMCSlib_Uninit()
182198
{
199+
gCoreData->remove("CMCS_GUI:pinPressedCallbacks");
200+
183201
gRunning = false;
184202
if (gThread->joinable())
185203
{

Diff for: extensions/CMCS_Oscilloscope/CMakeLists.txt

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
project(CMCS_Oscilloscope)
2+
3+
set(CMAKE_CXX_STANDARD 17)
4+
5+
set(CMAKE_SHARED_LIBRARY_PREFIX "")
6+
7+
include_directories(${PROJECT_NAME} ${SDL2_INCLUDE_DIR})
8+
include_directories(${PROJECT_NAME} ${CMAKE_CURRENT_SOURCE_DIR}/..)
9+
include_directories(${PROJECT_NAME} ${DRAWINGUTILS_INCLUDE_DIR})
10+
11+
add_library(${PROJECT_NAME} SHARED)
12+
13+
target_sources(${PROJECT_NAME} PRIVATE main.cpp)
14+
target_sources(${PROJECT_NAME} PRIVATE main.hpp)
15+
16+
target_sources(${PROJECT_NAME} PRIVATE ../CMCS_API.hpp)
17+
18+
target_link_libraries(${PROJECT_NAME} SDL2 SDL2_ttf drawingUtils replxx)
Binary file not shown.
Binary file not shown.
Binary file not shown.
File renamed without changes.

0 commit comments

Comments
 (0)