Cleaned up initializations
authorBernard Blackham <[email protected]>
Sat, 16 Aug 2003 17:42:47 +0000 (17:42 +0000)
committerBernard Blackham <[email protected]>
Sat, 16 Aug 2003 17:42:47 +0000 (17:42 +0000)
Added PING/PONG message

ROM2/coinmech.c
ROM2/coinmech.h
ROM2/comm.h
ROM2/keypad.c
ROM2/keypad.h
ROM2/main_basic.c

index c52e146..d3b0992 100644 (file)
@@ -4,14 +4,14 @@
 #define COINMECH_ID   0x20
 
 volatile u8 last_byte;
-volatile u8 packet_pos = 0;
-volatile u16 value_1 = 0;
-volatile u8 value_2 = 0;
-volatile u8 dec_point = 0; 
+volatile u8 packet_pos;
+volatile u16 value_1;
+volatile u8 value_2;
+volatile u8 dec_point;
 
-volatile u16 coin_value = 0;
-u8 item_cost = 0;
-volatile bool have_change = 0;
+volatile u16 coin_value;
+u8 item_cost;
+volatile bool have_change;
 
 u8 parity_test(u8 c) {
        u8 parity = 0;
@@ -132,6 +132,12 @@ void coin_cost(u16 cost) {
 }
 
 void coinmech_init() {
+       packet_pos = 0;
+       value_1 = value_2 = 0;
+       dec_point = 0;
+       coin_value = 0;
+       item_cost = 0;
+       have_change = 0;
        _io_ports[M6811_SCCR1] = 0x10;
        _io_ports[M6811_SCCR2] = 0x2e;
        _io_ports[M6811_BAUD] = 0x03;
index 615caf6..7940b06 100644 (file)
@@ -4,6 +4,7 @@
 #include "vend.h"
 
 extern volatile u16 coin_value;
+extern volatile bool have_change;
 
 void coin_eat();
 void coin_cost(u16 cost); /* specify the cost of an item. */
index 65a3446..c203708 100644 (file)
  *
  * Messages Sent:
  *  KX - keypad press where X is (ascii 0..9 or R)
- *  CXXXXX - coin balance, XXXXX is number of cents.
+ *  CYXXXXX - coin balance, XXXXX is number of cents. Y is 0 if we have change, 
+ *            1 otherwise
  *  MXYY - dispense ack/nack. X is what happened (0..MOTOR_*_FAIL), YY is the motor
  *  DX - door open/close event where X is 1 for open, 0 for closed.
+ *  PONG - response to a ping
  *
  * Messages Received:
  *  VXX - vend a slot XX
  *  U - query current coin balance. - replies with CXXXXX
  *  GXXXXX - give change, XXXXX is the amount of the cost of the item hence change
  *           is the current value in the coin mech - XXXXX
+ *  PING - ping. responds with PONG
  *
  */
 
-#define TX_BUFFER_LEN 6 /* maximum 12 due to the way tx_int works with the FIFO */
+#define TX_BUFFER_LEN 8 /* maximum 12 due to the way tx_int works with the FIFO */
 extern char tx_buffer[TX_BUFFER_LEN+2]; /* \n + null terminated */
 #define RX_BUFFER_LEN 11
 extern volatile char rx_buffer[RX_BUFFER_LEN+1]; /* null terminated */
index cc6093d..980b234 100644 (file)
@@ -3,7 +3,7 @@
 #include "keypad.h"
 
 u8 last_key; /* the last key registered */
-bool new_key = 0;
+bool new_key;
 
 /* first 8 from the first row, then 3 from the second row */
 /* keys are 1-9, 0, reset */
@@ -62,3 +62,8 @@ bool keypad_pressed() {
        new_key = 0;
        return 1;
 }
+
+void keypad_init() {
+       last_key = 0;
+       new_key = 0;
+}
index 1928aa8..ef01345 100644 (file)
@@ -19,5 +19,6 @@ extern u8 last_key;
 bool keypad_pressed();
 void keypad_read();
 u8   keypad_getkey();
+void keypad_init();
 
 #endif /* _KEYPAD_H_ */
index 6019371..b2a797e 100644 (file)
@@ -61,13 +61,14 @@ void write_to_display() {
 void send_balance() {
        wait_for_tx_free();
        tx_buffer[0] = 'C';
-       tx_buffer[1] = (coin_value/10000)%10;
-       tx_buffer[2] = (coin_value/1000)%10;
-       tx_buffer[3] = (coin_value/100)%10;
-       tx_buffer[4] = (coin_value/10)%10;
-       tx_buffer[5] = coin_value%10;
-       tx_buffer[6] = '\n';
-       tx_buffer[7] = 0;
+       tx_buffer[1] = have_change?'0':'1';
+       tx_buffer[2] = (coin_value/10000)%10;
+       tx_buffer[3] = (coin_value/1000)%10;
+       tx_buffer[4] = (coin_value/100)%10;
+       tx_buffer[5] = (coin_value/10)%10;
+       tx_buffer[6] = coin_value%10;
+       tx_buffer[7] = '\n';
+       tx_buffer[8] = 0;
        send_packet();
 }
 
@@ -118,6 +119,25 @@ void do_chime() {
        send_ack();
 }
 
+void ping_pong() {
+       /* make sure it's really a ping */
+       if (msg_buf[1] != 'I' ||
+               msg_buf[2] != 'N' ||
+               msg_buf[3] != 'G') {
+               send_nack();
+               return;
+       }
+       /* respond with ack & pong */
+       wait_for_tx_free();
+       tx_buffer[0] = 'P';
+       tx_buffer[1] = 'O';
+       tx_buffer[2] = 'N';
+       tx_buffer[3] = 'G';
+       tx_buffer[4] = '\n';
+       tx_buffer[5] = 0;
+       send_packet();
+}
+
 int main() {
        u16 last_coin_value;
        bool last_door_open;
@@ -137,6 +157,7 @@ int main() {
        display_init();
        comm_init();
        coinmech_init();
+       keypad_init();
 
        last_coin_value = 0;
        last_door_open = 0;
@@ -164,6 +185,9 @@ int main() {
                                case 'G':
                                        give_change();
                                        break;
+                               case 'P':
+                                       ping_pong();
+                                       break;
                                default:
                                /* shrug */
                                        send_nack();

UCC git Repository :: git.ucc.asn.au