Skip to content

Commit 4bd5097

Browse files
committed
Keep button with the timer
1 parent 1cbe7a0 commit 4bd5097

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

main.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ static M2MResource* m2m_deregister_res;
3939

4040
EventQueue queue(32 * EVENTS_EVENT_SIZE);
4141
Thread t;
42+
Mutex value_increment_mutex;
4243

4344
void print_client_ids(void)
4445
{
@@ -49,8 +50,10 @@ void print_client_ids(void)
4950

5051
void value_increment(void)
5152
{
53+
value_increment_mutex.lock();
5254
m2m_get_res->set_value(m2m_get_res->get_value_int() + 1);
5355
printf("Counter %" PRIu64 "\n", m2m_get_res->get_value_int());
56+
value_increment_mutex.unlock();
5457
}
5558

5659
void put_update(const char* /*object_name*/)
@@ -163,7 +166,7 @@ int main(void)
163166
// PUT resource 3201/0/5853
164167
m2m_put_res = M2MInterfaceFactory::create_resource(m2m_obj_list, 3201, 0, 5853, M2MResourceInstance::INTEGER, M2MBase::GET_PUT_ALLOWED);
165168
if (m2m_put_res->set_value(0) != true) {
166-
printf("m2m_led_res->set_value() failed\n");
169+
printf("m2m_put_res->set_value() failed\n");
167170
return -1;
168171
}
169172
if (m2m_put_res->set_value_updated_function(put_update) != true) {
@@ -195,7 +198,7 @@ int main(void)
195198
cloud_client->setup(network); // cloud_client->setup(NULL); -- https://jira.arm.com/browse/IOTCLT-3114
196199

197200
t.start(callback(&queue, &EventQueue::dispatch_forever));
198-
queue.call_every(10000, value_increment);
201+
queue.call_every(5000, value_increment);
199202

200203
while(cloud_client_running) {
201204
int in_char = getchar();
@@ -207,6 +210,9 @@ int main(void)
207210
printf("Storage erased, rebooting the device.\n\n");
208211
wait(1);
209212
NVIC_SystemReset();
213+
} else if (in_char > 0 && in_char != 0x03) { // Ctrl+C is 0x03 in Mbed OS and Linux returns negative number
214+
value_increment(); // Simulate button press
215+
continue;
210216
}
211217
deregister_client();
212218
break;

0 commit comments

Comments
 (0)