@@ -805,93 +805,15 @@ Device_mode(PyObject *self, PyObject *args)
805
805
}
806
806
807
807
808
- static float rescale_float (float value ,
809
- min_max_t * inrange ,
810
- min_max_t * outrange )
811
- {
812
- float in_interval = inrange -> max - inrange -> min ;
813
- float out_interval = outrange -> max - outrange -> min ;
814
-
815
- return ((value - inrange -> min ) *
816
- out_interval / in_interval ) + outrange -> min ;
817
- }
818
-
819
-
820
- static long rescale_long (long value , min_max_t * inrange , min_max_t * outrange )
821
- {
822
- return (long )(rescale_float ((float )value , inrange , outrange ) + 0.5 );
823
- }
824
-
825
-
826
- static PyObject * convert_raw (PyObject * value , int format , mode_info_t * mode )
827
- {
828
- if (PyLong_Check (value ))
829
- {
830
- long long_value = PyLong_AsLong (value );
831
-
832
- if (long_value == -1 && PyErr_Occurred () != NULL )
833
- return NULL ;
834
-
835
- switch (format )
836
- {
837
- case DEVICE_FORMAT_PERCENT :
838
- long_value = rescale_long (long_value ,
839
- & mode -> raw ,
840
- & mode -> percent );
841
- break ;
842
-
843
- case DEVICE_FORMAT_SI :
844
- long_value = rescale_long (long_value ,
845
- & mode -> raw ,
846
- & mode -> si );
847
- break ;
848
-
849
- default :
850
- break ;
851
- }
852
- return PyLong_FromLong (long_value );
853
- }
854
- else if (PyFloat_Check (value ))
855
- {
856
- float fvalue = (float )PyFloat_AsDouble (value );
857
-
858
- if (fvalue == -1.0 && PyErr_Occurred () != NULL )
859
- return NULL ;
860
-
861
- switch (format )
862
- {
863
- case DEVICE_FORMAT_PERCENT :
864
- fvalue = rescale_float (fvalue ,
865
- & mode -> raw ,
866
- & mode -> percent );
867
- break ;
868
-
869
- case DEVICE_FORMAT_SI :
870
- fvalue = rescale_float (fvalue ,
871
- & mode -> raw ,
872
- & mode -> si );
873
- break ;
874
-
875
- default :
876
- break ;
877
- }
878
- return PyFloat_FromDouble ((double )fvalue );
879
- }
880
- else if (value == Py_None )
881
- {
882
- Py_RETURN_NONE ;
883
- }
884
-
885
- /* Otherwise this is unexpected */
886
- PyErr_SetString (cmd_get_exception (), "Invalid value" );
887
- return NULL ;
888
- }
889
-
890
-
891
808
static int get_value (DeviceObject * device )
892
809
{
893
810
device -> rx_error = DO_RXERR_NONE ;
894
- if (cmd_get_port_value (port_get_id (device -> port )) < 0 )
811
+
812
+ uint8_t selindex = 0 ;
813
+ if (device -> current_mode != MODE_IS_COMBI )
814
+ selindex = device -> current_mode ;
815
+
816
+ if (cmd_get_port_value (port_get_id (device -> port ), selindex ) < 0 )
895
817
{
896
818
PyObject * hub_protocol_exception = cmd_get_exception ();
897
819
@@ -988,30 +910,31 @@ Device_get(PyObject *self, PyObject *args)
988
910
* SI (2).
989
911
*/
990
912
991
- if (/* device->current_mode != MODE_IS_COMBI*/ 1 == 0 )
913
+ if (device -> current_mode != MODE_IS_COMBI )
992
914
{
993
915
/* Simple (single) mode */
994
916
/* Get the current mode data */
995
917
mode = & device -> modes [device -> current_mode ];
996
918
result_count = PyList_Size (device -> values );
997
- if (result_count != mode -> format .datasets )
919
+ /* if (result_count != mode->format.datasets)
998
920
{
999
921
PyErr_SetString(cmd_get_exception(),
1000
922
"Device value length mismatch");
1001
923
return NULL;
1002
- }
924
+ }*/
1003
925
1004
926
/* We wish to return a list with "mode->format->datasets" data
1005
927
* values.
1006
928
*/
1007
- if ((results = PyList_New (mode -> format .datasets )) == NULL )
929
+
930
+ result_count = PyList_Size (device -> values );
931
+ if ((results = PyList_New (result_count )) == NULL )
1008
932
return NULL ;
1009
933
1010
934
/* device->values is a list containing result_count elements */
1011
935
for (i = 0 ; i < result_count ; i ++ )
1012
936
{
1013
937
PyObject * value = PyList_GetItem (device -> values , i );
1014
- value = convert_raw (value , format , mode );
1015
938
if (value == NULL )
1016
939
{
1017
940
Py_DECREF (results );
@@ -1086,9 +1009,9 @@ Device_callback(PyObject *self, PyObject *args)
1086
1009
1087
1010
if (device -> num_combi_modes == 0 )
1088
1011
{
1089
- /* if (set_simple_mode(device, device->current_mode) < 0){
1012
+ if (set_simple_mode (device , device -> current_mode ) < 0 ){
1090
1013
return NULL ;
1091
- }*/
1014
+ }
1092
1015
}
1093
1016
else
1094
1017
{
@@ -1580,6 +1503,7 @@ int device_new_combi_value(PyObject *self,
1580
1503
mode_info_t * mode ;
1581
1504
int bytes_consumed ;
1582
1505
int i ;
1506
+ int modes ;
1583
1507
1584
1508
device -> is_mode_busy = 0 ;
1585
1509
@@ -1592,6 +1516,9 @@ int device_new_combi_value(PyObject *self,
1592
1516
1593
1517
mode_number = (device -> combi_mode [entry ] >> 4 ) & 0x0f ;
1594
1518
mode = & device -> modes [mode_number ];
1519
+ modes = device -> num_combi_modes ;
1520
+ if (device -> current_mode != MODE_IS_COMBI )
1521
+ modes = entry + 1 ;
1595
1522
1596
1523
bytes_consumed = read_value_new (buffer , & value );
1597
1524
if (bytes_consumed < 0 )
@@ -1601,14 +1528,14 @@ int device_new_combi_value(PyObject *self,
1601
1528
}
1602
1529
1603
1530
/* This is not terribly efficient... */
1604
- if ((values = PyList_New (device -> num_combi_modes )) == NULL )
1531
+ if ((values = PyList_New (modes )) == NULL )
1605
1532
{
1606
1533
Py_DECREF (value );
1607
1534
device -> rx_error = DO_RXERR_INTERNAL ;
1608
1535
return -1 ;
1609
1536
}
1610
1537
1611
- for (i = 0 ; i < device -> num_combi_modes ; i ++ )
1538
+ for (i = 0 ; i < modes ; i ++ )
1612
1539
{
1613
1540
if (i == entry )
1614
1541
{
@@ -1831,5 +1758,6 @@ int device_set_device_format(PyObject *device, uint8_t modei, uint8_t type)
1831
1758
mode_info_t * mode ;
1832
1759
mode = & dev -> modes [modei ];
1833
1760
mode -> format .type = type ;
1761
+ dev -> num_modes = modei ;
1834
1762
return 0 ;
1835
1763
}
0 commit comments