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: CANBuffer KS0108_fork mbed-rtos mbed CAN Addresses
Fork of REVO_Updated_Steering by
Revision 35:b42afc973902, committed 2014-11-22
- Comitter:
- palimar
- Date:
- Sat Nov 22 22:24:53 2014 +0000
- Parent:
- 34:9a4103f39042
- Child:
- 36:8544a8900884
- Commit message:
- Added linked list, also graphics updates only when variables change.
Changed in this revision
--- a/Steering.cpp Sat Nov 15 19:10:34 2014 +0000
+++ b/Steering.cpp Sat Nov 22 22:24:53 2014 +0000
@@ -4,45 +4,59 @@
bool NOT_biSWTR_HELD;
void update_display(void const *args){
-
-
+
while(true){
+ if(screen_flags[curr_screen] || should_redraw){
+ screen_flags[curr_screen] = 0;
+ should_redraw = false;
switch(curr_screen){
- case HOME_SCREEN:
-
+ case HOME_SCREEN:{
+
display.ClearScreen();
display.SelectFont(Arial10,BLACK,ReadData);
display.GotoXY(37,0);
- display.PrintString("Home Screen");
+ display.PrintString(" Home Screen");
+
+ display.GotoXY(22,30);
+ if(vars_list->get_value(PCM_STATE_ID) == 0){
+ display.PutString(17, 30, "Drive Status: OFF");
+ }
+ else{
+ display.PrintString("Drive Status: ON");
+ }
break;
+ }
case BATTERY_SCREEN:
display.ClearScreen();
display.SelectFont(Arial10,BLACK,ReadData);
display.GotoXY(33,0);
- display.PrintString("Battery Screen");
+ display.PrintString(" Battery Screen");
break;
default:
break;
+ }
}
wait(2);
}
}
void toggle_screen(){
- curr_screen = (curr_screen+1) % 2;
+ should_redraw = true;
+ curr_screen = (curr_screen+1) % NUM_SCREEN;
}
void request_status_change(){
char drive_status_request;
ds_mutex.lock();
- drive_status_request = !drive_status;
+ drive_status_request = !(vars_list->get_value(PCM_STATE_ID));
+
ds_mutex.unlock();
char * status_string;
@@ -58,11 +72,6 @@
CAN_Steering_Buffer.txWrite(Txmsg_drive_status_request);
}
- display.ClearScreen();
- display.SelectFont(Arial12,BLACK,ReadData);
- display.GotoXY(26,16);
- display.PrintString("DRIVE STATUS REQUEST");
-
printf("%s\n\r", status_string);
return;
}
@@ -78,7 +87,6 @@
display.ClearScreen();
display.SelectFont(Arial12,BLACK,ReadData);
display.GotoXY(16,16);
- display.PrintString(" RESET INITIATED");
printf("Reset Initiated\n\r");
return;
@@ -86,6 +94,7 @@
void Init()
{
+ should_redraw = true;
pc.baud(921600);
curr_screen = HOME_SCREEN;
drive_status = 0;
@@ -94,37 +103,32 @@
ledstream.write(0);
NOT_biSWBL_HELD = true;
NOT_biSWTR_HELD = true;
+
+ vars_list = new variables();
+
+ vars_list->add(PCM_STATE_ID, HOME_SCREEN);
+ vars_list->add(BATTERY_VOLTAGE_ID, BATTERY_SCREEN);
+ vars_list->add(BATTERY_POWER_ID, BATTERY_SCREEN);
+ vars_list->add(BATTERY_CURRENT_ID, BATTERY_SCREEN);
+
}
void read_messages(void const *args) {
while (true) {
+
CANMessage Rxmsg;
-
- if(CAN_Steering_Buffer.rxRead(Rxmsg))
- if(Rxmsg.id == PCM_STATE_ID){
-
- // Mutex to protex shared variables
- ds_mutex.lock();
- drive_status = Rxmsg.data[0];
- ds_mutex.unlock();
- }
-
- if(Rxmsg.id == BATTERY_POWER_ID)
- {
- float power_ratio;
- ftc rcv;
- rcv.FLOAT=0.0;
-
- for(int i=0; i<4; i++){
- rcv.C_FLOAT[i] = Rxmsg.data[i];
+ if(CAN_Steering_Buffer.rxRead(Rxmsg)){
+ id_node = vars_list->get_node(Rxmsg.id);
+ if(id_node != NULL){
+ if(id_node->value != Rxmsg.data[0]){
+ screen_flags[id_node->screen] = 1;
}
- power_ratio=rcv.FLOAT/80000;
- ledstream.write(power_ratio);
+ id_node->value = Rxmsg.data[0];
}
}
}
-
+}
int main(){
// Initialize, set all variables.
@@ -163,7 +167,6 @@
}
if(biSWTR.read() && NOT_biSWTR_HELD){
- printf("ff\r\n");
toggle_screen();
NOT_biSWTR_HELD = false;
}
@@ -176,7 +179,6 @@
// ignore BiSWTR.read()
}
-
if(biSWBR.read()){
reset();
}
--- a/Steering.h Sat Nov 15 19:10:34 2014 +0000
+++ b/Steering.h Sat Nov 22 22:24:53 2014 +0000
@@ -11,6 +11,8 @@
#include "Comic24.h"
#include "vivaldi16.h"
#include "CANBuffer.h"
+#include "variables.h"
+
#include "LPCDigitalIn.h"
@@ -31,6 +33,8 @@
#define BATTERY_AVG_CELLTEMPERATURE_ID 0x30B
#define AMS_BATTERY_STATE 0x30E // AIRS 7 and 6 // Precharge 3
+#define NUM_SCREEN 2
+
#define HOME_SCREEN 0
#define BATTERY_SCREEN 1
@@ -103,15 +107,49 @@
{102,32}, //tsm
};
-int maxScreen=2;
-int curr_screen;
+int curr_screen;
+int screen_flags[NUM_SCREEN];
+bool should_redraw;
char drive_status;
char drive_status_request;
char reset_body;
+node * id_node = NULL;
+variables * vars_list;
Mutex ds_mutex;
+/*
+void read_messages(void const *args) {
+
+ while (true) {
+ CANMessage Rxmsg;
+
+ if(CAN_Steering_Buffer.rxRead(Rxmsg))
+ if(Rxmsg.id == PCM_STATE_ID){
+
+ // Mutex to protex shared variables
+ ds_mutex.lock();
+ drive_status = Rxmsg.data[0];
+ ds_mutex.unlock();
+ }
+
+ if(Rxmsg.id == BATTERY_POWER_ID)
+ {
+ float power_ratio;
+ ftc rcv;
+ rcv.FLOAT=0.0;
+
+ for(int i=0; i<4; i++){
+ rcv.C_FLOAT[i] = Rxmsg.data[i];
+ }
+ power_ratio=rcv.FLOAT/80000;
+ ledstream.write(power_ratio);
+ }
+ }
+ }
+*/
+
#endif /* STEERING_H */
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/node.h Sat Nov 22 22:24:53 2014 +0000
@@ -0,0 +1,35 @@
+class node{
+
+ public:
+
+ node();
+ node(int id, int screen);
+ void set_val(char v);
+ ~node();
+
+ int screen;
+ int id;
+ char value;
+ node * next;
+
+};
+
+node::node(){
+ screen = 0;
+ id = 0;
+ next = NULL;
+}
+
+node::node(int i, int s){
+ id = i;
+ screen = s;
+ next = NULL;
+}
+
+void node::set_val(char v){
+ value = v;
+}
+
+node::~node(){
+}
+
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/variables.h Sat Nov 22 22:24:53 2014 +0000
@@ -0,0 +1,117 @@
+#include "node.h"
+
+class variables{
+
+ public:
+
+ variables();
+ ~variables();
+ void add(int i, int s);
+ int get_screen(int i);
+ char get_value(int i);
+ int set_value(int i, char v);
+ node * get_node(int i);
+
+
+ int size;
+ node * head;
+ node * tail;
+
+};
+
+variables::variables(){
+ size = 0;
+ head = NULL;
+ tail = NULL;
+}
+
+variables::~variables(){
+
+ node * curr = head;
+ node * next = head;
+
+ while(curr != NULL){
+ next = curr->next;
+ delete(curr);
+ curr = next;
+ }
+
+ head = NULL;
+ tail = NULL;
+ size = 0;
+}
+
+void variables::add(int i, int s){
+
+ if(head == NULL){
+ head = new node(i, s);
+ tail = head;
+ }
+
+ else{
+ tail->next = new node(i,s);
+ tail = tail->next;
+ }
+ size++;
+}
+
+node * variables::get_node(int i){
+
+ node * curr = head;
+
+ while(curr != NULL){
+ if(curr->id == i){
+ return curr;
+ }
+ else{
+ curr = curr->next;
+ }
+ }
+ return NULL;
+}
+
+int variables::get_screen(int i){
+
+ node * curr = head;
+
+ while(curr != NULL){
+ if(curr->id == i){
+ return curr->screen;
+ }
+ else{
+ curr = curr->next;
+ }
+ }
+ return -1;
+}
+
+int variables::set_value(int i, char v){
+
+ node * curr = head;
+
+ while(curr != NULL){
+ if(curr->id == i){
+ curr->set_val(v);
+ return 0;
+ }
+ else{
+ curr = curr->next;
+ }
+ }
+ return -1;
+}
+
+char variables::get_value(int i){
+
+ node * curr = head;
+
+ while(curr != NULL){
+ if(curr->id == i){
+ return curr->value;
+ }
+ else{
+ curr = curr->next;
+ }
+ }
+ return 0;
+}
\ No newline at end of file
