src/hp34comm.cpp

changeset 39
63c6a720cb97
parent 37
07e8ca2bdf6d
child 44
b3c3d54d2c7c
--- a/src/hp34comm.cpp	Mon Oct 26 00:23:55 2020 +0100
+++ b/src/hp34comm.cpp	Tue Oct 27 21:48:28 2020 +0100
@@ -16,10 +16,11 @@
 #define RXTIMEOUT 50ms
 #define STARTUPRETRY 0.5
 
-const uint8_t startup_seq[] = {
+uint8_t startup_seq[] = {
   0x33,
   0x02,
   0x00,
+  0x00,  // to be replaced by the actual keycode, if any
 };
 
 HPSerial::statemethod HPSerial::state_table[NUM_STATES] = {
@@ -42,7 +43,12 @@
   serial.attach(callback(this, &HPSerial::rxIrq), SerialBase::RxIrq);
 }
 
-void HPSerial::startup(void) {
+void HPSerial::startup(uint8_t keycode) {
+  if (keycode != 0xFF) {
+      startup_sed[2] = 0xFF;
+      startup_sed[3] = keycode;
+  }
+
   cur_gstate = GSTATE_STARTING;
   set_timer(10ms); // launch the startup in 10ms
 }
@@ -50,20 +56,19 @@
 void HPSerial::_startup(void)
 {
   cur_gstate = GSTATE_STARTING;
-  tr_data.size = sizeof(startup_seq);
   tr_data.cmd = 0xFF;
   tr_data.pos = 0;
+
+  if (startup_seq[2] == 0xFF)
+      tr_data.size = 4;
+  else
+      tr_data.size = 3; // sizeof(startup_seq);
   for(uint8_t i=0; i<tr_data.size; i++)
     tr_data.payload[i] = startup_seq[i];
+
   cur_state = do_state_sending();
 }
 
-void HPSerial::send(const uint8_t *buf, uint8_t size)
-{
-  //  tx_data->
-  //send(startup, sizeof(startup)/sizeof(startup[0]));
-}
-
 void HPSerial::sendkey(uint8_t keycode)
 {
   tr_data.size = 2;

mercurial