Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed PinDetect TextLCD
Fork of FWFSU_Start_28102013 by
Revision 17:ce5a80e8fc8e, committed 2016-08-02
- Comitter:
- manuelfederanko
- Date:
- Tue Aug 02 09:54:13 2016 +0000
- Parent:
- 16:78da467a0609
- Child:
- 18:e69ae6ebcec3
- Commit message:
- Fixed a bug, when pressing stop right after a reset caused the program to break.
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/linked_list.lib Tue Aug 02 09:54:13 2016 +0000 @@ -0,0 +1,1 @@ +linked_list#bc209b9f1edc
--- a/main.cpp Tue Aug 02 07:47:35 2016 +0000
+++ b/main.cpp Tue Aug 02 09:54:13 2016 +0000
@@ -2,7 +2,7 @@
#define PING_TIMEOUT 50000 //5 seconds
-run_time times[MAX_ROUND_CNT - MIN_ROUND_CNT];
+struct linked_list *times;
/**
* Controls the button presses:
@@ -113,7 +113,23 @@
comm_flags = 0;
buzzer_state = 0;
button_state = 0;
- D = MIN_ROUND_CNT;
+ D = MIN_ROUND_CNT;
+
+ if (times != NULL) {
+ deleteList(times);
+ times = initNode();
+ }
+}
+
+void reinit_list( void ) {
+ struct run_time *rt = (struct run_time *)malloc(sizeof(struct run_time));
+ times = getLast(times);
+ rt->start = start_tm;
+ rt->snap0 = snapshot0;
+ rt->snap1 = snapshot1;
+ rt->end = end_tm;
+ times->data = (void *) rt;
+ appendNode(times, initNode());
}
/**
@@ -130,11 +146,13 @@
switch(rec_code) {
case MSG_CODE_KILL:
+ deleteList(times);
shutdown_seq(); //the other device will already be shut down when we send the kill signal again, thus it doesn't matter if we do.
break;
case MSG_CODE_PING:
break;
case MSG_CODE_RESET:
+ reinit_list();
reset();
break;
case MSG_CODE_START:
@@ -143,12 +161,14 @@
case MSG_CODE_STOP:
//pin is the time for a two way signal, if it just needs to travel from 1 device to the other, one must half it for the correct result
//end_tm = systime - pin;
- end_tm = systime;
- comm_flags |= FLAG_STOP;
- int_to_str(end_tm, rec_buff);
- ser.sendCode(MSG_CODE_TMP, rec_buff);
- ser.flush();
- btn_cnt = 5; //otherwise we could press stop again and the end_tm value would be replaced by systime once again
+ if (comm_flags & FLAG_START) { //resetting and pressing stop right afterwards breaks the code, one would need to reset again to start the time.
+ end_tm = systime;
+ comm_flags |= FLAG_STOP;
+ int_to_str(end_tm, rec_buff);
+ ser.sendCode(MSG_CODE_TMP, rec_buff);
+ ser.flush();
+ btn_cnt = 5; //otherwise we could press stop again and the end_tm value would be replaced by systime once again
+ }
break;
case MSG_CODE_TOTAL_RESET:
// NOTHING
@@ -169,10 +189,7 @@
}
void bzr_held_pressed( void ) {
- //times[D-MIN_ROUND_CNT].start = start_tm;
- //times[D-MIN_ROUND_CNT].snap0 = snapshot0;
- //times[D-MIN_ROUND_CNT].snap1 = snapshot1;
- //times[D-MIN_ROUND_CNT].end = end_tm;
+ reinit_list();
reset();
ser.sendCode(MSG_CODE_RESET, NULL);
ser.flush();
@@ -183,6 +200,7 @@
}
void btn_held_released( void ) {
+ deleteList(times);
shutdown_seq();
}
@@ -195,6 +213,67 @@
//init
init_io();
init_values();
+ times = NULL;
+ tick.attach_us(&handle_systime, 100); //every 100 us
+ pb1.attach_asserted(&bzr_pressed);
+ pb1.attach_asserted_held(&bzr_held_pressed);
+ pb1.setSamplesTillHeld(2000); //2000 samples ---> 1ms ---> 2 seconds
+ pb1.setSampleFrequency(1000); //1ms
+
+ pb2.attach_asserted(&btn_pressed);
+ pb2.attach_deasserted_held(&btn_held_released);
+ pb2.setSamplesTillHeld(200);
+ pb2.setSampleFrequency();
+
+ //info
+ cprintf(RUNMODE_SERVER);
+ display();
+ wait(WAIT_INFO_TM);
+
+ //config
+ config_buttons();
+ config_rf_mod();
+
+ //start
+ lowbatt();
+ ser.registerRecFc(&hdl_rec);
+ resync();
+
+ prev[0] = prev[1] = prev[2] = prev[3] = prev[4] = systime;
+
+ times = initNode();
+
+ while(1) {
+ if (systime - prev[2] >= RATE_DISPLAY) {
+ prev[2] = systime;
+ render_time();
+ display();
+ }
+ if (systime - prev[1] >= ((akku_state >= AKKU_1)? RATE_LED_NOK : RATE_LED_OK)) {
+ prev[1] = systime;
+ stoppled.write(!stoppled.read());
+ }
+ if (comm_flags & FLAG_INFO_LOCK && systime - info_tm >= RATE_SHOW_INFO) {
+ //if the flag is set it means, that we wanna show something and the time has been set --> if the difference bigger than the rate, then clear the flag
+ //the flag gets checked in the render_time function, to prevent that from overwriting the info text
+ comm_flags &= ~FLAG_INFO_LOCK;
+ }
+ if (systime - prev[0] >= RATE_CHECK_AKKU) {
+ prev[0] = systime;
+ akkucheck();
+
+ if (akku_state == AKKU_CRITICAL) {
+ shutdown_seq();
+ }
+ }
+ }
+}
+
+/*
+int main() {
+ //init
+ init_io();
+ init_values();
tick.attach_us(&handle_systime, 100); //every 100 us
pb1.attach_asserted(&bzr_pressed);
pb1.attach_asserted_held(&bzr_held_pressed);
@@ -219,33 +298,35 @@
lowbatt();
//ping();
ser.registerRecFc(&hdl_rec);
- resync();
-
- prev[0] = prev[1] = prev[2] = prev[3] = prev[4] = systime;
+
+ struct linked_list *base = initNode();
+ appendNode(base, initNode());
+ appendNode(base, initNode());
+ base->data = (void *) "abc";
+ base->next->data = (void *) "def";
+ base->next->next->data = (void *) "ghi";
+
+ struct linked_list *nd = initNode();
+
+ nd->data = (void *)"123";
+ insertNode(base->next, nd);
- while(1) {
- if (systime - prev[2] >= RATE_DISPLAY) {
- prev[2] = systime;
- render_time();
- display();
- }
- if (systime - prev[1] >= ((akku_state >= AKKU_1)? RATE_LED_NOK : RATE_LED_OK)) {
- prev[1] = systime;
- stoppled.write(!stoppled.read());
- }
- if (comm_flags & FLAG_INFO_LOCK && systime - info_tm >= RATE_SHOW_INFO) {
- //if the flag is set it means, that we wanna show something and the time has been set --> if the difference bigger than the rate, then clear the flag
- //the flag gets checked in the render_time function, to prevent that from overwriting the info text
- comm_flags &= ~FLAG_INFO_LOCK;
- }
- if (systime - prev[0] >= RATE_CHECK_AKKU) {
- prev[0] = systime;
- akkucheck();
+ nd = base->next;
+ removeNode(nd);
+ nd = base;
+ while (1) {
+ if (nd->data != NULL)
+ cprintf("%s", (char *) nd->data);
+ else
+ cprintf("");
- if (akku_state == AKKU_CRITICAL) {
- shutdown_seq();
- }
- }
+ display();
+ wait(2);
+
+ nd = nd->next;
+ if (nd == NULL)
+ nd = base;
}
-}
\ No newline at end of file
+}
+*/
\ No newline at end of file
--- a/main.h Tue Aug 02 07:47:35 2016 +0000
+++ b/main.h Tue Aug 02 09:54:13 2016 +0000
@@ -1,18 +1,9 @@
#include "common.h"
+#include "linked_list.h"
-struct run_time_ {
+struct run_time {
time_100us start;
time_100us snap0;
time_100us snap1;
time_100us end;
-};
-
-struct linked_list_ {
- struct linked_list_ *next;
- void *data;
-};
-
-typedef struct run_time_ run_time;
-typedef struct linked_list_ linked_list;
-
-extern run_time times[];
\ No newline at end of file
+};
\ No newline at end of file
